the whole shebang

This commit is contained in:
2014-11-25 16:42:40 +01:00
parent 7f74c0613e
commit ab1334c0cf
3686 changed files with 496409 additions and 1 deletions

View File

@@ -0,0 +1,158 @@
<?php namespace Illuminate\Foundation;
class AliasLoader {
/**
* The array of class aliases.
*
* @var array
*/
protected $aliases;
/**
* Indicates if a loader has been registered.
*
* @var bool
*/
protected $registered = false;
/**
* The singleton instance of the loader.
*
* @var \Illuminate\Foundation\AliasLoader
*/
protected static $instance;
/**
* Create a new class alias loader instance.
*
* @param array $aliases
* @return void
*/
public function __construct(array $aliases = array())
{
$this->aliases = $aliases;
}
/**
* Get or create the singleton alias loader instance.
*
* @param array $aliases
* @return \Illuminate\Foundation\AliasLoader
*/
public static function getInstance(array $aliases = array())
{
if (is_null(static::$instance)) static::$instance = new static($aliases);
$aliases = array_merge(static::$instance->getAliases(), $aliases);
static::$instance->setAliases($aliases);
return static::$instance;
}
/**
* Load a class alias if it is registered.
*
* @param string $alias
* @return void
*/
public function load($alias)
{
if (isset($this->aliases[$alias]))
{
return class_alias($this->aliases[$alias], $alias);
}
}
/**
* Add an alias to the loader.
*
* @param string $class
* @param string $alias
* @return void
*/
public function alias($class, $alias)
{
$this->aliases[$class] = $alias;
}
/**
* Register the loader on the auto-loader stack.
*
* @return void
*/
public function register()
{
if ( ! $this->registered)
{
$this->prependToLoaderStack();
$this->registered = true;
}
}
/**
* Prepend the load method to the auto-loader stack.
*
* @return void
*/
protected function prependToLoaderStack()
{
spl_autoload_register(array($this, 'load'), true, true);
}
/**
* Get the registered aliases.
*
* @return array
*/
public function getAliases()
{
return $this->aliases;
}
/**
* Set the registered aliases.
*
* @param array $aliases
* @return void
*/
public function setAliases(array $aliases)
{
$this->aliases = $aliases;
}
/**
* Indicates if the loader has been registered.
*
* @return bool
*/
public function isRegistered()
{
return $this->registered;
}
/**
* Set the "registered" state of the loader.
*
* @param bool $value
* @return void
*/
public function setRegistered($value)
{
$this->registered = $value;
}
/**
* Set the value of the singleton alias loader.
*
* @param \Illuminate\Foundation\AliasLoader $loader
* @return void
*/
public static function setInstance($loader)
{
static::$instance = $loader;
}
}

View File

