1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-05 08:30:07 +01:00

load extensions

This commit is contained in:
Taylor Otwell
2016-05-11 20:32:53 -05:00
parent f48b6c7563
commit 14588a40d8
8 changed files with 60 additions and 31 deletions

View File

@@ -26,6 +26,7 @@ function install()
{
$this->createConfigurationDirectory();
$this->createDriversDirectory();
$this->createExtensionsDirectory();
$this->writeBaseConfiguration();
$this->files->chown($this->path(), user());
@@ -38,9 +39,7 @@ function install()
*/
function createConfigurationDirectory()
{
if (! $this->files->isDir(VALET_HOME_PATH)) {
$this->files->mkdirAsUser(VALET_HOME_PATH);
}
$this->files->ensureDirExists(VALET_HOME_PATH, user());
}
/**
@@ -62,6 +61,16 @@ function createDriversDirectory()
);
}
/**
* Create the directory for the Valet extensions.
*
* @return void
*/
function createExtensionsDirectory()
{
$this->files->ensureDirExists(VALET_HOME_PATH.'/Extensions', user());
}
/**
* Write the base, initial configuration for Valet.
*/

View File

@@ -2,6 +2,8 @@
namespace Valet;
use CommandLine as CommandLineFacade;
class Filesystem
{
/**
@@ -199,20 +201,33 @@ function copyAsUser($from, $to)
*
* @param string $target
* @param string $link
* @param string|null $owner
* @return void
*/
function symlink($target, $link, $owner = null)
function symlink($target, $link)
{
if ($this->exists($link)) {
$this->unlink($link);
}
symlink($target, $link);
}
if ($owner) {
$this->chown($link, $owner);
/**
* Create a symlink to the given target for the non-root user.
*
* This uses the command line as PHP can't change symlink permissions.
*
* @param string $target
* @param string $link
* @return void
*/
function symlinkAsUser($target, $link)
{
if ($this->exists($link)) {
$this->unlink($link);
}
CommandLineFacade::runAsUser('ln -s '.$target.' '.$link);
}
/**
@@ -223,7 +238,7 @@ function symlink($target, $link, $owner = null)
*/
function unlink($path)
{
if ($this->exists($path)) {
if (file_exists($path) || is_link($path)) {
@unlink($path);
}
}

View File

@@ -38,7 +38,7 @@ function link($target, $link)
$this->config->prependPath($linkPath);
$this->cli->runAsUser('ln -s '.$target.' '.$linkPath.'/'.$link);
$this->files->symlinkAsUser($target, $linkPath.'/'.$link);
return $linkPath.'/'.$link;
}

View File

@@ -46,13 +46,30 @@ function createSudoersEntry()
%admin ALL=(root) NOPASSWD: VALET'.PHP_EOL);
}
/**
* Get the paths to all of the Valet extensions.
*
* @return array
*/
function extensions()
{
if (! $this->files->isDir(VALET_HOME_PATH.'/Extensions')) {
return [];
}
return collect($this->files->scandir(VALET_HOME_PATH.'/Extensions'))
->reject(function ($file) {
return is_dir($file);
})->values()->all();
}
/**
* Determine if this is the latest version of Valet.
*
* @param string $currentVersion
* @return bool
*/
public function onLatestVersion($currentVersion)
function onLatestVersion($currentVersion)
{
$response = \Httpful\Request::get('https://api.github.com/repos/laravel/valet/releases/latest')->send();

View File

@@ -1,7 +1,5 @@
<?php
namespace Valet\Facades;
class Facade
{
/**

View File

@@ -11,16 +11,6 @@
}
use Silly\Application;
use Valet\Facades\Brew;
use Valet\Facades\Site;
use Valet\Facades\Valet;
use Valet\Facades\Caddy;
use Valet\Facades\Ngrok;
use Valet\Facades\PhpFpm;
use Valet\Facades\DnsMasq;
use Valet\Facades\Filesystem;
use Valet\Facades\CommandLine;
use Valet\Facades\Configuration;
use Illuminate\Container\Container;
/**
@@ -227,6 +217,13 @@
}
})->descriptions('Determine if this is the latest version of Valet');
/**
* Load all of the Valet extensions.
*/
foreach (Valet::extensions() as $extension) {
include $extension;
}
/**
* Run the application.
*/

View File

@@ -23,14 +23,7 @@ public function tearDown()
public function test_configuration_directory_is_created_if_it_doesnt_exist()
{
$files = Mockery::mock(Filesystem::class);
$files->shouldReceive('isDir')->with(VALET_HOME_PATH)->andReturn(false);
$files->shouldReceive('mkdirAsUser')->with(VALET_HOME_PATH);
swap(Filesystem::class, $files);
resolve(Configuration::class)->createConfigurationDirectory();
$files = Mockery::mock(Filesystem::class);
$files->shouldReceive('isDir')->with(VALET_HOME_PATH)->andReturn(true);
$files->shouldReceive('mkdirAsUser')->never();
$files->shouldReceive('ensureDirExists')->once()->with(VALET_HOME_PATH, user());
swap(Filesystem::class, $files);
resolve(Configuration::class)->createConfigurationDirectory();
}

View File

@@ -31,7 +31,7 @@ public function test_symlink_creates_symlink_to_given_path()
$files->shouldReceive('ensureDirExists')->once()->with(VALET_HOME_PATH.'/Sites', user());
$config = Mockery::mock(Configuration::class);
$config->shouldReceive('prependPath')->once()->with(VALET_HOME_PATH.'/Sites');
$files->shouldReceive('symlink')->once()->with('target', VALET_HOME_PATH.'/Sites/link');
$files->shouldReceive('symlinkAsUser')->once()->with('target', VALET_HOME_PATH.'/Sites/link');
swap(Filesystem::class, $files);
swap(Configuration::class, $config);