@@ -0,0 +1,842 @@
<?php namespace Illuminate\Foundation;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Route;
use Illuminate\Routing\Router;
use Illuminate\Config\FileLoader;
use Illuminate\Container\Container;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Facades\Facade;
use Illuminate\Support\ServiceProvider;
use Illuminate\Events\EventServiceProvider;
use Illuminate\Foundation\ProviderRepository;
use Illuminate\Routing\RoutingServiceProvider;
use Illuminate\Exception\ExceptionServiceProvider;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Illuminate\Support\Contracts\ResponsePreparerInterface;
use Symfony\Component\HttpKernel\Exception\FatalErrorException;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpFoundation\RedirectResponse as SymfonyRedirect;
class Application extends Container implements HttpKernelInterface, ResponsePreparerInterface {
/**
* The Laravel framework version.
*
* @var string
*/
const VERSION = '4.0.6';
/**
* Indicates if the application has "booted".
*
* @var bool
*/
protected $booted = false;
/**
* The array of booting callbacks.
*
* @var array
*/
protected $bootingCallbacks = array();
/**
* The array of booted callbacks.
*
* @var array
*/
protected $bootedCallbacks = array();
/**
* The array of shutdown callbacks.
*
* @var array
*/
protected $shutdownCallbacks = array();
/**
* All of the registered service providers.
*
* @var array
*/
protected $serviceProviders = array();
/**
* The names of the loaded service providers.
*
* @var array
*/
protected $loadedProviders = array();
/**
* The deferred services and their providers.
*
* @var array
*/
protected $deferredServices = array();
/**
* The request class used by the application.
*
* @var string
*/
protected static $requestClass = 'Illuminate\Http\Request';
/**
* Create a new Illuminate application instance.
*
* @param \Illuminate\Http\Request $request
* @return void
*/
public function __construct(Request $request = null)
{
$this['request'] = $this->createRequest($request);
// The exception handler class takes care of determining which of the bound
// exception handler Closures should be called for a given exception and
// gets the response from them. We'll bind it here to allow overrides.
$this->register(new ExceptionServiceProvider($this));
$this->register(new RoutingServiceProvider($this));
$this->register(new EventServiceProvider($this));
}
/**
* Create the request for the application.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Request
*/
protected function createRequest(Request $request = null)
{
return $request ?: static::onRequest('createFromGlobals');
}
/**
* Set the application request for the console environment.
*
* @return void
*/
public function setRequestForConsoleEnvironment()
{
$url = $this['config']->get('app.url', 'http://localhost');
$parameters = array($url, 'GET', array(), array(), array(), $_SERVER);
$this->instance('request', static::onRequest('create', $parameters));
}
/**
* Redirect the request if it has a trailing slash.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse|null
*/
public function redirectIfTrailingSlash()
{
if ($this->runningInConsole()) return;
// Here we will check if the request path ends in a single trailing slash and
// redirect it using a 301 response code if it does which avoids duplicate
// content in this application while still providing a solid experience.
$path = $this['request']->getPathInfo();
if ($path != '/' and ends_with($path, '/') and ! ends_with($path, '//'))
{
with(new SymfonyRedirect($this['request']->fullUrl(), 301))->send();
exit;
}
}
/**
* Bind the installation paths to the application.
*
* @param array $paths
* @return void
*/
public function bindInstallPaths(array $paths)
{
$this->instance('path', realpath($paths['app']));
foreach (array_except($paths, array('app')) as $key => $value)
{
$this->instance("path.{$key}", realpath($value));
}
}
/**
* Get the application bootstrap file.
*
* @return string
*/
public static function getBootstrapFile()
{
return __DIR__.'/start.php';
}
/**
* Start the exception handling for the request.
*
* @return void
*/
public function startExceptionHandling()
{
$this['exception']->register($this->environment());
$this['exception']->setDebug($this['config']['app.debug']);
}
/**
* Get the current application environment.
*
* @return string
*/
public function environment()
{
return $this['env'];
}
/**
* Detect the application's current environment.
*
* @param array|string $environments
* @return string
*/
public function detectEnvironment($environments)
{
$base = $this['request']->getHost();
$arguments = $this['request']->server->get('argv');
if ($this->runningInConsole())
{
return $this->detectConsoleEnvironment($base, $environments, $arguments);
}
return $this->detectWebEnvironment($base, $environments);
}
/**
* Set the application environment for a web request.
*
* @param string $base
* @param array|string $environments
* @return string
*/
protected function detectWebEnvironment($base, $environments)
{
// If the given environment is just a Closure, we will defer the environment
// detection to the Closure the developer has provided, which allows them
// to totally control the web environment detection if they require to.
if ($environments instanceof Closure)
{
return $this['env'] = call_user_func($environments);
}
foreach ($environments as $environment => $hosts)
{
// To determine the current environment, we'll simply iterate through the
// possible environments and look for a host that matches this host in
// the request's context, then return back that environment's names.
foreach ((array) $hosts as $host)
{
if (str_is($host, $base) or $this->isMachine($host))
{
return $this['env'] = $environment;
}
}
}
return $this['env'] = 'production';
}
/**
* Set the application environment from command-line arguments.
*
* @param string $base
* @param mixed $environments
* @param array $arguments
* @return string
*/
protected function detectConsoleEnvironment($base, $environments, $arguments)
{
foreach ($arguments as $key => $value)
{
// For the console environment, we'll just look for an argument that starts
// with "--env" then assume that it is setting the environment for every
// operation being performed, and we'll use that environment's config.
if (starts_with($value, '--env='))
{
$segments = array_slice(explode('=', $value), 1);
return $this['env'] = head($segments);
}
}
return $this->detectWebEnvironment($base, $environments);
}
/**
* Determine if the name matches the machine name.
*
* @param string $name
* @return bool
*/
protected function isMachine($name)
{
return str_is($name, gethostname());
}
/**
* Determine if we are running in the console.
*
* @return bool
*/
public function runningInConsole()
{
return php_sapi_name() == 'cli';
}
/**
* Determine if we are running unit tests.
*
* @return bool
*/
public function runningUnitTests()
{
return $this['env'] == 'testing';
}
/**
* Register a service provider with the application.
*
* @param \Illuminate\Support\ServiceProvider|string $provider
* @param array $options
* @return void
*/
public function register($provider, $options = array())
{
// If the given "provider" is a string, we will resolve it, passing in the
// application instance automatically for the developer. This is simply
// a more convenient way of specifying your service provider classes.
if (is_string($provider))
{
$provider = $this->resolveProviderClass($provider);
}
$provider->register();
// Once we have registered the service we will iterate through the options
// and set each of them on the application so they will be available on
// the actual loading of the service objects and for developer usage.
foreach ($options as $key => $value)
{
$this[$key] = $value;
}
$this->serviceProviders[] = $provider;
$this->loadedProviders[get_class($provider)] = true;
}
/**
* Resolve a service provider instance from the class name.
*
* @param string $provider
* @return \Illuminate\Support\ServiceProvider
*/
protected function resolveProviderClass($provider)
{
return new $provider($this);
}
/**
* Load and boot all of the remaining deferred providers.
*
* @return void
*/
public function loadDeferredProviders()
{
// We will simply spin through each of the deferred providers and register each
// one and boot them if the application has booted. This should make each of
// the remaining services available to this application for immediate use.
foreach (array_unique($this->deferredServices) as $provider)
{
$this->register($instance = new $provider($this));
if ($this->booted) $instance->boot();
}
$this->deferredServices = array();
}
/**
* Load the provider for a deferred service.
*
* @param string $service
* @return void
*/
protected function loadDeferredProvider($service)
{
$provider = $this->deferredServices[$service];
// If the service provider has not already been loaded and registered we can
// register it with the application and remove the service from this list
// of deferred services, since it will already be loaded on subsequent.
if ( ! isset($this->loadedProviders[$provider]))
{
$this->register($instance = new $provider($this));
unset($this->deferredServices[$service]);
$this->setupDeferredBoot($instance);
}
}
/**
* Handle the booting of a deferred service provider.
*
* @param \Illuminate\Support\ServiceProvider $instance
* @return void
*/
protected function setupDeferredBoot($instance)
{
if ($this->booted) return $instance->boot();
$this->booting(function() use ($instance) { $instance->boot(); });
}
/**
* Resolve the given type from the container.
*
* (Overriding Container::make)
*
* @param string $abstract
* @param array $parameters
* @return mixed
*/
public function make($abstract, $parameters = array())
{
if (isset($this->deferredServices[$abstract]))
{
$this->loadDeferredProvider($abstract);
}
return parent::make($abstract, $parameters);
}
/**
* Register a "before" application filter.
*
* @param Closure|string $callback
* @return void
*/
public function before($callback)
{
return $this['router']->before($callback);
}
/**
* Register an "after" application filter.
*
* @param Closure|string $callback
* @return void
*/
public function after($callback)
{
return $this['router']->after($callback);
}
/**
* Register a "close" application filter.
*
* @param Closure|string $callback
* @return void
*/
public function close($callback)
{
return $this['router']->close($callback);
}
/**
* Register a "finish" application filter.
*
* @param Closure|string $callback
* @return void
*/
public function finish($callback)
{
$this['router']->finish($callback);
}
/**
* Register a "shutdown" callback.
*
* @param callable $callback
* @return void
*/
public function shutdown($callback = null)
{
if (is_null($callback))
{
$this->fireAppCallbacks($this->shutdownCallbacks);
}
else
{
$this->shutdownCallbacks[] = $callback;
}
}
/**
* Handles the given request and delivers the response.
*
* @return void
*/
public function run()
{
$response = $this->dispatch($this['request']);
$this['router']->callCloseFilter($this['request'], $response);
$response->send();
$this['router']->callFinishFilter($this['request'], $response);
}
/**
* Handle the given request and get the response.
*
* @param \Illuminate\Http\Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function dispatch(Request $request)
{
if ($this->isDownForMaintenance())
{
$response = $this['events']->until('illuminate.app.down');
if ( ! is_null($response)) return $this->prepareResponse($response, $request);
}
return $this['router']->dispatch($this->prepareRequest($request));
}
/**
* Handle the given request and get the response.
*
* Provides compatibility with BrowserKit functional testing.
*
* @implements HttpKernelInterface::handle
*
* @param \Illuminate\Http\Request $request
* @param int $type
* @param bool $catch
* @return \Symfony\Component\HttpFoundation\Response
*/
public function handle(SymfonyRequest $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
{
$this->instance('request', $request);
Facade::clearResolvedInstance('request');
return $this->dispatch($request);
}
/**
* Boot the application's service providers.
*
* @return void
*/
public function boot()
{
if ($this->booted) return;
// To boot the application we will simply spin through each service provider
// and call the boot method, which will give them a chance to override on
// something that was registered by another provider when it registers.
foreach ($this->serviceProviders as $provider)
{
$provider->boot();
}
$this->fireAppCallbacks($this->bootingCallbacks);
// Once the application has booted we will also fire some "booted" callbacks
// for any listeners that need to do work after this initial booting gets
// finished. This is useful when ordering the boot-up processes we run.
$this->booted = true;
$this->fireAppCallbacks($this->bootedCallbacks);
}
/**
* Register a new boot listener.
*
* @param mixed $callback
* @return void
*/
public function booting($callback)
{
$this->bootingCallbacks[] = $callback;
}
/**
* Register a new "booted" listener.
*
* @param mixed $callback
* @return void
*/
public function booted($callback)
{
$this->bootedCallbacks[] = $callback;
}
/**
* Call the booting callbacks for the application.
*
* @return void
*/
protected function fireAppCallbacks(array $callbacks)
{
foreach ($callbacks as $callback)
{
call_user_func($callback, $this);
}
}
/**
* Prepare the request by injecting any services.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Request
*/
public function prepareRequest(Request $request)
{
if (isset($this['session']))
{
$request->setSessionStore($this['session']);
}
return $request;
}
/**
* Prepare the given value as a Response object.
*
* @param mixed $value
* @return \Symfony\Component\HttpFoundation\Response
*/
public function prepareResponse($value)
{
if ( ! $value instanceof SymfonyResponse) $value = new Response($value);
return $value->prepare($this['request']);
}
/**
* Determine if the application is currently down for maintenance.
*
* @return bool
*/
public function isDownForMaintenance()
{
return file_exists($this['path.storage'].'/meta/down');
}
/**
* Register a maintenance mode event listener.
*
* @param \Closure $callback
* @return void
*/
public function down(Closure $callback)
{
$this['events']->listen('illuminate.app.down', $callback);
}
/**
* Throw an HttpException with the given data.
*
* @param int $code
* @param string $message
* @param array $headers
* @return void
*/
public function abort($code, $message = '', array $headers = array())
{
if ($code == 404)
{
throw new NotFoundHttpException($message);
}
else
{
throw new HttpException($code, $message, null, $headers);
}
}
/**
* Register a 404 error handler.
*
* @param Closure $callback
* @return void
*/
public function missing(Closure $callback)
{
$this->error(function(NotFoundHttpException $e) use ($callback)
{
return call_user_func($callback, $e);
});
}
/**
* Register an application error handler.
*
* @param \Closure $callback
* @return void
*/
public function error(Closure $callback)
{
$this['exception']->error($callback);
}
/**
* Register an error handler at the bottom of the stack.
*
* @param \Closure $callback
* @return void
*/
public function pushError(Closure $callback)
{
$this['exception']->pushError($callback);
}
/**
* Register an error handler for fatal errors.
*
* @param Closure $callback
* @return void
*/
public function fatal(Closure $callback)
{
$this->error(function(FatalErrorException $e) use ($callback)
{
return call_user_func($callback, $e);
});
}
/**
* Get the configuration loader instance.
*
* @return \Illuminate\Config\LoaderInterface
*/
public function getConfigLoader()
{
return new FileLoader(new Filesystem, $this['path'].'/config');
}
/**
* Get the service provider repository instance.
*
* @return \Illuminate\Foundation\ProviderRepository
*/
public function getProviderRepository()
{
$manifest = $this['config']['app.manifest'];
return new ProviderRepository(new Filesystem, $manifest);
}
/**
* Set the current application locale.
*
* @param string $locale
* @return void
*/
public function setLocale($locale)
{
$this['config']->set('app.locale', $locale);
$this['translator']->setLocale($locale);
$this['events']->fire('locale.changed', array($locale));
}
/**
* Get the service providers that have been loaded.
*
* @return array
*/
public function getLoadedProviders()
{
return $this->loadedProviders;
}
/**
* Set the application's deferred services.
*
* @param array $services
* @return void
*/
public function setDeferredServices(array $services)
{
$this->deferredServices = $services;
}
/**
* Get or set the request class for the application.
*
* @param string $class
* @return string
*/
public static function requestClass($class = null)
{
if ( ! is_null($class)) static::$requestClass = $class;
return static::$requestClass;
}
/**
* Call a method on the default request class.
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public static function onRequest($method, $parameters = array())
{
return forward_static_call_array(array(static::requestClass(), $method), $parameters);
}
/**
* Dynamically access application services.
*
* @param string $key
* @return mixed
*/
public function __get($key)
{
return $this[$key];
}
/**
* Dynamically set application services.
*
* @param string $key
* @param mixed $value
* @return void
*/
public function __set($key, $value)
{
$this[$key] = $value;
}
}

View File

@@ -0,0 +1,85 @@
<?php namespace Illuminate\Foundation;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Illuminate\Console\Application as ConsoleApplication;
class Artisan {
/**
* The application instance.
*
* @var \Illuminate\Foundation\Application
*/
protected $app;
/**
* The Artisan console instance.
*
* @var \Illuminate\Console\Application
*/
protected $artisan;
/**
* Create a new Artisan command runner instance.
*
* @param \Illuminate\Foundation\Application $app
* @return void
*/
public function __construct(Application $app)
{
$this->app = $app;
}
/**
* Run an Artisan console command by name.
*
* @param string $command
* @param array $parameters
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @return void
*/
public function call($command, array $parameters = array(), OutputInterface $output = null)
{
$artisan = $this->getArtisan();
$parameters['command'] = $command;
// Unless an output interface implementation was specifically passed to us we
// will use the "NullOutput" implementation by default to keep any writing
// suppressed so it doesn't leak out to the browser or any other source.
$output = $output ?: new NullOutput;
$input = new ArrayInput($parameters);
return $artisan->find($command)->run($input, $output);
}
/**
* Get the Artisan console instance.
*
* @return \Illuminate\Console\Application
*/
protected function getArtisan()
{
if ( ! is_null($this->artisan)) return $this->artisan;
$this->app->loadDeferredProviders();
return $this->artisan = ConsoleApplication::start($this->app);
}
/**
* Dynamically pass all missing methods to console Artisan.
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public function __call($method, $parameters)
{
return call_user_func_array(array($this->app['artisan'], $method), $parameters);
}
}

View File

@@ -0,0 +1,92 @@
<?php namespace Illuminate\Foundation;
use Illuminate\Filesystem\Filesystem;
class AssetPublisher {
/**
* The filesystem instance.
*
* @var \Illuminate\Filesystem\Filesystem
*/
protected $files;
/**
* The path where assets should be published.
*
* @var string
*/
protected $publishPath;
/**
* The path where packages are located.
*
* @var string
*/
protected $packagePath;
/**
* Create a new asset publisher instance.
*
* @param \Illuminate\Filesystem\Filesystem $files
* @param string $publishPath
* @return void
*/
public function __construct(Filesystem $files, $publishPath)
{
$this->files = $files;
$this->publishPath = $publishPath;
}
/**
* Copy all assets from a given path to the publish path.
*
* @param string $name
* @param string $source
* @return bool
*/
public function publish($name, $source)
{
$destination = $this->publishPath."/packages/{$name}";
$success = $this->files->copyDirectory($source, $destination);
if ( ! $success)
{
throw new \RuntimeException("Unable to publish assets.");
}
return $success;
}
/**
* Publish a given package's assets to the publish path.
*
* @param string $package
* @param string $packagePath
* @return bool
*/
public function publishPackage($package, $packagePath = null)
{
$packagePath = $packagePath ?: $this->packagePath;
// Once we have the package path we can just create the source and destination
// path and copy the directory from one to the other. The directory copy is
// recursive so all nested files and directories will get copied as well.
$source = $packagePath."/{$package}/public";
return $this->publish($package, $source);
}
/**
* Set the default package path.
*
* @param string $packagePath
* @return void
*/
public function setPackagePath($packagePath)
{
$this->packagePath = $packagePath;
}
}

View File

@@ -0,0 +1,98 @@
<?php namespace Illuminate\Foundation;
use Illuminate\Filesystem\Filesystem;
use Symfony\Component\Process\Process;
class Composer {
/**
* The filesystem instance.
*
* @var \Illuminate\Filesystem\Filesystem
*/
protected $files;
/**
* The working path to regenerate from.
*
* @var string
*/
protected $workingPath;
/**
* Create a new Composer manager instance.
*
* @param \Illuminate\Filesystem\Filesystem $files
* @param string $workingPath
* @return void
*/
public function __construct(Filesystem $files, $workingPath = null)
{
$this->files = $files;
$this->workingPath = $workingPath;
}
/**
* Regenerate the Composer autoloader files.
*
* @param string $extra
* @return void
*/
public function dumpAutoloads($extra = '')
{
$process = $this->getProcess();
$process->setCommandLine(trim($this->findComposer().' dump-autoload '.$extra));
$process->run();
}
/**
* Regenerate the optimized Composer autoloader files.
*
* @return void
*/
public function dumpOptimized()
{
$this->dumpAutoloads('--optimize');
}
/**
* Get the composer command for the environment.
*
* @return string
*/
protected function findComposer()
{
if ($this->files->exists($this->workingPath.'/composer.phar'))
{
return 'php composer.phar';
}
return 'composer';
}
/**
* Get a new Symfony process instance.
*
* @return \Symfony\Component\Process\Process
*/
protected function getProcess()
{
return new Process('', $this->workingPath);
}
/**
* Set the working path used by the class.
*
* @param string $path
* @return \Illuminate\Foundation\Composer
*/
public function setWorkingPath($path)
{
$this->workingPath = realpath($path);
return $this;
}
}

View File

@@ -0,0 +1,123 @@
<?php namespace Illuminate\Foundation;
use Illuminate\Filesystem\Filesystem;
class ConfigPublisher {
/**
* The filesystem instance.
*
* @var \Illuminate\Filesystem\Filesystem
*/
protected $files;
/**
* The destination of the config files.
*
* @var string
*/
protected $publishPath;
/**
* The path to the application's packages.
*
* @var string
*/
protected $packagePath;
/**
* Create a new configuration publisher instance.
*
* @param \Illuminate\Filesystem\Filesystem $files
* @param string $publishPath
* @return void
*/
public function __construct(Filesystem $files, $publishPath)
{
$this->files = $files;
$this->publishPath = $publishPath;
}
/**
* Publish configuration files from a given path.
*
* @param string $package
* @param string $source
* @return void
*/
public function publish($package, $source)
{
$destination = $this->publishPath."/packages/{$package}";
$this->makeDestination($destination);
return $this->files->copyDirectory($source, $destination);
}
/**
* Publish the configuration files for a package.
*
* @param string $package
* @param string $packagePath
* @return void
*/
public function publishPackage($package, $packagePath = null)
{
list($vendor, $name) = explode('/', $package);
// First we will figure out the source of the package's configuration location
// which we do by convention. Once we have that we will move the files over
// to the "main" configuration directory for this particular application.
$path = $packagePath ?: $this->packagePath;
$source = $this->getSource($package, $name, $path);
return $this->publish($package, $source);
}
/**
* Get the source configuration directory to publish.
*
* @param string $package
* @param string $name
* @param string $packagePath
* @return string
*/
protected function getSource($package, $name, $packagePath)
{
$source = $packagePath."/{$package}/src/config";
if ( ! $this->files->isDirectory($source))
{
throw new \InvalidArgumentException("Configuration not found.");
}
return $source;
}
/**
* Create the destination directory if it doesn't exist.
*
* @param string $destination
* @return void
*/
protected function makeDestination($destination)
{
if ( ! $this->files->isDirectory($destination))
{
$this->files->makeDirectory($destination, 0777, true);
}
}
/**
* Set the default package path.
*
* @param string $packagePath
* @return void
*/
public function setPackagePath($packagePath)
{
$this->packagePath = $packagePath;
}
}

View File

@@ -0,0 +1,170 @@
<?php namespace Illuminate\Foundation\Console;
use Illuminate\Console\Command;
use Symfony\Component\Finder\Finder;
use Illuminate\Foundation\AssetPublisher;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class AssetPublishCommand extends Command {
/**
* The console command name.
*
* @var string
*/
protected $name = 'asset:publish';
/**
* The console command description.
*
* @var string
*/
protected $description = "Publish a package's assets to the public directory";
/**
* The asset publisher instance.
*
* @var \Illuminate\Foundation\AssetPublisher
*/
protected $assets;
/**
* Create a new asset publish command instance.
*
* @param \Illuminate\Foundation\AssetPublisher $assets
* @return void
*/
public function __construct(AssetPublisher $assets)
{
parent::__construct();
$this->assets = $assets;
}
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
foreach ($this->getPackages() as $package)
{
$this->publishAssets($package);
}
}
/**
* Publish the assets for a given package name.
*
* @param string $package
* @return void
*/
protected function publishAssets($package)
{
if ( ! is_null($path = $this->getPath()))
{
$this->assets->publish($package, $path);
}
else
{
$this->assets->publishPackage($package);
}
$this->output->writeln('<info>Assets published for package:</info> '.$package);
}
/**
* Get the name of the package being published.
*
* @return array
*/
protected function getPackages()
{
if ( ! is_null($package = $this->input->getArgument('package')))
{
return array($package);
}
elseif ( ! is_null($bench = $this->input->getOption('bench')))
{
return array($bench);
}
return $this->findAllAssetPackages();
}
/**
* Find all the asset hosting packages in the system.
*
* @return array
*/
protected function findAllAssetPackages()
{
$vendor = $this->laravel['path.base'].'/vendor';
$packages = array();
foreach (Finder::create()->directories()->in($vendor)->name('public')->depth('< 3') as $package)
{
$packages[] = $package->getRelativePath();
}
return $packages;
}
/**
* Get the specified path to the files.
*
* @return string
*/
protected function getPath()
{
$path = $this->input->getOption('path');
// First we will check for an explicitly specified path from the user. If one
// exists we will use that as the path to the assets. This allows the free
// storage of assets wherever is best for this developer's web projects.
if ( ! is_null($path))
{
return $this->laravel['path.base'].'/'.$path;
}
// If a "bench" option was specified, we will publish from a workbench as the
// source location. This is mainly just a short-cut for having to manually
// specify the full workbench path using the --path command line option.
$bench = $this->input->getOption('bench');
if ( ! is_null($bench))
{
return $this->laravel['path.base']."/workbench/{$bench}/public";
}
}
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return array(
array('package', InputArgument::OPTIONAL, 'The name of package being published.'),
);
}
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return array(
array('bench', null, InputOption::VALUE_OPTIONAL, 'The name of the workbench to publish.', null),
array('path', null, InputOption::VALUE_OPTIONAL, 'The path to the configuration files.', null),
);
}
}

View File

@@ -0,0 +1,93 @@
<?php namespace Illuminate\Foundation\Console;
use Illuminate\Console\Command;
use Illuminate\Foundation\Composer;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class AutoloadCommand extends Command {
/**
* The console command name.
*
* @var string
*/
protected $name = 'dump-autoload';
/**
* The console command description.
*
* @var string
*/
protected $description = "Regenerate framework autoload files";
/**
* The composer instance.
*
* @var \Illuminate\Foundation\Composer
*/
protected $composer;
/**
* Create a new optimize command instance.
*
* @param \Illuminate\Foundation\Composer $composer
* @return void
*/
public function __construct(Composer $composer)
{
parent::__construct();
$this->composer = $composer;
}
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
$this->call('optimize');
foreach ($this->findWorkbenches() as $workbench)
{
$this->comment("Running for workbench [{$workbench['name']}]...");
$this->composer->setWorkingPath($workbench['path'])->dumpOptimized();
}
}
/**
* Get all of the workbench directories.
*
* @return array
*/
protected function findWorkbenches()
{
$results = array();
foreach ($this->getWorkbenchComposers() as $file)
{
$results[] = array('name' => $file->getRelativePath(), 'path' => $file->getPath());
}
return $results;
}
/**
* Get all of the workbench composer files.
*
* @return \Symfony\Component\Finder\Finder
*/
protected function getWorkbenchComposers()
{
$workbench = $this->laravel['path.base'].'/workbench';
if ( ! is_dir($workbench)) return array();
return Finder::create()->files()->in($workbench)->name('composer.json')->depth('< 3');
}
}

View File

@@ -0,0 +1,115 @@
<?php namespace Illuminate\Foundation\Console;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class ChangesCommand extends Command {
/**
* The console command name.
*
* @var string
*/
protected $name = 'changes';
/**
* The console command description.
*
* @var string
*/
protected $description = "Display the framework change list";
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
list($version, $changes) = $this->getChangeVersion($this->getChangesArray());
$this->writeHeader($version);
foreach ($changes as $change)
{
$this->line($this->formatMessage($change));
}
}
/**
* Write the heading for the change log.
*
* @param string $version
* @return void
*/
protected function writeHeader($version)
{
$this->info($heading = 'Changes For Laravel '.$version);
$this->comment(str_repeat('-', strlen($heading)));
}
/**
* Format the given change message.
*
* @param array $change
* @return stirng
*/
protected function formatMessage(array $change)
{
$message = '<comment>-></comment> <info>'.$change['message'].'</info>';
if ( ! is_null($change['backport']))
{
$message .= ' <comment>(Backported to '.$change['backport'].')</comment>';
}
return $message;
}
/**
* Get the change list for the specified version.
*
* @param array $changes
* @return array
*/
protected function getChangeVersion(array $changes)
{
$version = $this->argument('version');
if (is_null($version))
{
$latest = head(array_keys($changes));
return array($latest, $changes[$latest]);
}
else
{
return array($version, array_get($changes, $version, array()));
}
}
/**
* Get the changes array from disk.
*
* @return array
*/
protected function getChangesArray()
{
return json_decode(file_get_contents(__DIR__.'/../changes.json'), true);
}
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return array(
array('version', InputArgument::OPTIONAL, 'The version to list changes for.'),
);
}
}

View File

@@ -0,0 +1,35 @@
<?php namespace Illuminate\Foundation\Console;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class ClearCompiledCommand extends Command {
/**
* The console command name.
*
* @var string
*/
protected $name = 'clear-compiled';
/**
* The console command description.
*
* @var string
*/
protected $description = "Remove the compiled class file";
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
@unlink($this->laravel['path.base'].'/bootstrap/compiled.php');
@unlink($this->laravel['path.storage'].'/meta/services.json');
}
}

View File

@@ -0,0 +1,160 @@
<?php namespace Illuminate\Foundation\Console;
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class CommandMakeCommand extends Command {
/**
* The console command name.
*
* @var string
*/
protected $name = 'command:make';
/**
* The console command description.
*
* @var string
*/
protected $description = "Create a new Artisan command";
/**
* Create a new command creator command.
*
* @param \Illuminate\Filesystem\Filesystem $files
* @return void
*/
public function __construct(Filesystem $files)
{
parent::__construct();
$this->files = $files;
}
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
$path = $this->getPath();
$stub = $this->files->get(__DIR__.'/stubs/command.stub');
// We'll grab the class name to determine the file name. Since applications are
// typically using the PSR-0 standards we can safely assume the classes name
// will correspond to what the actual file should be stored as on storage.
$file = $path.'/'.$this->input->getArgument('name').'.php';
$this->writeCommand($file, $stub);
}
/**
* Write the finished command file to disk.
*
* @param string $file
* @param string $stub
* @return void
*/
protected function writeCommand($file, $stub)
{
if ( ! file_exists($file))
{
$this->files->put($file, $this->formatStub($stub));
$this->info('Command created successfully.');
}
else
{
$this->error('Command already exists!');
}
}
/**
* Format the command class stub.
*
* @param string $stub
* @return string
*/
protected function formatStub($stub)
{
$stub = str_replace('{{class}}', $this->input->getArgument('name'), $stub);
if ( ! is_null($this->option('command')))
{
$stub = str_replace('command:name', $this->option('command'), $stub);
}
return $this->addNamespace($stub);
}
/**
* Add the proper namespace to the command.
*
* @param string $stub
* @return string
*/
protected function addNamespace($stub)
{
if ( ! is_null($namespace = $this->input->getOption('namespace')))
{
return str_replace('{{namespace}}', ' namespace '.$namespace.';', $stub);
}
else
{
return str_replace('{{namespace}}', '', $stub);
}
}
/**
* Get the path where the command should be stored.
*
* @return string
*/
protected function getPath()
{
$path = $this->input->getOption('path');
if (is_null($path))
{
return $this->laravel['path'].'/commands';
}
else
{
return $this->laravel['path.base'].'/'.$path;
}
}
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return array(
array('name', InputArgument::REQUIRED, 'The name of the command.'),
);
}
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return array(
array('command', null, InputOption::VALUE_OPTIONAL, 'The terminal command that should be assigned.', null),
array('path', null, InputOption::VALUE_OPTIONAL, 'The path where the command should be stored.', null),
array('namespace', null, InputOption::VALUE_OPTIONAL, 'The command namespace.', null),
);
}
}

View File

@@ -0,0 +1,104 @@
<?php namespace Illuminate\Foundation\Console;
use Illuminate\Console\Command;
use Illuminate\Foundation\ConfigPublisher;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class ConfigPublishCommand extends Command {
/**
* The console command name.
*
* @var string
*/
protected $name = 'config:publish';
/**
* The console command description.
*
* @var string
*/
protected $description = "Publish a package's configuration to the application";
/**
* The asset publisher instance.
*
* @var \Illuminate\Foundation\AssetPublisher
*/
protected $config;
/**
* Create a new configuration publish command instance.
*
* @param \Illuminate\Foundation\ConfigPublisher $config
* @return void
*/
public function __construct(ConfigPublisher $config)
{
parent::__construct();
$this->config = $config;
}
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
$package = $this->input->getArgument('package');
if ( ! is_null($path = $this->getPath()))
{
$this->config->publish($package, $path);
}
else
{
$this->config->publishPackage($package);
}
$this->output->writeln('<info>Configuration published for package:</info> '.$package);
}
/**
* Get the specified path to the files.
*
* @return string
*/
protected function getPath()
{
$path = $this->input->getOption('path');
if ( ! is_null($path))
{
return $this->laravel['path.base'].'/'.$path;
}
}
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return array(
array('package', InputArgument::REQUIRED, 'The name of package being published.'),
);
}
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return array(
array('path', null, InputOption::VALUE_OPTIONAL, 'The path to the configuration files.', null),
);
}
}

View File

@@ -0,0 +1,33 @@
<?php namespace Illuminate\Foundation\Console;
use Illuminate\Console\Command;
class DownCommand extends Command {
/**
* The console command name.
*
* @var string
*/
protected $name = 'down';
/**
* The console command description.
*
* @var string
*/
protected $description = "Put the application into maintenance mode";
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
touch($this->laravel['path.storage'].'/meta/down');
$this->comment('Application is now in maintenance mode.');
}
}

View File

@@ -0,0 +1,78 @@
<?php namespace Illuminate\Foundation\Console;
use Illuminate\Support\Str;
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
class KeyGenerateCommand extends Command {
/**
* The console command name.
*
* @var string
*/
protected $name = 'key:generate';
/**
* The console command description.
*
* @var string
*/
protected $description = "Set the application key";
/**
* Create a new key generator command.
*
* @param \Illuminate\Filesystem\Filesystem $files
* @return void
*/
public function __construct(Filesystem $files)
{
parent::__construct();
$this->files = $files;
}
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
list($path, $contents) = $this->getKeyFile();
$key = $this->getRandomKey();
$contents = str_replace($this->laravel['config']['app.key'], $key, $contents);
$this->files->put($path, $contents);
$this->info("Application key [$key] set successfully.");
}
/**
* Get the key file and contents.
*
* @return array
*/
protected function getKeyFile()
{
$env = $this->option('env') ? $this->option('env').'/' : '';
$contents = $this->files->get($path = $this->laravel['path']."/config/{$env}app.php");
return array($path, $contents);
}
/**
* Generate a random key for the application.
*
* @return string
*/
protected function getRandomKey()
{
return Str::random(32);
}
}

View File

@@ -0,0 +1,117 @@
<?php
$basePath = $app['path.base'];
return array_map('realpath', array(
$basePath.'/vendor/laravel/framework/src/Illuminate/Support/ClassLoader.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Container/Container.php',
$basePath.'/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpKernelInterface.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Support/Contracts/ResponsePreparerInterface.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Foundation/Application.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Http/Request.php',
$basePath.'/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Request.php',
$basePath.'/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/ParameterBag.php',
$basePath.'/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/FileBag.php',
$basePath.'/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/ServerBag.php',
$basePath.'/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/HeaderBag.php',
$basePath.'/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Session/SessionInterface.php',
$basePath.'/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Session/Storage/SessionStorageInterface.php',
$basePath.'/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Session/SessionBagInterface.php',
$basePath.'/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Session/Attribute/AttributeBagInterface.php',
$basePath.'/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Session/Session.php',
$basePath.'/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php',
$basePath.'/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Session/Attribute/AttributeBag.php',
$basePath.'/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Session/Flash/FlashBagInterface.php',
$basePath.'/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Session/Flash/FlashBag.php',
$basePath.'/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Session/Flash/AutoExpireFlashBag.php',
$basePath.'/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Session/Storage/MetadataBag.php',
$basePath.'/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Session/Storage/Handler/NativeSessionHandler.php',
$basePath.'/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Session/Storage/Proxy/AbstractProxy.php',
$basePath.'/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Session/Storage/Proxy/SessionHandlerProxy.php',
$basePath.'/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/AcceptHeaderItem.php',
$basePath.'/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/AcceptHeader.php',
$basePath.'/vendor/symfony/debug/Symfony/Component/Debug/ExceptionHandler.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Session/FlashBag.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Support/ServiceProvider.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Exception/ExceptionServiceProvider.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Routing/RoutingServiceProvider.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Events/EventServiceProvider.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Support/Str.php',
$basePath.'/vendor/symfony/debug/Symfony/Component/Debug/ErrorHandler.php',
$basePath.'/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Debug/ErrorHandler.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Config/Repository.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Support/NamespacedItemResolver.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Config/FileLoader.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Config/LoaderInterface.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Foundation/AliasLoader.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Cookie/CookieServiceProvider.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Database/DatabaseServiceProvider.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Encryption/EncryptionServiceProvider.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemServiceProvider.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Session/SessionServiceProvider.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/View/ViewServiceProvider.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Routing/Router.php',
$basePath.'/vendor/symfony/routing/Symfony/Component/Routing/RouteCollection.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Workbench/WorkbenchServiceProvider.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Support/Contracts/ArrayableInterface.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Support/Contracts/JsonableInterface.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Database/DatabaseManager.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Database/ConnectionResolverInterface.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Database/Connectors/ConnectionFactory.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Session/Store.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Session/SessionManager.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Support/Manager.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Cookie/CookieJar.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Support/Facades/Log.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Log/LogServiceProvider.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Log/Writer.php',
$basePath.'/vendor/monolog/monolog/src/Monolog/Logger.php',
$basePath.'/vendor/psr/log/Psr/Log/LoggerInterface.php',
$basePath.'/vendor/monolog/monolog/src/Monolog/Handler/AbstractHandler.php',
$basePath.'/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php',
$basePath.'/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php',
$basePath.'/vendor/monolog/monolog/src/Monolog/Handler/RotatingFileHandler.php',
$basePath.'/vendor/monolog/monolog/src/Monolog/Handler/HandlerInterface.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Support/Facades/App.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Exception/ExceptionDisplayerInterface.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Exception/SymfonyDisplayer.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Exception/WhoopsDisplayer.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Exception/Handler.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Support/Facades/Route.php',
$basePath.'/vendor/symfony/routing/Symfony/Component/Routing/Route.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Routing/Route.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/View/Engines/EngineResolver.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/View/ViewFinderInterface.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/View/FileViewFinder.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/View/Environment.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Support/Contracts/MessageProviderInterface.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Support/MessageBag.php',
$basePath.'/vendor/symfony/routing/Symfony/Component/Routing/RequestContext.php',
$basePath.'/vendor/symfony/routing/Symfony/Component/Routing/Matcher/UrlMatcherInterface.php',
$basePath.'/vendor/symfony/routing/Symfony/Component/Routing/Matcher/UrlMatcher.php',
$basePath.'/vendor/symfony/routing/Symfony/Component/Routing/RequestContextAwareInterface.php',
$basePath.'/vendor/symfony/routing/Symfony/Component/Routing/RouteCompilerInterface.php',
$basePath.'/vendor/symfony/routing/Symfony/Component/Routing/RouteCompiler.php',
$basePath.'/vendor/symfony/routing/Symfony/Component/Routing/CompiledRoute.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Support/Facades/View.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Support/Contracts/RenderableInterface.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/View/View.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/View/Engines/EngineInterface.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php',
$basePath.'/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Response.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Http/Response.php',
$basePath.'/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/ResponseHeaderBag.php',
$basePath.'/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Cookie.php',
$basePath.'/vendor/filp/whoops/src/Whoops/Run.php',
$basePath.'/vendor/filp/whoops/src/Whoops/Handler/HandlerInterface.php',
$basePath.'/vendor/filp/whoops/src/Whoops/Handler/Handler.php',
$basePath.'/vendor/filp/whoops/src/Whoops/Handler/PrettyPageHandler.php',
$basePath.'/vendor/filp/whoops/src/Whoops/Handler/JsonResponseHandler.php',
));

View File

@@ -0,0 +1,123 @@
<?php namespace Illuminate\Foundation\Console;
use Illuminate\Console\Command;
use Illuminate\Foundation\Composer;
use Illuminate\Foundation\AssetPublisher;
use ClassPreloader\Command\PreCompileCommand;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class OptimizeCommand extends Command {
/**
* The console command name.
*
* @var string
*/
protected $name = 'optimize';
/**
* The console command description.
*
* @var string
*/
protected $description = "Optimize the framework for better performance";
/**
* The composer instance.
*
* @var \Illuminate\Foundation\Composer
*/
protected $composer;
/**
* Create a new optimize command instance.
*
* @param \Illuminate\Foundation\Composer $composer
* @return void
*/
public function __construct(Composer $composer)
{
parent::__construct();
$this->composer = $composer;
}
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
$this->info('Generating optimized class loader');
$this->composer->dumpOptimized();
if ($this->option('force') or ! $this->laravel['config']['app.debug'])
{
$this->info('Compiling common classes');
$this->compileClasses();
}
else
{
$this->call('clear-compiled');
}
}
/**
* Generate the compiled class file.
*
* @return void
*/
protected function compileClasses()
{
$this->registerClassPreloaderCommand();
$outputPath = $this->laravel['path.base'].'/bootstrap/compiled.php';
$this->callSilent('compile', array(
'--config' => implode(',', $this->getClassFiles()),
'--output' => $outputPath,
'--strip_comments' => 1,
));
}
/**
* Get the classes that should be combined and compiled.
*
* @return array
*/
protected function getClassFiles()
{
$app = $this->laravel;
$core = require __DIR__.'/Optimize/config.php';
return array_merge($core, $this->laravel['config']['compile']);
}
/**
* Register the pre-compiler command instance with Artisan.
*
* @return void
*/
protected function registerClassPreloaderCommand()
{
$this->laravel['artisan']->add(new PreCompileCommand);
}
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return array(
array('force', null, InputOption::VALUE_NONE, 'Force the compiled class file to be written.'),
);
}
}

View File

@@ -0,0 +1,189 @@
<?php namespace Illuminate\Foundation\Console;
use Illuminate\Routing\Router;
use Illuminate\Console\Command;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class RoutesCommand extends Command {
/**
* The console command name.
*
* @var string
*/
protected $name = 'routes';
/**
* The console command description.
*
* @var string
*/
protected $description = 'List all registered routes';
/**
* The router instance.
*
* @var \Illuminate\Routing\Router
*/
protected $router;
/**
* An array of all the registered routes.
*
* @var \Symfony\Component\Routing\RouteCollection
*/
protected $routes;
/**
* The table helper set.
*
* @var \Symfony\Component\Console\Helper\TableHelper
*/
protected $table;
/**
* Create a new route command instance.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function __construct(Router $router)
{
parent::__construct();
$this->router = $router;
$this->routes = $router->getRoutes();
}
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
$this->table = $this->getHelperSet()->get('table');
if (count($this->routes) == 0)
{
return $this->error("Your application doesn't have any routes.");
}
$this->displayRoutes($this->getRoutes());
}
/**
* Compile the routes into a displayable format.
*
* @return array
*/
protected function getRoutes()
{
$results = array();
foreach($this->routes as $name => $route)
{
$results[] = $this->getRouteInformation($name, $route);
}
return $results;
}
/**
* Get the route information for a given route.
*
* @param string $name
* @param \Symfony\Component\Routing\Route $route
* @return array
*/
protected function getRouteInformation($name, Route $route)
{
$uri = head($route->getMethods()).' '.$route->getPath();
$action = $route->getAction() ?: 'Closure';
return array(
'host' => $route->getHost(),
'uri' => $uri,
'name' => $this->getRouteName($name),
'action' => $action,
'before' => $this->getBeforeFilters($route),
'after' => $this->getAfterFilters($route));
}
/**
* Display the route information on the console.
*
* @param array $routes
* @return void
*/
protected function displayRoutes(array $routes)
{
$headers = array('Domain', 'URI', 'Name', 'Action', 'Before Filters', 'After Filters');
$this->table->setHeaders($headers)->setRows($routes);
$this->table->render($this->getOutput());
}
/**
* Get the route name for the given name.
*
* @param string $name
* @return string
*/
protected function getRouteName($name)
{
return str_contains($name, ' ') ? '' : $name;
}
/**
* Get before filters
*
* @param \Illuminate\Routing\Route $route
* @return string
*/
protected function getBeforeFilters($route)
{
$before = $route->getBeforeFilters();
$before = array_unique(array_merge($before, $this->getPatternFilters($route)));
return implode(', ', $before);
}
/**
* Get all of the pattern filters matching the route.
*
* @param \Illuminate\Routing\Route $route
* @return array
*/
protected function getPatternFilters($route)
{
$patterns = array();
foreach ($route->getMethods() as $method)
{
$inner = $this->router->findPatternFilters($method, $route->getPath());
$patterns = array_merge($patterns, $inner);
}
return $patterns;
}
/**
* Get after filters
*
* @param Route $route
* @return string
*/
protected function getAfterFilters($route)
{
return implode(', ',$route->getAfterFilters());
}
}

View File

@@ -0,0 +1,71 @@
<?php namespace Illuminate\Foundation\Console;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
class ServeCommand extends Command {
/**
* The console command name.
*
* @var string
*/
protected $name = 'serve';
/**
* The console command description.
*
* @var string
*/
protected $description = "Serve the application on the PHP development server";
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
$this->checkPhpVersion();
chdir($this->laravel['path.base']);
$host = $this->input->getOption('host');
$port = $this->input->getOption('port');
$public = $this->laravel['path.public'];
$this->info("Laravel development server started on http://{$host}:{$port}");
passthru("php -S {$host}:{$port} -t \"{$public}\" server.php");
}
/**
* Check the current PHP version is >= 5.4.
*
* @return void
*/
protected function checkPhpVersion()
{
if (version_compare(PHP_VERSION, '5.4.0', '<'))
{
throw new \Exception('This PHP binary is not version 5.4 or greater.');
}
}
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return array(
array('host', null, InputOption::VALUE_OPTIONAL, 'The host address to serve the application on.', 'localhost'),
array('port', null, InputOption::VALUE_OPTIONAL, 'The port to serve the application on.', 8000),
);
}
}

View File

@@ -0,0 +1,69 @@
<?php namespace Illuminate\Foundation\Console;
use Illuminate\Console\Command;
class TinkerCommand extends Command {
/**
* The console command name.
*
* @var string
*/
protected $name = 'tinker';
/**
* The console command description.
*
* @var string
*/
protected $description = "Interact with your application";
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
$input = $this->prompt();
while ($input != 'quit')
{
// We will wrap the execution of the command in a try / catch block so we
// can easily display the errors in a convenient way instead of having
// them bubble back out to the CLI and stop the entire command loop.
try
{
if (starts_with($input, 'dump '))
{
$input = 'var_dump('.substr($input, 5).');';
}
eval($input);
}
// If an exception occurs, we will just display the message and keep this
// loop going so we can keep executing commands. However, when a fatal
// a error occurs we have no choice but to bail out of the routines.
catch (\Exception $e)
{
$this->error($e->getMessage());
}
$input = $this->prompt();
}
}
/**
* Prompt the developer for a command.
*
* @return string
*/
protected function prompt()
{
$dialog = $this->getHelperSet()->get('dialog');
return $dialog->ask($this->output, "<info>></info>", null);
}
}

View File

@@ -0,0 +1,33 @@
<?php namespace Illuminate\Foundation\Console;
use Illuminate\Console\Command;
class UpCommand extends Command {
/**
* The console command name.
*
* @var string
*/
protected $name = 'up';
/**
* The console command description.
*
* @var string
*/
protected $description = "Bring the application out of maintenance mode";
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
@unlink($this->laravel['path.storage'].'/meta/down');
$this->info('Application is now live.');
}
}

View File

@@ -0,0 +1,67 @@
<?php{{namespace}}
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class {{class}} extends Command {
/**
* The console command name.
*
* @var string
*/
protected $name = 'command:name';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
//
}
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return array(
array('example', InputArgument::REQUIRED, 'An example argument.'),
);
}
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return array(
array('example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null),
);
}
}

View File

@@ -0,0 +1,205 @@
<?php namespace Illuminate\Foundation;
use Illuminate\Filesystem\Filesystem;
class ProviderRepository {
/**
* The filesystem instance.
*
* @var \Illuminate\Filesystem\Filesystem
*/
protected $files;
/**
* The path to the manifest.
*
* @var string
*/
protected $manifestPath;
/**
* Create a new service repository instance.
*
* @param \Illuminate\Filesystem\Filesystem $files
* @param string $manifestPath
* @return void
*/
public function __construct(Filesystem $files, $manifestPath)
{
$this->files = $files;
$this->manifestPath = $manifestPath;
}
/**
* Register the application service providers.
*
* @param \Illuminate\Foundation\Application $app
* @param array $providers
* @param string $path
* @return void
*/
public function load(Application $app, array $providers)
{
$manifest = $this->loadManifest();
// First we will load the service manifest, which contains information on all
// service providers registered with the application and which services it
// provides. This is used to know which services are "deferred" loaders.
if ($this->shouldRecompile($manifest, $providers))
{
$manifest = $this->compileManifest($app, $providers);
}
// If the application is running in the console, we will not lazy load any of
// the service providers. This is mainly because it's not as necessary for
// performance and also so any provided Artisan commands get registered.
if ($app->runningInConsole())
{
$manifest['eager'] = $manifest['providers'];
}
// We will go ahead and register all of the eagerly loaded providers with the
// application so their services can be registered with the application as
// a provided service. Then we will set the deferred service list on it.
foreach ($manifest['eager'] as $provider)
{
$app->register($this->createProvider($app, $provider));
}
$app->setDeferredServices($manifest['deferred']);
}
/**
* Compile the application manifest file.
*
* @param \Illuminate\Foundation\Application $app
* @param array $providers
* @return array
*/
protected function compileManifest(Application $app, $providers)
{
// The service manifest should contain a list of all of the providers for
// the application so we can compare it on each request to the service
// and determine if the manifest should be recompiled or is current.
$manifest = $this->freshManifest($providers);
foreach ($providers as $provider)
{
$instance = $this->createProvider($app, $provider);
// When recompiling the service manifest, we will spin through each of the
// providers and check if it's a deferred provider or not. If so we'll
// add it's provided services to the manifest and note the provider.
if ($instance->isDeferred())
{
foreach ($instance->provides() as $service)
{
$manifest['deferred'][$service] = $provider;
}
}
// If the service providers are not deferred, we will simply add it to an
// of eagerly loaded providers that will be registered with the app on
// each request to the applications instead of being lazy loaded in.
else
{
$manifest['eager'][] = $provider;
}
}
return $this->writeManifest($manifest);
}
/**
* Create a new provider instance.
*
* @param \Illuminate\Foundation\Application $app
* @param string $provider
* @return \Illuminate\Support\ServiceProvider
*/
public function createProvider(Application $app, $provider)
{
return new $provider($app);
}
/**
* Determine if the manifest should be compiled.
*
* @param array $manifest
* @param array $providers
* @return bool
*/
public function shouldRecompile($manifest, $providers)
{
return is_null($manifest) or $manifest['providers'] != $providers;
}
/**
* Load the service provider manifest JSON file.
*
* @return array
*/
public function loadManifest()
{
$path = $this->manifestPath.'/services.json';
// The service manifest is a file containing a JSON representation of every
// service provided by the application and whether its provider is using
// deferred loading or should be eagerly loaded on each request to us.
if ($this->files->exists($path))
{
return json_decode($this->files->get($path), true);
}
}
/**
* Write the service manifest file to disk.
*
* @param array $manifest
* @return array
*/
public function writeManifest($manifest)
{
$path = $this->manifestPath.'/services.json';
$this->files->put($path, json_encode($manifest));
return $manifest;
}
/**
* Get the manifest file path.
*
* @param \Illuminate\Foundation\Application $app
* @return string
*/
protected function getManifestPath($app)
{
return $this->manifestPath;
}
/**
* Create a fresh manifest array.
*
* @param array $providers
* @return array
*/
protected function freshManifest(array $providers)
{
list($eager, $deferred) = array(array(), array());
return compact('providers', 'eager', 'deferred');
}
/**
* Get the filesystem instance.
*
* @return \Illuminate\Filesystem\Filesystem
*/
public function getFilesystem()
{
return $this->files;
}
}

View File

@@ -0,0 +1,46 @@
<?php namespace Illuminate\Foundation\Providers;
use Illuminate\Foundation\Artisan;
use Illuminate\Support\ServiceProvider;
use Illuminate\Foundation\Console\ChangesCommand;
class ArtisanServiceProvider extends ServiceProvider {
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = true;
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app['artisan'] = $this->app->share(function($app)
{
return new Artisan($app);
});
$this->app['command.changes'] = $this->app->share(function($app)
{
return new ChangesCommand;
});
$this->commands('command.changes');
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array('artisan', 'command.changes');
}
}

View File

@@ -0,0 +1,42 @@
<?php namespace Illuminate\Foundation\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Foundation\Console\CommandMakeCommand;
class CommandCreatorServiceProvider extends ServiceProvider {
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = true;
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app['command.command.make'] = $this->app->share(function($app)
{
return new CommandMakeCommand($app['files']);
});
$this->commands('command.command.make');
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array(
'command.command.make',
);
}
}

View File

@@ -0,0 +1,46 @@
<?php namespace Illuminate\Foundation\Providers;
use Illuminate\Foundation\Composer;
use Illuminate\Support\ServiceProvider;
use Illuminate\Foundation\Console\AutoloadCommand;
class ComposerServiceProvider extends ServiceProvider {
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = true;
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app['composer'] = $this->app->share(function($app)
{
return new Composer($app['files'], $app['path.base']);
});
$this->app['command.dump-autoload'] = $this->app->share(function($app)
{
return new AutoloadCommand($app['composer']);
});
$this->commands('command.dump-autoload');
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array('composer', 'command.dump-autoload');
}
}

View File

@@ -0,0 +1,40 @@
<?php namespace Illuminate\Foundation\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Foundation\Console\KeyGenerateCommand;
class KeyGeneratorServiceProvider extends ServiceProvider {
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = true;
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app['command.key.generate'] = $this->app->share(function($app)
{
return new KeyGenerateCommand($app['files']);
});
$this->commands('command.key.generate');
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array('command.key.generate');
}
}

View File

@@ -0,0 +1,46 @@
<?php namespace Illuminate\Foundation\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Foundation\Console\UpCommand;
use Illuminate\Foundation\Console\DownCommand;
class MaintenanceServiceProvider extends ServiceProvider {
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = true;
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app['command.up'] = $this->app->share(function($app)
{
return new UpCommand;
});
$this->app['command.down'] = $this->app->share(function($app)
{
return new DownCommand;
});
$this->commands('command.up', 'command.down');
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array('command.up', 'command.down');
}
}

View File

@@ -0,0 +1,66 @@
<?php namespace Illuminate\Foundation\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Foundation\Console\OptimizeCommand;
use Illuminate\Foundation\Console\ClearCompiledCommand;
class OptimizeServiceProvider extends ServiceProvider {
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = true;
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->registerOptimizeCommand();
$this->registerClearCompiledCommand();
$this->commands('command.optimize', 'command.clear-compiled');
}
/**
* Register the optimize command.
*
* @return void
*/
protected function registerOptimizeCommand()
{
$this->app['command.optimize'] = $this->app->share(function($app)
{
return new OptimizeCommand($app['composer']);
});
}
/**
* Register the compiled file remover command.
*
* @return void
*/
protected function registerClearCompiledCommand()
{
$this->app['command.clear-compiled'] = $this->app->share(function()
{
return new ClearCompiledCommand;
});
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array('command.optimize', 'command.clear-compiled');
}
}

View File

@@ -0,0 +1,121 @@
<?php namespace Illuminate\Foundation\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Foundation\AssetPublisher;
use Illuminate\Foundation\ConfigPublisher;
use Illuminate\Foundation\Console\AssetPublishCommand;
use Illuminate\Foundation\Console\ConfigPublishCommand;
class PublisherServiceProvider extends ServiceProvider {
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = true;
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->registerAssetPublisher();
$this->registerConfigPublisher();
$this->commands('command.asset.publish', 'command.config.publish');
}
/**
* Register the asset publisher service and command.
*
* @return void
*/
protected function registerAssetPublisher()
{
$this->registerAssetPublishCommand();
$this->app['asset.publisher'] = $this->app->share(function($app)
{
$publicPath = $app['path.public'];
// The asset "publisher" is responsible for moving package's assets into the
// web accessible public directory of an application so they can actually
// be served to the browser. Otherwise, they would be locked in vendor.
$publisher = new AssetPublisher($app['files'], $publicPath);
$publisher->setPackagePath($app['path.base'].'/vendor');
return $publisher;
});
}
/**
* Register the asset publish console command.
*
* @return void
*/
protected function registerAssetPublishCommand()
{
$this->app['command.asset.publish'] = $this->app->share(function($app)
{
return new AssetPublishCommand($app['asset.publisher']);
});
}
/**
* Register the configuration publisher class and command.
*
* @return void
*/
protected function registerConfigPublisher()
{
$this->registerConfigPublishCommand();
$this->app['config.publisher'] = $this->app->share(function($app)
{
$configPath = $app['path'].'/config';
// Once we have created the configuration publisher, we will set the default
// package path on the object so that it knows where to find the packages
// that are installed for the application and can move them to the app.
$publisher = new ConfigPublisher($app['files'], $configPath);
$publisher->setPackagePath($app['path.base'].'/vendor');
return $publisher;
});
}
/**
* Register the configuration publish console command.
*
* @return void
*/
protected function registerConfigPublishCommand()
{
$this->app['command.config.publish'] = $this->app->share(function($app)
{
return new ConfigPublishCommand($app['config.publisher']);
});
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array(
'asset.publisher',
'command.asset.publish',
'config.publisher',
'command.config.publish'
);
}
}

View File

@@ -0,0 +1,40 @@
<?php namespace Illuminate\Foundation\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Foundation\Console\RoutesCommand;
class RouteListServiceProvider extends ServiceProvider {
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = true;
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app['command.routes'] = $this->app->share(function($app)
{
return new RoutesCommand($app['router']);
});
$this->commands('command.routes');
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array('command.routes');
}
}

View File

@@ -0,0 +1,40 @@
<?php namespace Illuminate\Foundation\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Foundation\Console\ServeCommand;
class ServerServiceProvider extends ServiceProvider {
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = true;
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app['command.serve'] = $this->app->share(function()
{
return new ServeCommand;
});
$this->commands('command.serve');
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array('command.serve');
}
}

View File

@@ -0,0 +1,40 @@
<?php namespace Illuminate\Foundation\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Foundation\Console\TinkerCommand;
class TinkerServiceProvider extends ServiceProvider {
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = true;
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app['command.tinker'] = $this->app->share(function()
{
return new TinkerCommand;
});
$this->commands('command.tinker');
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array('command.tinker');
}
}

View File

@@ -0,0 +1,40 @@
<?php namespace Illuminate\Foundation\Testing;
use Illuminate\Http\Request;
use Illuminate\Foundation\Application;
use Symfony\Component\HttpKernel\Client as BaseClient;
use Symfony\Component\BrowserKit\Request as DomRequest;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
class Client extends BaseClient {
/**
* Convert a BrowserKit request into a Illuminate request.
*
* @param \Symfony\Component\BrowserKit\Request $request
* @return \Illuminate\Http\Request
*/
protected function filterRequest(DomRequest $request)
{
$httpRequest = Application::onRequest('create', $this->getRequestParameters($request));
$httpRequest->files->replace($this->filterFiles($httpRequest->files->all()));
return $httpRequest;
}
/**
* Get the request parameters from a BrowserKit request.
*
* @param \Symfony\Component\BrowserKit\Request $request
* @return array
*/
protected function getRequestParameters(DomRequest $request)
{
return array(
$request->getUri(), $request->getMethod(), $request->getParameters(), $request->getCookies(),
$request->getFiles(), $request->getServer(), $request->getContent()
);
}
}

View File

@@ -0,0 +1,346 @@
<?php namespace Illuminate\Foundation\Testing;
use Illuminate\View\View;
use Illuminate\Auth\UserInterface;
class TestCase extends \PHPUnit_Framework_TestCase {
/**
* The Illuminate application instance.
*
* @var \Illuminate\Foundation\Application
*/
protected $app;
/**
* The HttpKernel client instance.
*
* @var \Illuminate\Foundation\Testing\Client
*/
protected $client;
/**
* Setup the test environment.
*
* @return void
*/
public function setUp()
{
$this->refreshApplication();
}
/**
* Refresh the application instance.
*
* @return void
*/
protected function refreshApplication()
{
$this->app = $this->createApplication();
$this->client = $this->createClient();
}
/**
* Call the given URI and return the Response.
*
* @param string $method
* @param string $uri
* @param array $parameters
* @param array $files
* @param array $server
* @param string $content
* @param bool $changeHistory
* @return \Illuminate\Http\Response
*/
public function call()
{
call_user_func_array(array($this->client, 'request'), func_get_args());
return $this->client->getResponse();
}
/**
* Call the given HTTPS URI and return the Response.
*
* @param string $method
* @param string $uri
* @param array $parameters
* @param array $files
* @param array $server
* @param string $content
* @param bool $changeHistory
* @return \Illuminate\Http\Response
*/
public function callSecure()
{
$parameters = func_get_args();
$parameters[1] = 'https://localhost/'.ltrim($parameters[1], '/');
return call_user_func_array(array($this, 'call'), $parameters);
}
/**
* Call a controller action and return the Response.
*
* @param string $method
* @param string $action
* @param array $wildcards
* @param array $parameters
* @param array $files
* @param array $server
* @param string $content
* @param bool $changeHistory
* @return \Illuminate\Http\Response
*/
public function action($method, $action, $wildcards = array(), $parameters = array(), $files = array(), $server = array(), $content = null, $changeHistory = true)
{
$uri = $this->app['url']->action($action, $wildcards, true);
return $this->call($method, $uri, $parameters, $files, $server, $content, $changeHistory);
}
/**
* Call a named route and return the Response.
*
* @param string $method
* @param string $name
* @param array $routeParameters
* @param array $parameters
* @param array $files
* @param array $server
* @param string $content
* @param bool $changeHistory
* @return \Illuminate\Http\Response
*/
public function route($method, $name, $routeParameters = array(), $parameters = array(), $files = array(), $server = array(), $content = null, $changeHistory = true)
{
$uri = $this->app['url']->route($name, $routeParameters, true);
return $this->call($method, $uri, $parameters, $files, $server, $content, $changeHistory);
}
/**
* Assert that the client response has an OK status code.
*
* @return void
*/
public function assertResponseOk()
{
$response = $this->client->getResponse();
$actual = $response->getStatusCode();
return $this->assertTrue($response->isOk(), 'Expected status code 200, got ' .$actual);
}
/**
* Assert that the client response has a given code.
*
* @param int $code
* @return void
*/
public function assertResponseStatus($code)
{
return $this->assertEquals($code, $this->client->getResponse()->getStatusCode());
}
/**
* Assert that the response view has a given piece of bound data.
*
* @param string|array $key
* @param mixed $value
* @return void
*/
public function assertViewHas($key, $value = null)
{
if (is_array($key)) return $this->assertViewHasAll($key);
$response = $this->client->getResponse()->original;
if ( ! $response instanceof View)
{
return $this->assertTrue(false, 'The response was not a view.');
}
if (is_null($value))
{
$this->assertArrayHasKey($key, $response->getData());
}
else
{
$this->assertEquals($value, $response->$key);
}
}
/**
* Assert that the view has a given list of bound data.
*
* @param array $bindings
* @return void
*/
public function assertViewHasAll(array $bindings)
{
foreach ($bindings as $key => $value)
{
if (is_int($key))
{
$this->assertViewHas($value);
}
else
{
$this->assertViewHas($key, $value);
}
}
}
/**
* Assert whether the client was redirected to a given URI.
*
* @param string $uri
* @param array $with
* @return void
*/
public function assertRedirectedTo($uri, $with = array())
{
$response = $this->client->getResponse();
$this->assertInstanceOf('Illuminate\Http\RedirectResponse', $response);
$this->assertEquals($this->app['url']->to($uri), $response->headers->get('Location'));
$this->assertSessionHasAll($with);
}
/**
* Assert whether the client was redirected to a given route.
*
* @param string $name
* @param array $parameters
* @param array $with
* @return void
*/
public function assertRedirectedToRoute($name, $parameters = array(), $with = array())
{
$this->assertRedirectedTo($this->app['url']->route($name, $parameters), $with);
}
/**
* Assert whether the client was redirected to a given action.
*
* @param string $name
* @param array $parameters
* @param array $with
* @return void
*/
public function assertRedirectedToAction($name, $parameters = array(), $with = array())
{
$this->assertRedirectedTo($this->app['url']->action($name, $parameters), $with);
}
/**
* Assert that the session has a given list of values.
*
* @param string|array $key
* @param mixed $value
* @return void
*/
public function assertSessionHas($key, $value = null)
{
if (is_array($key)) return $this->assertSessionHasAll($key);
if (is_null($value))
{
$this->assertTrue($this->app['session']->has($key));
}
else
{
$this->assertEquals($value, $this->app['session']->get($key));
}
}
/**
* Assert that the session has a given list of values.
*
* @param array $bindings
* @return void
*/
public function assertSessionHasAll(array $bindings)
{
foreach ($bindings as $key => $value)
{
if (is_int($key))
{
$this->assertSessionHas($value);
}
else
{
$this->assertSessionHas($key, $value);
}
}
}
/**
* Assert that the session has errors bound.
*
* @param string|array $bindings
* @param mixed $format
* @return void
*/
public function assertSessionHasErrors($bindings = array(), $format = null)
{
$this->assertSessionHas('errors');
$bindings = (array)$bindings;
$errors = $this->app['session']->get('errors');
foreach ($bindings as $key => $value)
{
if (is_int($key))
{
$this->assertTrue($errors->has($value));
}
else
{
$this->assertContains($value, $errors->get($key, $format));
}
}
}
/**
* Set the currently logged in user for the application.
*
* @param \Illuminate\Auth\UserInterface $user
* @param string $driver
* @return void
*/
public function be(UserInterface $user, $driver = null)
{
$this->app['auth']->driver($driver)->setUser($user);
}
/**
* Seed a given database connection.
*
* @param string $class
* @return void
*/
public function seed($class = 'DatabaseSeeder')
{
$this->app[$class]->run();
}
/**
* Create a new HttpKernel client instance.
*
* @param array $server
* @return \Symfony\Component\HttpKernel\Client
*/
protected function createClient(array $server = array())
{
return new Client($this->app, $server);
}
}

View File

@@ -0,0 +1,36 @@
{
"4.0.x": [
{"message": "Added implode method to query builder and Colletion class.", "backport": null},
{"message": "Fixed bug that caused Model->push method to fail.", "backport": null},
{"message": "Make session cookie HttpOnly by default.", "backport": null},
{"message": "Added mail.pretend configuration option.", "backport": null},
{"message": "Query elapsed time is now reported as float instead of string.", "backport": null},
{"message": "Added Model::query method for generating an empty query builder.", "backport": null},
{"message": "The @yield Blade directive now accepts a default value as the second argument.", "backport": null},
{"message": "Fixed bug causing null to be passed to auth.logout event.", "backport": null},
{"message": "Added polyfill for array_column forward compatibility.", "backport": null},
{"message": "Passing NULL to validator exists rule as extra condition will do where null check.", "backport": null},
{"message": "Auth::extend Closures should only return UserProviderInterface implementations.", "backport": null},
{"message": "Make it easier to extend the Request class.", "backport": null},
{"message": "Transparent support for APCu cache via 'apc' driver.", "backport": null},
{"message": "Add morphs short-cut for adding polymorphic schema columns.", "backport": null},
{"message": "Namespaces are now excluded from guessed model names.", "backport": null},
{"message": "Added new --command option to command:make Artisan command.", "backport": null},
{"message": "Added mediumText and longText to schema builder.", "backport": null},
{"message": "Added support for macros on the Response class.", "backport": null},
{"message": "Added support for view creators in addition to composers.", "backport": null},
{"message": "Allow App::down to be bypassed if the event returns null.", "backport": null},
{"message": "Added Request::format function to get human-readable expected Response format.", "backport": null},
{"message": "Allow array sizes to be checked by validator.", "backport": null},
{"message": "Added support for where conditions on unique validation rule.", "backport": null},
{"message": "Restore method on Eloquent models now fires restoring and restored events.", "backport": null},
{"message": "Fixed re-population of radio buttons and checkboxes in FormBuilder.", "backport": null},
{"message": "Postgres ENUMs are now more truly implemented using 'check' constraints.", "backport": null},
{"message": "Added selectMonth and selectYear to FormBuilder.", "backport": null},
{"message": "Fix container resolution of default values for non-scalar dependencies.", "backport": null},
{"message": "Allow optional path to be specified with calling _path helpers.", "backport": null},
{"message": "Emulate nested transactions in the database connection layer.", "backport": null},
{"message": "Added new appends property to Eloquent for adding ot arrays and JSON.", "backport": null},
{"message": "Allow connection to be configurable when using Redis based sessions.", "backport": null}
]
}

View File

@@ -0,0 +1,254 @@
<?php
/*
|--------------------------------------------------------------------------
| Set PHP Error Reporting Options
|--------------------------------------------------------------------------
|
| Here we will set the strictest error reporting options, and also turn
| off PHP's error reporting, since all errors will be handled by the
| framework and we don't want any output leaking back to the user.
|
*/
error_reporting(-1);
/*
|--------------------------------------------------------------------------
| Check Extensions
|--------------------------------------------------------------------------
|
| Laravel requires a few extensions to function. Here we will check the
| loaded extensions to make sure they are present. If not we'll just
| bail from here. Otherwise, Composer will crazily fall back code.
|
*/
if ( ! extension_loaded('mcrypt'))
{
die('Laravel requires the Mcrypt PHP extension.'.PHP_EOL);
exit(1);
}
/*
|--------------------------------------------------------------------------
| Register Class Imports
|--------------------------------------------------------------------------
|
| Here we will just import a few classes that we need during the booting
| of the framework. These are mainly classes that involve loading the
| config files for this application, such as the config repository.
|
*/
use Illuminate\Http\Request;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Facades\Facade;
use Illuminate\Foundation\AliasLoader;
use Illuminate\Config\Repository as Config;
/*
|--------------------------------------------------------------------------
| Bind The Application In The Container
|--------------------------------------------------------------------------
|
| This may look strange, but we actually want to bind the app into itself
| in case we need to Facade test an application. This will allow us to
| resolve the "app" key out of this container for this app's facade.
|
*/
$app->instance('app', $app);
/*
|--------------------------------------------------------------------------
| Check For The Test Environment
|--------------------------------------------------------------------------
|
| If the "unitTesting" variable is set, it means we are running the unit
| tests for the application and should override this environment here
| so we use the right configuration. The flag gets set by TestCase.
|
*/
if (isset($unitTesting))
{
$app['env'] = $env = $testEnvironment;
}
/*
|--------------------------------------------------------------------------
| Load The Illuminate Facades
|--------------------------------------------------------------------------
|
| The facades provide a terser static interface over the various parts
| of the application, allowing their methods to be accessed through
| a mixtures of magic methods and facade derivatives. It's slick.
|
*/
Facade::clearResolvedInstances();
Facade::setFacadeApplication($app);
/*
|--------------------------------------------------------------------------
| Register The Configuration Repository
|--------------------------------------------------------------------------
|
| The configuration repository is used to lazily load in the options for
| this application from the configuration files. The files are easily
| separated by their concerns so they do not become really crowded.
|
*/
$config = new Config($app->getConfigLoader(), $env);
$app->instance('config', $config);
/*
|--------------------------------------------------------------------------
| Register Application Exception Handling
|--------------------------------------------------------------------------
|
| We will go ahead and register the application exception handling here
| which will provide a great output of exception details and a stack
| trace in the case of exceptions while an application is running.
|
*/
$app->startExceptionHandling();
if ($env != 'testing') ini_set('display_errors', 'Off');
/*
|--------------------------------------------------------------------------
| Set The Console Request If Necessary
|--------------------------------------------------------------------------
|
| If we're running in a console context, we won't have a host on this
| request so we'll need to re-bind a new request with a URL from a
| configuration file. This will help the URL generator generate.
|
*/
if ($app->runningInConsole())
{
$app->setRequestForConsoleEnvironment();
}
/*
|--------------------------------------------------------------------------
| Set The Default Timezone
|--------------------------------------------------------------------------
|
| Here we will set the default timezone for PHP. PHP is notoriously mean
| if the timezone is not explicitly set. This will be used by each of
| the PHP date and date-time functions throughout the application.
|
*/
$config = $app['config']['app'];
date_default_timezone_set($config['timezone']);
/*
|--------------------------------------------------------------------------
| Register The Alias Loader
|--------------------------------------------------------------------------
|
| The alias loader is responsible for lazy loading the class aliases setup
| for the application. We will only register it if the "config" service
| is bound in the application since it contains the alias definitions.
|
*/
AliasLoader::getInstance($config['aliases'])->register();
/*
|--------------------------------------------------------------------------
| Enable HTTP Method Override
|--------------------------------------------------------------------------
|
| Next we will tell the request class to allow HTTP method overriding
| since we use this to simulate PUT and DELETE requests from forms
| as they are not currently supported by plain HTML form setups.
|
*/
Request::enableHttpMethodParameterOverride();
/*
|--------------------------------------------------------------------------
| Register The Core Service Providers
|--------------------------------------------------------------------------
|
| The Illuminate core service providers register all of the core pieces
| of the Illuminate framework including session, caching, encryption
| and more. It's simply a convenient wrapper for the registration.
|
*/
$providers = $config['providers'];
$app->getProviderRepository()->load($app, $providers);
/*
|--------------------------------------------------------------------------
| Boot The Application
|--------------------------------------------------------------------------
|
| Before we handle the requests we need to make sure the application has
| been booted up. The boot process will call the "boot" method on all
| service provider giving all a chance to register their overrides.
|
*/
$app->boot();
/*
|--------------------------------------------------------------------------
| Load The Application Start Script
|--------------------------------------------------------------------------
|
| The start script gives us the application the opportunity to override
| any of the existing IoC bindings, as well as register its own new
| bindings for things like repositories, etc. We'll load it here.
|
*/
$path = $app['path'].'/start/global.php';
if (file_exists($path)) require $path;
/*
|--------------------------------------------------------------------------
| Load The Environment Start Script
|--------------------------------------------------------------------------
|
| The environment start script is only loaded if it exists for the app
| environment currently active, which allows some actions to happen
| in one environment while not in the other, keeping things clean.
|
*/
$path = $app['path']."/start/{$env}.php";
if (file_exists($path)) require $path;
/*
|--------------------------------------------------------------------------
| Load The Application Routes
|--------------------------------------------------------------------------
|
| The Application routes are kept separate from the application starting
| just to keep the file a little cleaner. We'll go ahead and load in
| all of the routes now and return the application to the callers.
|
*/
if (file_exists($path = $app['path'].'/routes.php'))
{
require $path;
}