storage/logs/.gitignore 0000666 00000000016 13436751307 0011156 0 ustar 00 *
!.gitignore
phpunit.xml 0000666 00000001414 13436751307 0006772 0 ustar 00
./tests./src
config/mail.php 0000666 00000010521 13436751307 0007460 0 ustar 00 env('MAIL_DRIVER', 'smtp'),
/*
|--------------------------------------------------------------------------
| SMTP Host Address
|--------------------------------------------------------------------------
|
| Here you may provide the host address of the SMTP server used by your
| applications. A default option is provided that is compatible with
| the Mailgun mail service which will provide reliable deliveries.
|
*/
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
/*
|--------------------------------------------------------------------------
| SMTP Host Port
|--------------------------------------------------------------------------
|
| This is the SMTP port used by your application to deliver e-mails to
| users of the application. Like the host we have set this value to
| stay compatible with the Mailgun e-mail application by default.
|
*/
'port' => env('MAIL_PORT', 587),
/*
|--------------------------------------------------------------------------
| Global "From" Address
|--------------------------------------------------------------------------
|
| You may wish for all e-mails sent by your application to be sent from
| the same address. Here, you may specify a name and address that is
| used globally for all e-mails that are sent by your application.
|
*/
'from' => ['address' => env('MAIL_FROM_ADDRESS'), 'name' => env('MAIL_FROM_NAME')],
/*
|--------------------------------------------------------------------------
| E-Mail Encryption Protocol
|--------------------------------------------------------------------------
|
| Here you may specify the encryption protocol that should be used when
| the application send e-mail messages. A sensible default using the
| transport layer security protocol should provide great security.
|
*/
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
/*
|--------------------------------------------------------------------------
| SMTP Server Username
|--------------------------------------------------------------------------
|
| If your SMTP server requires a username for authentication, you should
| set it here. This will get used to authenticate with your server on
| connection. You may also set the "password" value below this one.
|
*/
'username' => env('MAIL_USERNAME'),
/*
|--------------------------------------------------------------------------
| SMTP Server Password
|--------------------------------------------------------------------------
|
| Here you may set the password required by your SMTP server to send out
| messages from your application. This will be given to the server on
| connection so that the application will be able to send messages.
|
*/
'password' => env('MAIL_PASSWORD'),
/*
|--------------------------------------------------------------------------
| Sendmail System Path
|--------------------------------------------------------------------------
|
| When using the "sendmail" driver to send e-mails, we will need to know
| the path to where Sendmail lives on this server. A default path has
| been provided here, which will work well on most of your systems.
|
*/
'sendmail' => '/usr/sbin/sendmail -bs',
/*
|--------------------------------------------------------------------------
| Mail "Pretend"
|--------------------------------------------------------------------------
|
| When this option is enabled, e-mail will not actually be sent over the
| web and will instead be written to your application's logs files so
| you may inspect the message. This is great for local development.
|
*/
'pretend' => false,
];
config/filesystems.php 0000666 00000004367 13436751307 0011120 0 ustar 00 env('FILESYSTEM_DRIVER', 'local'),
/*
|--------------------------------------------------------------------------
| Default Cloud Filesystem Disk
|--------------------------------------------------------------------------
|
| Many applications store files both locally and in the cloud. For this
| reason, you may specify a default "cloud" driver here. This driver
| will be bound as the Cloud disk implementation in the container.
|
*/
'cloud' => env('FILESYSTEM_CLOUD', 's3'),
/*
|--------------------------------------------------------------------------
| Filesystem Disks
|--------------------------------------------------------------------------
|
| Here you may configure as many filesystem "disks" as you wish, and you
| may even configure multiple disks of the same driver. Defaults have
| been setup for each driver as an example of the required options.
|
*/
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
's3' => [
'driver' => 's3',
'key' => env('S3_KEY'),
'secret' => env('S3_SECRET'),
'region' => env('S3_REGION'),
'bucket' => env('S3_BUCKET'),
'base_url' => env('S3_URL'),
],
'rackspace' => [
'driver' => 'rackspace',
'username' => env('RACKSPACE_USERNAME'),
'key' => env('RACKSPACE_KEY'),
'container' => env('RACKSPACE_CONTAINER'),
'endpoint' => 'https://identity.api.rackspacecloud.com/v2.0/',
'region' => env('RACKSPACE_REGION'),
'url_type' => 'publicURL'
],
],
];
config/session.php 0000666 00000012460 13436751307 0010225 0 ustar 00 env('SESSION_DRIVER', 'memcached'),
/*
|--------------------------------------------------------------------------
| Session Lifetime
|--------------------------------------------------------------------------
|
| Here you may specify the number of minutes that you wish the session
| to be allowed to remain idle before it expires. If you want them
| to immediately expire on the browser closing, set that option.
|
*/
'lifetime' => env('SESSION_LIFETIME', 120),
'expire_on_close' => env('SESSION_EXPIRE_ON_CLOSE', false),
/*
|--------------------------------------------------------------------------
| Session Encryption
|--------------------------------------------------------------------------
|
| This option allows you to easily specify that all of your session data
| should be encrypted before it is stored. All encryption will be run
| automatically by Laravel and you can use the Session like normal.
|
*/
'encrypt' => false,
/*
|--------------------------------------------------------------------------
| Session File Location
|--------------------------------------------------------------------------
|
| When using the native session driver, we need a location where session
| files may be stored. A default has been set for you but a different
| location may be specified. This is only needed for file sessions.
|
*/
'files' => storage_path('framework/sessions'),
/*
|--------------------------------------------------------------------------
| Session Database Connection
|--------------------------------------------------------------------------
|
| When using the "database" or "redis" session drivers, you may specify a
| connection that should be used to manage these sessions. This should
| correspond to a connection in your database configuration options.
|
*/
'connection' => env('SESSION_DATABASE_CONNECTION'),
/*
|--------------------------------------------------------------------------
| Session Database Table
|--------------------------------------------------------------------------
|
| When using the "database" session driver, you may specify the table we
| should use to manage the sessions. Of course, a sensible default is
| provided for you; however, you are free to change this as needed.
|
*/
'table' => env('SESSION_DATABASE_TABLE', 'sessions'),
/*
|--------------------------------------------------------------------------
| Session Sweeping Lottery
|--------------------------------------------------------------------------
|
| Some session drivers must manually sweep their storage location to get
| rid of old sessions from storage. Here are the chances that it will
| happen on a given request. By default, the odds are 2 out of 100.
|
*/
'lottery' => [2, 100],
/*
|--------------------------------------------------------------------------
| Session Cookie Name
|--------------------------------------------------------------------------
|
| Here you may change the name of the cookie used to identify a session
| instance by ID. The name specified here will get used every time a
| new session cookie is created by the framework for every driver.
|
*/
'cookie' => 'laravel_session',
/*
|--------------------------------------------------------------------------
| Session Cookie Path
|--------------------------------------------------------------------------
|
| The session cookie path determines the path for which the cookie will
| be regarded as available. Typically, this will be the root path of
| your application but you are free to change this when necessary.
|
*/
'path' => '/',
/*
|--------------------------------------------------------------------------
| Session Cookie Domain
|--------------------------------------------------------------------------
|
| Here you may change the domain of the cookie used to identify a session
| in your application. This will determine which domains the cookie is
| available to in your application. A sensible default has been set.
|
*/
'domain' => null,
/*
|--------------------------------------------------------------------------
| HTTPS Only Cookies
|--------------------------------------------------------------------------
|
| By setting this option to true, session cookies will only be sent back
| to the server if the browser has a HTTPS connection. This will keep
| the cookie from being sent to you if it can not be done securely.
|
*/
'secure' => false,
];
config/queue.php 0000666 00000005151 13436751307 0007665 0 ustar 00 env('QUEUE_DRIVER', 'sync'),
/*
|--------------------------------------------------------------------------
| Queue Connections
|--------------------------------------------------------------------------
|
| Here you may configure the connection information for each server that
| is used by your application. A default configuration has been added
| for each back-end shipped with Laravel. You are free to add more.
|
*/
'connections' => [
'sync' => [
'driver' => 'sync',
],
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'expire' => 60,
],
'beanstalkd' => [
'driver' => 'beanstalkd',
'host' => 'localhost',
'queue' => 'default',
'ttr' => 60,
],
'sqs' => [
'driver' => 'sqs',
'key' => 'your-public-key',
'secret' => 'your-secret-key',
'queue' => 'your-queue-url',
'region' => 'us-east-1',
],
'iron' => [
'driver' => 'iron',
'host' => 'mq-aws-us-east-1.iron.io',
'token' => 'your-token',
'project' => 'your-project-id',
'queue' => 'your-queue-name',
'encrypt' => true,
],
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => 'default',
'expire' => 60,
],
],
/*
|--------------------------------------------------------------------------
| Failed Queue Jobs
|--------------------------------------------------------------------------
|
| These options configure the behavior of failed queue job logging so you
| can control which database and table are used to store the jobs that
| have failed. You may change them to any database / table you wish.
|
*/
'failed' => [
'database' => 'mysql', 'table' => 'failed_jobs',
],
];
config/database.php 0000666 00000010423 13436751307 0010303 0 ustar 00 PDO::FETCH_CLASS,
/*
|--------------------------------------------------------------------------
| Default Database Connection Name
|--------------------------------------------------------------------------
|
| Here you may specify which of the database connections below you wish
| to use as your default connection for all database work. Of course
| you may use many connections at once using the Database library.
|
*/
'default' => env('DB_CONNECTION', 'mysql'),
/*
|--------------------------------------------------------------------------
| Database Connections
|--------------------------------------------------------------------------
|
| Here are each of the database connections setup for your application.
| Of course, examples of configuring each database platform that is
| supported by Laravel is shown below to make development simple.
|
|
| All database work in Laravel is done through the PHP PDO facilities
| so make sure you have the driver for your particular database of
| choice installed on your machine before you begin development.
|
*/
'connections' => [
'testing' => [
'driver' => 'sqlite',
'database' => ':memory:',
],
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', storage_path('database.sqlite')),
'prefix' => env('DB_PREFIX', ''),
],
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => env('DB_PREFIX', ''),
'timezone' => env('DB_TIMEZONE','+00:00'),
'strict' => false,
],
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => env('DB_PREFIX', ''),
'schema' => 'public',
],
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'prefix' => env('DB_PREFIX', ''),
],
],
/*
|--------------------------------------------------------------------------
| Migration Repository Table
|--------------------------------------------------------------------------
|
| This table keeps track of all the migrations that have already run for
| your application. Using this information, we can determine which of
| the migrations on disk haven't actually been run in the database.
|
*/
'migrations' => 'migrations',
/*
|--------------------------------------------------------------------------
| Redis Databases
|--------------------------------------------------------------------------
|
| Redis is an open source, fast, and advanced key-value store that also
| provides a richer set of commands than a typical key-value systems
| such as APC or Memcached. Laravel makes it easy to dig right in.
|
*/
'redis' => [
'cluster' => env('REDIS_CLUSTER', false),
'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
],
];
config/auth.php 0000666 00000004423 13436751307 0007503 0 ustar 00 env('AUTH_DRIVER', 'eloquent'),
/*
|--------------------------------------------------------------------------
| Authentication Model
|--------------------------------------------------------------------------
|
| When using the "Eloquent" authentication driver, we need to know which
| Eloquent model should be used to retrieve your users. Of course, it
| is often just the "User" model but you may use whatever you like.
|
*/
'model' => env('AUTH_MODEL', 'App\User'),
/*
|--------------------------------------------------------------------------
| Authentication Table
|--------------------------------------------------------------------------
|
| When using the "Database" authentication driver, we need to know which
| table should be used to retrieve your users. We have chosen a basic
| default value but you may easily change it to any table you like.
|
*/
'table' => env('AUTH_TABLE', 'users'),
/*
|--------------------------------------------------------------------------
| Password Reset Settings
|--------------------------------------------------------------------------
|
| Here you may set the options for resetting passwords including the view
| that is your password reset e-mail. You can also set the name of the
| table that maintains all of the reset tokens for your application.
|
| The expire time is the number of minutes that the reset token should be
| considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed.
|
*/
'password' => [
'email' => 'emails.password',
'table' => 'password_resets',
'expire' => 60,
],
];
config/app.php 0000666 00000002776 13436751307 0007333 0 ustar 00 env('APP_KEY', 'SomeRandomString!!!'),
'cipher' => MCRYPT_RIJNDAEL_128,
/*
|--------------------------------------------------------------------------
| Application Locale Configuration
|--------------------------------------------------------------------------
|
| The application locale determines the default locale that will be used
| by the translation service provider. You are free to set this value
| to any of the locales which will be supported by the application.
|
*/
'locale' => env('APP_LOCALE', 'en'),
/*
|--------------------------------------------------------------------------
| Application Fallback Locale
|--------------------------------------------------------------------------
|
| The fallback locale determines the locale to use when the current one
| is not available. You may change the value to correspond to any of
| the language folders that are provided through your application.
|
*/
'fallback_locale' => env('APP_FALLBACK_LOCALE', 'en'),
];
config/view.php 0000666 00000001773 13436751307 0007521 0 ustar 00 [
realpath(base_path('resources/views'))
],
/*
|--------------------------------------------------------------------------
| Compiled View Path
|--------------------------------------------------------------------------
|
| This option determines where all the compiled Blade templates will be
| stored for your application. Typically, this is within the storage
| directory. However, as usual, you are free to change this value.
|
*/
'compiled' => realpath(storage_path('framework/views')),
];
config/cache.php 0000666 00000004155 13436751307 0007607 0 ustar 00 env('CACHE_DRIVER', 'memcached'),
/*
|--------------------------------------------------------------------------
| Cache Stores
|--------------------------------------------------------------------------
|
| Here you may define all of the cache "stores" for your application as
| well as their drivers. You may even define multiple stores for the
| same cache driver to group types of items stored in your caches.
|
*/
'stores' => [
'array' => [
'driver' => 'array'
],
'database' => [
'driver' => 'database',
'table' => env('CACHE_DATABASE_TABLE', 'cache'),
'connection' => null,
],
'file' => [
'driver' => 'file',
'path' => storage_path('framework/cache'),
],
'memcached' => [
'driver' => 'memcached',
'servers' => [
[
'host' => env('MEMCACHED_HOST', '127.0.0.1'), 'port' => env('MEMCACHED_PORT', 11211), 'weight' => 100
],
],
],
'redis' => [
'driver' => 'redis',
'connection' => 'default',
],
],
/*
|--------------------------------------------------------------------------
| Cache Key Prefix
|--------------------------------------------------------------------------
|
| When utilizing a RAM based store such as APC or Memcached, there might
| be other applications utilizing the same cache. So, we'll specify a
| value to get prefixed to all our keys so we can avoid collisions.
|
*/
'prefix' => 'laravel',
];
src/Testing/ApplicationTrait.php 0000666 00000010505 13436751307 0012746 0 ustar 00 app = $this->createApplication();
}
/**
* Call the given URI and return the Response.
*
* @param string $method
* @param string $uri
* @param array $parameters
* @param array $cookies
* @param array $files
* @param array $server
* @param string $content
* @return \Illuminate\Http\Response
*/
public function call($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null)
{
$request = Request::create($uri, $method, $parameters, $cookies, $files, $server, $content);
return $this->response = $this->app->prepareResponse($this->app->handle($request));
}
/**
* Call the given HTTPS URI and return the Response.
*
* @param string $method
* @param string $uri
* @param array $parameters
* @param array $cookies
* @param array $files
* @param array $server
* @param string $content
* @return \Illuminate\Http\Response
*/
public function callSecure($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null)
{
$uri = 'https://localhost/'.ltrim($uri, '/');
return $this->response = $this->call($method, $uri, $parameters, $cookies, $files, $server, $content);
}
/**
* Call a named route and return the Response.
*
* @param string $method
* @param string $name
* @param array $routeParameters
* @param array $parameters
* @param array $cookies
* @param array $files
* @param array $server
* @param string $content
* @return \Illuminate\Http\Response
*/
public function route($method, $name, $routeParameters = [], $parameters = [], $cookies = [], $files = [], $server = [], $content = null)
{
$uri = $this->app['url']->route($name, $routeParameters);
return $this->response = $this->call($method, $uri, $parameters, $cookies, $files, $server, $content);
}
/**
* Set the session to the given array.
*
* @param array $data
* @return void
*/
public function session(array $data)
{
$this->startSession();
foreach ($data as $key => $value) {
$this->app['session']->put($key, $value);
}
}
/**
* Flush all of the current session data.
*
* @return void
*/
public function flushSession()
{
$this->startSession();
$this->app['session']->flush();
}
/**
* Start the session for the application.
*
* @return void
*/
protected function startSession()
{
if (! $this->app['session']->isStarted()) {
$this->app['session']->start();
}
}
/**
* Set the currently logged in user for the application.
*
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @param string $driver
* @return void
*/
public function be(UserContract $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->artisan('db:seed', ['--class' => $class]);
}
/**
* Call artisan command and return code.
*
* @param string $command
* @param array $parameters
* @return int
*/
public function artisan($command, $parameters = [])
{
return $this->code = $this->app['Illuminate\Contracts\Console\Kernel']->call($command, $parameters);
}
}
src/Testing/AssertionsTrait.php 0000666 00000012132 13436751307 0012633 0 ustar 00 response->getStatusCode();
return PHPUnit::assertTrue($this->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)
{
$actual = $this->response->getStatusCode();
return PHPUnit::assertEquals($code, $this->response->getStatusCode(), "Expected status code {$code}, got {$actual}.");
}
/**
* 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);
}
if (! isset($this->response->original) || ! $this->response->original instanceof View) {
return PHPUnit::assertTrue(false, 'The response was not a view.');
}
if (is_null($value)) {
PHPUnit::assertArrayHasKey($key, $this->response->original->getData());
} else {
PHPUnit::assertEquals($value, $this->response->original->$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 that the response view is missing a piece of bound data.
*
* @param string $key
* @return void
*/
public function assertViewMissing($key)
{
if (! isset($this->response->original) || ! $this->response->original instanceof View) {
return PHPUnit::assertTrue(false, 'The response was not a view.');
}
PHPUnit::assertArrayNotHasKey($key, $this->response->original->getData());
}
/**
* Assert whether the client was redirected to a given URI.
*
* @param string $uri
* @param array $with
* @return void
*/
public function assertRedirectedTo($uri, $with = array())
{
PHPUnit::assertInstanceOf('Illuminate\Http\RedirectResponse', $this->response);
PHPUnit::assertEquals($this->app['url']->to($uri), $this->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 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)) {
PHPUnit::assertTrue($this->app['session.store']->has($key), "Session missing key: $key");
} else {
PHPUnit::assertEquals($value, $this->app['session.store']->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.store']->get('errors');
foreach ($bindings as $key => $value) {
if (is_int($key)) {
PHPUnit::assertTrue($errors->has($value), "Session missing error: $value");
} else {
PHPUnit::assertContains($value, $errors->get($key, $format));
}
}
}
/**
* Assert that the session has old input.
*
* @return void
*/
public function assertHasOldInput()
{
$this->assertSessionHas('_old_input');
}
}
src/Testing/TestCase.php 0000666 00000001464 13436751307 0011216 0 ustar 00 app) {
$this->refreshApplication();
}
}
/**
* Clean up the testing environment before the next test.
*
* @return void
*/
public function tearDown()
{
if ($this->app) {
$this->app->flush();
}
}
}
src/Http/Redirector.php 0000666 00000004671 13436751307 0011112 0 ustar 00 app = $app;
}
/**
* Create a new redirect response to the given path.
*
* @param string $path
* @param int $status
* @param array $headers
* @param bool $secure
* @return \Illuminate\Http\RedirectResponse
*/
public function to($path, $status = 302, $headers = array(), $secure = null)
{
$path = $this->app->make('url')->to($path, array(), $secure);
return $this->createRedirect($path, $status, $headers);
}
/**
* Create a new redirect response to a named route.
*
* @param string $route
* @param array $parameters
* @param int $status
* @param array $headers
* @return \Illuminate\Http\RedirectResponse
*/
public function route($route, $parameters = array(), $status = 302, $headers = array())
{
$path = $this->app->make('url')->route($route, $parameters);
return $this->to($path, $status, $headers);
}
/**
* Create a new redirect response to the previous location.
*
* @param int $status
* @param array $headers
* @return \Illuminate\Http\RedirectResponse
*/
public function back($status = 302, $headers = array())
{
$referrer = $this->app->make('request')
->headers->get('referer');
$url = $referrer ? $this->app->make('url')->to($referrer)
: $this->app->make('session')->previousUrl();
return $this->createRedirect($url, $status, $headers);
}
/**
* Create a new redirect response.
*
* @param string $path
* @param int $status
* @param array $headers
* @return \Illuminate\Http\RedirectResponse
*/
protected function createRedirect($path, $status, $headers)
{
$redirect = new RedirectResponse($path, $status, $headers);
$redirect->setRequest($this->app->make('request'));
$redirect->setSession($this->app->make('session.store'));
return $redirect;
}
}
src/Http/Middleware/VerifyCsrfToken.php 0000666 00000004717 13436751307 0014151 0 ustar 00 encrypter = $encrypter;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*
* @throws \Illuminate\Session\TokenMismatchException
*/
public function handle($request, Closure $next)
{
if ($this->isReading($request) || $this->tokensMatch($request)) {
return $this->addCookieToResponse($request, $next($request));
}
throw new TokenMismatchException;
}
/**
* Determine if the session and input CSRF tokens match.
*
* @param \Illuminate\Http\Request $request
* @return bool
*/
protected function tokensMatch($request)
{
$token = $request->input('_token') ?: $request->header('X-CSRF-TOKEN');
if (! $token && $header = $request->header('X-XSRF-TOKEN')) {
$token = $this->encrypter->decrypt($header);
}
return StringUtils::equals($request->session()->token(), $token);
}
/**
* Add the CSRF token to the response cookies.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Http\Response $response
* @return \Illuminate\Http\Response
*/
protected function addCookieToResponse($request, $response)
{
$response->headers->setCookie(
new Cookie('XSRF-TOKEN', $request->session()->token(), time() + 60 * 120, '/', null, false, false)
);
return $response;
}
/**
* Determine if the HTTP request uses a ‘read’ verb.
*
* @param \Illuminate\Http\Request $request
* @return bool
*/
protected function isReading($request)
{
return in_array($request->method(), ['HEAD', 'GET', 'OPTIONS']);
}
}
src/Http/ResponseFactory.php 0000666 00000003456 13436751307 0012136 0 ustar 00 toArray();
}
return new JsonResponse($data, $status, $headers, $options);
}
/**
* Create a new file download response.
*
* @param \SplFileInfo|string $file
* @param string $name
* @param array $headers
* @param null|string $disposition
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse
*/
public function download($file, $name = null, array $headers = array(), $disposition = 'attachment')
{
$response = new BinaryFileResponse($file, 200, $headers, true, $disposition);
if (! is_null($name)) {
return $response->setContentDisposition($disposition, $name, str_replace('%', '', Str::ascii($name)));
}
return $response;
}
}
src/Console/Kernel.php 0000666 00000011103 13436751307 0010677 0 ustar 00 app = $app;
if ($this->includeDefaultCommands) {
$this->app->prepareForConsoleCommand();
}
$this->defineConsoleSchedule();
}
/**
* Define the application's command schedule.
*
* @return void
*/
protected function defineConsoleSchedule()
{
$this->app->instance(
'Illuminate\Console\Scheduling\Schedule', $schedule = new Schedule
);
$this->schedule($schedule);
}
/**
* Run the console application.
*
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @return int
*/
public function handle($input, $output = null)
{
try {
return $this->getArtisan()->run($input, $output);
} catch (Exception $e) {
$this->reportException($e);
$this->renderException($output, $e);
return 1;
}
}
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
//
}
/**
* Run an Artisan console command by name.
*
* @param string $command
* @param array $parameters
* @return int
*/
public function call($command, array $parameters = array())
{
return $this->getArtisan()->call($command, $parameters);
}
/**
* Queue the given console command.
*
* @param string $command
* @param array $parameters
* @return void
*/
public function queue($command, array $parameters = array())
{
throw new RuntimeException("Queueing Artisan commands is not supported by Lumen.");
}
/**
* Get all of the commands registered with the console.
*
* @return array
*/
public function all()
{
return $this->getArtisan()->all();
}
/**
* Get the output for the last run command.
*
* @return string
*/
public function output()
{
return $this->getArtisan()->output();
}
/**
* Get the Artisan application instance.
*
* @return \Illuminate\Console\Application
*/
protected function getArtisan()
{
if (is_null($this->artisan)) {
return $this->artisan = (new Artisan($this->app, $this->app->make('events'), $this->app->version()))
->resolveCommands($this->getCommands());
}
return $this->artisan;
}
/**
* Get the commands to add to the application.
*
* @return array
*/
protected function getCommands()
{
if ($this->includeDefaultCommands) {
return array_merge($this->commands, [
'Illuminate\Console\Scheduling\ScheduleRunCommand',
'Laravel\Lumen\Console\Commands\ServeCommand',
]);
} else {
return $this->commands;
}
}
/**
* Report the exception to the exception handler.
*
* @param \Exception $e
* @return void
*/
protected function reportException(Exception $e)
{
$this->app['Illuminate\Contracts\Debug\ExceptionHandler']->report($e);
}
/**
* Report the exception to the exception handler.
*
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @param \Exception $e
* @return void
*/
protected function renderException($output, Exception $e)
{
$this->app['Illuminate\Contracts\Debug\ExceptionHandler']->renderForConsole($output, $e);
}
}
src/Console/Commands/ServeCommand.php 0000666 00000002442 13436751307 0013611 0 ustar 00 input->getOption('host');
$port = $this->input->getOption('port');
$base = $this->laravel->basePath();
$this->info("Lumen development server started on http://{$host}:{$port}/");
passthru('"'.PHP_BINARY.'"'." -S {$host}:{$port} \"{$base}\"/server.php");
}
/**
* 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),
);
}
}
src/Console/Commands/stubs/DatabaseSeeder.stub 0000666 00000000460 13436751307 0015406 0 ustar 00 call('UserTableSeeder');
}
}
src/Console/Commands/stubs/routes.stub 0000666 00000000725 13436751307 0014077 0 ustar 00 setRoutes(
unserialize(base64_decode('{{routes}}'))
);
src/Foundation/Composer.php 0000666 00000004005 13436751307 0011755 0 ustar 00 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_BINARY.'" composer.phar';
}
return 'composer';
}
/**
* Get a new Symfony process instance.
*
* @return \Symfony\Component\Process\Process
*/
protected function getProcess()
{
return (new Process('', $this->workingPath))->setTimeout(null);
}
/**
* Set the working path used by the class.
*
* @param string $path
* @return $this
*/
public function setWorkingPath($path)
{
$this->workingPath = realpath($path);
return $this;
}
}
src/Application.php 0000666 00000126777 13436751307 0010350 0 ustar 00 basePath = $basePath;
$this->bootstrapContainer();
$this->registerErrorHandling();
}
/**
* Bootstrap the application container.
*
* @return void
*/
protected function bootstrapContainer()
{
static::setInstance($this);
$this->instance('app', $this);
$this->registerContainerAliases();
}
/**
* Get the version number of the application.
*
* @return string
*/
public function version()
{
return 'Lumen (5.0.9) (Laravel Components 5.0.*)';
}
/**
* Get or check the current application environment.
*
* @param mixed
* @return string
*/
public function environment()
{
return env('APP_ENV', 'production');
}
/**
* Determine if the application is currently down for maintenance.
*
* @return bool
*/
public function isDownForMaintenance()
{
return false;
}
/**
* Register all of the configured providers.
*
* @return void
*/
public function registerConfiguredProviders()
{
//
}
/**
* Register a service provider with the application.
*
* @param \Illuminate\Support\ServiceProvider|string $provider
* @param array $options
* @param bool $force
* @return \Illuminate\Support\ServiceProvider
*/
public function register($provider, $options = array(), $force = false)
{
if (!$provider instanceof ServiceProvider) {
$provider = new $provider($this);
}
if (array_key_exists($providerName = get_class($provider), $this->loadedProviders)) {
return;
}
$this->loadedProviders[$providerName] = true;
$provider->register();
$provider->boot();
}
/**
* Register a deferred provider and service.
*
* @param string $provider
* @param string $service
* @return void
*/
public function registerDeferredProvider($provider, $service = null)
{
return $this->register($provider);
}
/**
* Boot the application's service providers.
*
* @return void
*/
public function boot()
{
//
}
/**
* Register a new boot listener.
*
* @param mixed $callback
* @return void
*/
public function booting($callback)
{
//
}
/**
* Register a new "booted" listener.
*
* @param mixed $callback
* @return void
*/
public function booted($callback)
{
//
}
/**
* Set the error handling for the application.
*
* @return void
*/
protected function registerErrorHandling()
{
error_reporting(-1);
set_error_handler(function ($level, $message, $file = '', $line = 0) {
if (error_reporting() & $level) {
throw new ErrorException($message, 0, $level, $file, $line);
}
});
set_exception_handler(function ($e) {
$this->handleUncaughtException($e);
});
}
/**
* Send the exception to the handler and retunr the response.
*
* @param Exception $e
* @return Response
*/
protected function sendExceptionToHandler($e)
{
$handler = $this->make('Illuminate\Contracts\Debug\ExceptionHandler');
$handler->report($e);
return $handler->render($this->make('request'), $e);
}
/**
* Handle an uncaught exception instance.
*
* @param Exception $e
* @return void
*/
protected function handleUncaughtException($e)
{
$handler = $this->make('Illuminate\Contracts\Debug\ExceptionHandler');
$handler->report($e);
if ($this->runningInConsole()) {
$handler->renderForConsole(new ConsoleOutput, $e);
} else {
$handler->render($this->make('request'), $e)->send();
}
}
/**
* Throw an HttpException with the given data.
*
* @param int $code
* @param string $message
* @param array $headers
* @return void
*
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
*/
public function abort($code, $message = '', array $headers = array())
{
if ($code == 404) {
throw new NotFoundHttpException($message);
}
throw new HttpException($code, $message, null, $headers);
}
/**
* Resolve the given type from the container.
*
* @param string $abstract
* @param array $parameters
* @return mixed
*/
public function make($abstract, $parameters = [])
{
if (array_key_exists($abstract, $this->availableBindings) &&
! array_key_exists($this->availableBindings[$abstract], $this->ranServiceBinders)) {
$this->{$method = $this->availableBindings[$abstract]}();
$this->ranServiceBinders[$method] = true;
}
return parent::make($abstract, $parameters);
}
/**
* Register container bindings for the application.
*
* @return void
*/
protected function registerAuthBindings()
{
$this->singleton('auth', function () {
return $this->loadComponent('auth', 'Illuminate\Auth\AuthServiceProvider', 'auth');
});
$this->singleton('auth.driver', function () {
return $this->loadComponent('auth', 'Illuminate\Auth\AuthServiceProvider', 'auth.driver');
});
$this->singleton('auth.password', function () {
return $this->loadComponent('auth', 'Illuminate\Auth\Passwords\PasswordResetServiceProvider', 'auth.password');
});
}
/**
* Register container bindings for the application.
*
* @return void
*/
protected function registerBusBindings()
{
$this->singleton('Illuminate\Contracts\Bus\Dispatcher', function () {
$this->register('Illuminate\Bus\BusServiceProvider');
return $this->make('Illuminate\Contracts\Bus\Dispatcher');
});
}
/**
* Register container bindings for the application.
*
* @return void
*/
protected function registerCacheBindings()
{
$this->singleton('cache', function () {
return $this->loadComponent('cache', 'Illuminate\Cache\CacheServiceProvider');
});
}
/**
* Register container bindings for the application.
*
* @return void
*/
protected function registerConfigBindings()
{
$this->singleton('config', function () {
return new ConfigRepository;
});
}
/**
* Register container bindings for the application.
*
* @return void
*/
protected function registerComposerBindings()
{
$this->app->singleton('composer', function ($app) {
return new Composer($app->make('files'), $this->basePath());
});
}
/**
* Register container bindings for the application.
*
* @return void
*/
protected function registerCookieBindings()
{
$this->singleton('cookie', function () {
return $this->loadComponent('session', 'Illuminate\Cookie\CookieServiceProvider', 'cookie');
});
}
/**
* Register container bindings for the application.
*
* @return void
*/
protected function registerDatabaseBindings()
{
$this->singleton('db', function () {
return $this->loadComponent(
'database', [
'Illuminate\Database\DatabaseServiceProvider',
'Illuminate\Pagination\PaginationServiceProvider'],
'db'
);
});
}
/**
* Register container bindings for the application.
*
* @return void
*/
protected function registerEncrypterBindings()
{
$this->singleton('encrypter', function () {
return $this->loadComponent('app', 'Illuminate\Encryption\EncryptionServiceProvider', 'encrypter');
});
}
/**
* Register container bindings for the application.
*
* @return void
*/
protected function registerEventBindings()
{
$this->singleton('events', function () {
$this->register('Illuminate\Events\EventServiceProvider');
return $this->make('events');
});
}
/**
* Register container bindings for the application.
*
* @return void
*/
protected function registerErrorBindings()
{
if (! $this->bound('Illuminate\Contracts\Debug\ExceptionHandler')) {
$this->singleton(
'Illuminate\Contracts\Debug\ExceptionHandler', 'Laravel\Lumen\Exceptions\Handler'
);
}
}
/**
* Register container bindings for the application.
*
* @return void
*/
protected function registerFilesBindings()
{
$this->singleton('files', function () {
return new Filesystem;
});
$this->singleton('filesystem', function () {
return $this->loadComponent('filesystems', 'Illuminate\Filesystem\FilesystemServiceProvider', 'filesystem');
});
}
/**
* Register container bindings for the application.
*
* @return void
*/
protected function registerHashBindings()
{
$this->singleton('hash', function () {
$this->register('Illuminate\Hashing\HashServiceProvider');
return $this->make('hash');
});
}
/**
* Register container bindings for the application.
*
* @return void
*/
protected function registerLogBindings()
{
$this->singleton('Psr\Log\LoggerInterface', function () {
return new Logger('lumen', [$this->getMonologHandler()]);
});
}
/**
* Get the Monolog handler for the application.
*
* @return \Monolog\Handler\AbstractHandler
*/
protected function getMonologHandler()
{
return (new StreamHandler(storage_path('logs/lumen.log'), Logger::DEBUG))
->setFormatter(new LineFormatter(null, null, true, true));
}
/**
* Register container bindings for the application.
*
* @return void
*/
protected function registerMailBindings()
{
$this->singleton('mailer', function () {
$this->configure('services');
return $this->loadComponent('mail', 'Illuminate\Mail\MailServiceProvider', 'mailer');
});
}
/**
* Register container bindings for the application.
*
* @return void
*/
protected function registerQueueBindings()
{
$this->singleton('queue', function () {
return $this->loadComponent('queue', 'Illuminate\Queue\QueueServiceProvider', 'queue');
});
$this->singleton('queue.connection', function () {
return $this->loadComponent('queue', 'Illuminate\Queue\QueueServiceProvider', 'queue.connection');
});
}
/**
* Register container bindings for the application.
*
* @return void
*/
protected function registerRedisBindings()
{
$this->singleton('redis', function() {
return $this->loadComponent('database', 'Illuminate\Redis\RedisServiceProvider', 'redis');
});
}
/**
* Register container bindings for the application.
*
* @return void
*/
protected function registerRequestBindings()
{
$this->singleton('Illuminate\Http\Request', function () {
return Request::capture()->setUserResolver(function () {
return $this->make('auth')->user();
})->setRouteResolver(function () {
return $this->currentRoute;
});
});
}
/**
* Register container bindings for the application.
*
* @return void
*/
protected function registerSessionBindings()
{
$this->singleton('session', function () {
return $this->loadComponent('session', 'Illuminate\Session\SessionServiceProvider');
});
$this->singleton('session.store', function () {
return $this->loadComponent('session', 'Illuminate\Session\SessionServiceProvider', 'session.store');
});
}
/**
* Register container bindings for the application.
*
* @return void
*/
protected function registerTranslationBindings()
{
$this->singleton('translator', function () {
$this->configure('app');
$this->instance('path.lang', $this->getLanguagePath());
$this->register('Illuminate\Translation\TranslationServiceProvider');
return $this->make('translator');
});
}
/**
* Get the path to the application's language files.
*
* @return string
*/
protected function getLanguagePath()
{
if (is_dir($appPath = $this->resourcePath('lang'))) {
return $appPath;
} else {
return __DIR__.'/../lang';
}
}
/**
* Register container bindings for the application.
*
* @return void
*/
protected function registerUrlGeneratorBindings()
{
$this->singleton('url', function () {
return new Routing\UrlGenerator($this);
});
}
/**
* Register container bindings for the application.
*
* @return void
*/
protected function registerValidatorBindings()
{
$this->singleton('validator', function () {
$this->register('Illuminate\Validation\ValidationServiceProvider');
return $this->make('validator');
});
}
/**
* Register container bindings for the application.
*
* @return void
*/
protected function registerViewBindings()
{
$this->singleton('view', function () {
return $this->loadComponent('view', 'Illuminate\View\ViewServiceProvider');
});
}
/**
* Configure and load the given component and provider.
*
* @param string $config
* @param array|string $providers
* @param string|null $return
* @return mixed
*/
protected function loadComponent($config, $providers, $return = null)
{
$this->configure($config);
foreach ((array) $providers as $provider) {
$this->register($provider);
}
return $this->make($return ?: $config);
}
/**
* Load a configuration file into the application.
*
* @return void
*/
public function configure($name)
{
if (isset($this->loadedConfigurations[$name])) {
return;
}
$this->loadedConfigurations[$name] = true;
$path = $this->getConfigurationPath($name);
if ($path) {
$this->make('config')->set($name, require $path);
}
}
/**
* Get the path to the given configuration file.
*
* @param string $name
* @return string
*/
protected function getConfigurationPath($name)
{
$appConfigPath = ($this->configPath ?: $this->basePath('config')).'/'.$name.'.php';
if (file_exists($appConfigPath)) {
return $appConfigPath;
} elseif (file_exists($path = __DIR__.'/../config/'.$name.'.php')) {
return $path;
}
}
/**
* Register the facades for the application.
*
* @return void
*/
public function withFacades()
{
Facade::setFacadeApplication($this);
if (! static::$aliasesRegistered) {
static::$aliasesRegistered = true;
class_alias('Illuminate\Support\Facades\App', 'App');
class_alias('Illuminate\Support\Facades\Auth', 'Auth');
class_alias('Illuminate\Support\Facades\Bus', 'Bus');
class_alias('Illuminate\Support\Facades\DB', 'DB');
class_alias('Illuminate\Support\Facades\Cache', 'Cache');
class_alias('Illuminate\Support\Facades\Crypt', 'Crypt');
class_alias('Illuminate\Support\Facades\Event', 'Event');
class_alias('Illuminate\Support\Facades\Hash', 'Hash');
class_alias('Illuminate\Support\Facades\Log', 'Log');
class_alias('Illuminate\Support\Facades\Mail', 'Mail');
class_alias('Illuminate\Support\Facades\Queue', 'Queue');
class_alias('Illuminate\Support\Facades\Request', 'Request');
class_alias('Illuminate\Support\Facades\Schema', 'Schema');
class_alias('Illuminate\Support\Facades\Session', 'Session');
class_alias('Illuminate\Support\Facades\Storage', 'Storage');
class_alias('Illuminate\Support\Facades\Validator', 'Validator');
}
}
/**
* Load the Eloquent library for the application.
*
* @return void
*/
public function withEloquent()
{
$this->make('db');
}
/**
* Register a set of routes with a set of shared attributes.
*
* @param array $attributes
* @param Closure $callback
* @return void
*/
public function group(array $attributes, Closure $callback)
{
$this->groupAttributes = $attributes;
call_user_func($callback, $this);
$this->groupAttributes = null;
}
/**
* Register a route with the application.
*
* @param string $uri
* @param mixed $action
* @return $this
*/
public function get($uri, $action)
{
$this->addRoute('GET', $uri, $action);
return $this;
}
/**
* Register a route with the application.
*
* @param string $uri
* @param mixed $action
* @return $this
*/
public function post($uri, $action)
{
$this->addRoute('POST', $uri, $action);
return $this;
}
/**
* Register a route with the application.
*
* @param string $uri
* @param mixed $action
* @return $this
*/
public function put($uri, $action)
{
$this->addRoute('PUT', $uri, $action);
return $this;
}
/**
* Register a route with the application.
*
* @param string $uri
* @param mixed $action
* @return $this
*/
public function patch($uri, $action)
{
$this->addRoute('PATCH', $uri, $action);
return $this;
}
/**
* Register a route with the application.
*
* @param string $uri
* @param mixed $action
* @return $this
*/
public function delete($uri, $action)
{
$this->addRoute('DELETE', $uri, $action);
return $this;
}
/**
* Register a route with the application.
*
* @param string $uri
* @param mixed $action
* @return $this
*/
public function options($uri, $action)
{
$this->addRoute('OPTIONS', $uri, $action);
return $this;
}
/**
* Add a route to the collection.
*
* @param string $method
* @param string $uri
* @param mixed $action
*/
protected function addRoute($method, $uri, $action)
{
$action = $this->parseAction($action);
$uri = $uri === '/' ? $uri : '/'.trim($uri, '/');
if (isset($this->groupAttributes)) {
if (isset($this->groupAttributes['prefix'])) {
$uri = rtrim('/'.trim($this->groupAttributes['prefix'], '/').$uri, '/');
}
$action = $this->mergeGroupAttributes($action);
}
if (isset($action['as'])) {
$this->namedRoutes[$action['as']] = $uri;
}
$this->routes[$method.$uri] = ['method' => $method, 'uri' => $uri, 'action' => $action];
}
/**
* Parse the action into an array format.
*
* @param mixed $action
* @return array
*/
protected function parseAction($action)
{
if (is_string($action)) {
return ['uses' => $action];
} elseif (! is_array($action)) {
return [$action];
}
return $action;
}
/**
* Merge the group attributes into the action.
*
* @param array $action
* @return array
*/
protected function mergeGroupAttributes(array $action)
{
return $this->mergeNamespaceGroup(
$this->mergeMiddlewareGroup($action)
);
}
/**
* Merge the namespace group into the action.
*
* @param array $action
* @return array
*/
protected function mergeNamespaceGroup(array $action)
{
if (isset($this->groupAttributes['namespace']) && isset($action['uses'])) {
$action['uses'] = $this->groupAttributes['namespace'].'\\'.$action['uses'];
}
return $action;
}
/**
* Merge the middleware group into the action.
*
* @param array $action
* @return array
*/
protected function mergeMiddlewareGroup($action)
{
if (isset($this->groupAttributes['middleware'])) {
if (isset($action['middleware'])) {
$action['middleware'] .= '|'.$this->groupAttributes['middleware'];
} else {
$action['middleware'] = $this->groupAttributes['middleware'];
}
}
return $action;
}
/**
* Add new middleware to the application.
*
* @param array $middleware
* @return $this
*/
public function middleware(array $middleware)
{
$this->middleware = array_unique(array_merge($this->middleware, $middleware));
return $this;
}
/**
* Define the route middleware for the application.
*
* @param array $middleware
* @return $this
*/
public function routeMiddleware(array $middleware)
{
$this->routeMiddleware = array_merge($this->routeMiddleware, $middleware);
return $this;
}
/**
* {@inheritdoc}
*/
public function handle(SymfonyRequest $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
{
return $this->dispatch($request);
}
/**
* Run the application and send the response.
*
* @param SymfonyRequest|null $request
* @return void
*/
public function run($request = null)
{
$response = $this->dispatch($request);
if ($response instanceof SymfonyResponse) {
$response->send();
} else {
echo (string) $response;
}
if (count($this->middleware) > 0) {
$this->callTerminableMiddleware($response);
}
}
/**
* Call the terminable middleware.
*
* @param mixed $response
* @return void
*/
protected function callTerminableMiddleware($response)
{
$response = $this->prepareResponse($response);
foreach ($this->middleware as $middleware) {
$instance = $this->make($middleware);
if ($instance instanceof TerminableMiddleware) {
$instance->terminate(
$this->make('request'), $response
);
}
}
}
/**
* Dispatch the incoming request.
*
* @param SymfonyRequest|null $request
* @return Response
*/
public function dispatch($request = null)
{
if ($request) {
$this->instance('Illuminate\Http\Request', $request);
$this->ranServiceBinders['registerRequestBindings'] = true;
$method = $request->getMethod();
$pathInfo = $request->getPathInfo();
} else {
$method = $this->getMethod();
$pathInfo = $this->getPathInfo();
}
try {
if (isset($this->routes[$method.$pathInfo])) {
return $this->handleFoundRoute([true, $this->routes[$method.$pathInfo]['action'], []]);
}
return $this->handleDispatcherResponse(
$this->createDispatcher()->dispatch($method, $pathInfo)
);
} catch (Exception $e) {
return $this->sendExceptionToHandler($e);
}
}
/**
* Create a FastRoute dispatcher instance for the application.
*
* @return Dispatcher
*/
protected function createDispatcher()
{
return $this->dispatcher ?: \FastRoute\simpleDispatcher(function ($r) {
foreach ($this->routes as $route) {
$r->addRoute($route['method'], $route['uri'], $route['action']);
}
});
}
/**
* Set the FastRoute dispatcher instance.
*
* @param \FastRoute\Dispatcher $dispatcher
* @return void
*/
public function setDispatcher(Dispatcher $dispatcher)
{
$this->dispatcher = $dispatcher;
}
/**
* Handle the response from the FastRoute dispatcher.
*
* @param array $routeInfo
* @return mixed
*/
protected function handleDispatcherResponse($routeInfo)
{
switch ($routeInfo[0]) {
case Dispatcher::NOT_FOUND:
throw new NotFoundHttpException;
case Dispatcher::METHOD_NOT_ALLOWED:
throw new MethodNotAllowedHttpException($routeInfo[1]);
case Dispatcher::FOUND:
return $this->handleFoundRoute($routeInfo);
}
}
/**
* Handle a route that was found by the dispatcher.
*
* @param array $routeInfo
* @return mixed
*/
protected function handleFoundRoute($routeInfo)
{
$this->currentRoute = $routeInfo;
// Pipe through global middleware...
if (count($this->middleware) > 0) {
return $this->prepareResponse($this->sendThroughPipeline($this->middleware, function () use ($routeInfo) {
return $this->prepareResponse($this->handleArrayBasedFoundRoute($routeInfo));
}));
}
return $this->handleArrayBasedFoundRoute($routeInfo);
}
/**
* Handle an array based route that was found by the dispatcher.
*
* @param array $routeInfo
* @return mixed
*/
protected function handleArrayBasedFoundRoute($routeInfo)
{
$action = $routeInfo[1];
// Pipe through route middleware...
if (isset($action['middleware'])) {
$middleware = $this->gatherMiddlewareClassNames($action['middleware']);
return $this->prepareResponse($this->sendThroughPipeline($middleware, function () use ($routeInfo) {
return $this->prepareResponse($this->callActionOnArrayBasedRoute($routeInfo));
}));
}
return is_string($response = $this->callActionOnArrayBasedRoute($routeInfo))
? $response : $this->prepareResponse($response);
}
/**
* Call the Closure on the array based route.
*
* @param array $routeInfo
* @return mixed
*/
protected function callActionOnArrayBasedRoute($routeInfo)
{
$action = $routeInfo[1];
if (isset($action['uses'])) {
return $this->callControllerAction($routeInfo);
}
foreach ($action as $value) {
if ($value instanceof Closure) {
$closure = $value->bindTo(new Routing\Closure);
break;
}
}
try {
return $this->call($closure, $routeInfo[2]);
} catch (HttpResponseException $e) {
return $e->getResponse();
}
}
/**
* Call a controller based route.
*
* @param array $routeInfo
* @return mixed
*/
protected function callControllerAction($routeInfo)
{
list($controller, $method) = explode('@', $routeInfo[1]['uses']);
if (! method_exists($instance = $this->make($controller), $method)) {
throw new NotFoundHttpException;
}
if ($instance instanceof Routing\Controller) {
return $this->callLumenController($instance, $method, $routeInfo);
} else {
return $this->callControllerCallable(
[$instance, $method], $routeInfo[2]
);
}
}
/**
* Send the request through a Lumen controller.
*
* @param mixed $instance
* @param string $method
* @param array $routeInfo
* @return mixed
*/
protected function callLumenController($instance, $method, $routeInfo)
{
$middleware = $instance->getMiddlewareForMethod(
$this->make('request'), $method
);
if (count($middleware) > 0) {
return $this->callLumenControllerWithMiddleware(
$instance, $method, $routeInfo, $middleware
);
} else {
return $this->callControllerCallable(
[$instance, $method], $routeInfo[2]
);
}
}
/**
* Send the request through a set of controller middleware.
*
* @param mixed $instance
* @param string $method
* @param array $routeInfo
* @param array $middleware
* @return mixed
*/
protected function callLumenControllerWithMiddleware($instance, $method, $routeInfo, $middleware)
{
$middleware = $this->gatherMiddlewareClassNames($middleware);
return $this->sendThroughPipeline($middleware, function () use ($instance, $method, $routeInfo) {
return $this->callControllerCallable(
[$instance, $method], $routeInfo[2]
);
});
}
/**
* Call the callable for a controller action with the given parameters.
*
* @param array $callable
* @param array $parameters
* @return mixed
*/
protected function callControllerCallable(array $callable, array $parameters)
{
try {
return $this->prepareResponse(
$this->call($callable, $parameters)
);
} catch (HttpResponseException $e) {
return $e->getResponse();
}
}
/**
* Gather the full class names for the middleware short-cut string.
*
* @param string $middleware
* @return array
*/
protected function gatherMiddlewareClassNames($middleware)
{
$middleware = is_string($middleware) ? explode('|', $middleware) : (array) $middleware;
return array_map(function ($name) {
return $this->routeMiddleware[$name];
}, $middleware);
}
/**
* Send the request through the pipeline with the given callback.
*
* @param array $middleware
* @param Closure $then
* @return mixed
*/
protected function sendThroughPipeline(array $middleware, Closure $then)
{
return (new Pipeline($this))
->send($this->make('request'))
->through($middleware)
->then($then);
}
/**
* Prepare the response for sending.
*
* @param mixed $response
* @return Response
*/
public function prepareResponse($response)
{
if (! $response instanceof SymfonyResponse) {
$response = new Response($response);
}
return $response;
}
/**
* Get the current HTTP request method.
*
* @return string
*/
protected function getMethod()
{
if (isset($_POST['_method'])) {
return strtoupper($_POST['_method']);
} else {
return $_SERVER['REQUEST_METHOD'];
}
}
/**
* Get the current HTTP path info.
*
* @return string
*/
public function getPathInfo()
{
$query = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '';
return '/'.trim(str_replace('?'.$query, '', $_SERVER['REQUEST_URI']), '/');
}
/**
* Get the base path for the application.
*
* @param string $path
* @return string
*/
public function basePath($path = null)
{
if (isset($this->basePath)) {
return $this->basePath.($path ? '/'.$path : $path);
}
if ($this->runningInConsole() || php_sapi_name() === 'cli-server') {
$this->basePath = getcwd();
} else {
$this->basePath = realpath(getcwd().'/../');
}
return $this->basePath($path);
}
/**
* Get the storage path for the application.
*
* @param string $path
* @return string
*/
public function storagePath($path = null)
{
if ($this->storagePath) {
return $this->storagePath.($path ? '/'.$path : $path);
}
return $this->basePath().'/storage'.($path ? '/'.$path : $path);
}
/**
* Set a custom storage path for the application.
*
* @param string $path
* @return $this
*/
public function useStoragePath($path)
{
$this->storagePath = $path;
return $this;
}
/**
* Get the database path for the application.
*
* @return string
*/
public function databasePath()
{
return $this->basePath().'/database';
}
/**
* Set a custom configuration path for the application.
*
* @param string $path
* @return $this
*/
public function useConfigPath($path)
{
$this->configPath = $path;
return $this;
}
/**
* Get the resource path for the application.
*
* @param string $path
* @return string
*/
public function resourcePath($path = null)
{
if ($this->resourcePath) {
return $this->resourcePath.($path ? '/'.$path : $path);
}
return $this->basePath().'/resources'.($path ? '/'.$path : $path);
}
/**
* Set a custom resource path for the application.
*
* @param string $path
* @return $this
*/
public function useResourcePath($path)
{
$this->resourcePath = $path;
return $this;
}
/**
* Determine if the application is running in the console.
*
* @return string
*/
public function runningInConsole()
{
return php_sapi_name() == 'cli';
}
/**
* Prepare the application to execute a console command.
*
* @return void
*/
public function prepareForConsoleCommand()
{
$this->withFacades();
$this->make('cache');
$this->make('queue');
$this->configure('database');
$this->register('Illuminate\Database\MigrationServiceProvider');
$this->register('Illuminate\Database\SeedServiceProvider');
$this->register('Illuminate\Queue\ConsoleServiceProvider');
}
/**
* Get the raw routes for the application.
*
* @return array
*/
public function getRoutes()
{
return $this->routes;
}
/**
* Set the cached routes.
*
* @param array $routes
* @return void
*/
public function setRoutes(array $routes)
{
$this->routes = $routes;
}
/**
* Register the core container aliases.
*
* @return void
*/
protected function registerContainerAliases()
{
$this->aliases = [
'Illuminate\Contracts\Foundation\Application' => 'app',
'Illuminate\Contracts\Auth\Guard' => 'auth.driver',
'Illuminate\Contracts\Auth\PasswordBroker' => 'auth.password',
'Illuminate\Contracts\Cache\Factory' => 'cache',
'Illuminate\Contracts\Cache\Repository' => 'cache.store',
'Illuminate\Container\Container' => 'app',
'Illuminate\Contracts\Container\Container' => 'app',
'Illuminate\Contracts\Cookie\Factory' => 'cookie',
'Illuminate\Contracts\Cookie\QueueingFactory' => 'cookie',
'Illuminate\Contracts\Encryption\Encrypter' => 'encrypter',
'Illuminate\Contracts\Events\Dispatcher' => 'events',
'Illuminate\Contracts\Filesystem\Factory' => 'filesystem',
'Illuminate\Contracts\Hashing\Hasher' => 'hash',
'log' => 'Psr\Log\LoggerInterface',
'Illuminate\Contracts\Mail\Mailer' => 'mailer',
'Illuminate\Contracts\Queue\Queue' => 'queue.connection',
'Illuminate\Redis\Database' => 'redis',
'Illuminate\Contracts\Redis\Database' => 'redis',
'request' => 'Illuminate\Http\Request',
'Illuminate\Session\SessionManager' => 'session',
'Illuminate\Contracts\View\Factory' => 'view',
];
}
/**
* The available container bindings and their respective load methods.
*
* @var array
*/
public $availableBindings = [
'auth' => 'registerAuthBindings',
'auth.driver' => 'registerAuthBindings',
'Illuminate\Contracts\Auth\Guard' => 'registerAuthBindings',
'auth.password' => 'registerAuthBindings',
'Illuminate\Contracts\Auth\PasswordBroker' => 'registerAuthBindings',
'Illuminate\Contracts\Bus\Dispatcher' => 'registerBusBindings',
'cache' => 'registerCacheBindings',
'Illuminate\Contracts\Cache\Factory' => 'registerCacheBindings',
'Illuminate\Contracts\Cache\Repository' => 'registerCacheBindings',
'config' => 'registerConfigBindings',
'composer' => 'registerComposerBindings',
'cookie' => 'registerCookieBindings',
'Illuminate\Contracts\Cookie\Factory' => 'registerCookieBindings',
'Illuminate\Contracts\Cookie\QueueingFactory' => 'registerCookieBindings',
'db' => 'registerDatabaseBindings',
'encrypter' => 'registerEncrypterBindings',
'Illuminate\Contracts\Encryption\Encrypter' => 'registerEncrypterBindings',
'events' => 'registerEventBindings',
'Illuminate\Contracts\Events\Dispatcher' => 'registerEventBindings',
'Illuminate\Contracts\Debug\ExceptionHandler' => 'registerErrorBindings',
'files' => 'registerFilesBindings',
'filesystem' => 'registerFilesBindings',
'Illuminate\Contracts\Filesystem\Factory' => 'registerFilesBindings',
'hash' => 'registerHashBindings',
'Illuminate\Contracts\Hashing\Hasher' => 'registerHashBindings',
'log' => 'registerLogBindings',
'Psr\Log\LoggerInterface' => 'registerLogBindings',
'mailer' => 'registerMailBindings',
'Illuminate\Contracts\Mail\Mailer' => 'registerMailBindings',
'queue' => 'registerQueueBindings',
'queue.connection' => 'registerQueueBindings',
'Illuminate\Contracts\Queue\Queue' => 'registerQueueBindings',
'redis' => 'registerRedisBindings',
'request' => 'registerRequestBindings',
'Illuminate\Http\Request' => 'registerRequestBindings',
'session' => 'registerSessionBindings',
'session.store' => 'registerSessionBindings',
'Illuminate\Session\SessionManager' => 'registerSessionBindings',
'translator' => 'registerTranslationBindings',
'url' => 'registerUrlGeneratorBindings',
'validator' => 'registerValidatorBindings',
'view' => 'registerViewBindings',
'Illuminate\Contracts\View\Factory' => 'registerViewBindings',
];
/**
* Get the HTML from the Lumen welcome screen.
*
* @return string
*/
public function welcome()
{
return "
Lumen
Lumen.
";
}
}
src/Exceptions/Handler.php 0000666 00000003740 13436751307 0011563 0 ustar 00 shouldntReport($e)) {
return;
}
app('Psr\Log\LoggerInterface')->error((string) $e);
}
/**
* Determine if the exception should be reported.
*
* @param \Exception $e
* @return bool
*/
public function shouldReport(Exception $e)
{
return ! $this->shouldntReport($e);
}
/**
* Determine if the exception is in the "do not report" list.
*
* @param \Exception $e
* @return bool
*/
protected function shouldntReport(Exception $e)
{
foreach ($this->dontReport as $type) {
if ($e instanceof $type) {
return true;
}
}
return false;
}
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Symfony\Component\HttpFoundation\Response
*/
public function render($request, Exception $e)
{
return (new SymfonyExceptionHandler(env('APP_DEBUG', false)))->createResponse($e);
}
/**
* Render an exception to the console.
*
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @param \Exception $e
* @return void
*/
public function renderForConsole($output, Exception $e)
{
(new ConsoleApplication)->renderException($e, $output);
}
}
src/Providers/CacheServiceProvider.php 0000666 00000001030 13436751307 0014067 0 ustar 00 app->singleton('command.cache.clear', function($app)
{
return new ClearCommand($app['cache']);
});
$this->commands('command.cache.clear');
}
}
src/Routing/ValidatesRequests.php 0000666 00000005140 13436751307 0013160 0 ustar 00 getValidationFactory()->make($request->all(), $rules, $messages);
if ($validator->fails()) {
$this->throwValidationException($request, $validator);
}
}
/**
* Throw the failed validation exception.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Contracts\Validation\Validator $validator
* @return void
*/
protected function throwValidationException(Request $request, $validator)
{
throw new HttpResponseException($this->buildFailedValidationResponse(
$request, $this->formatValidationErrors($validator)
));
}
/**
* Create the response for when a request fails validation.
*
* @param \Illuminate\Http\Request $request
* @param array $errors
* @return \Illuminate\Http\Response
*/
protected function buildFailedValidationResponse(Request $request, array $errors)
{
if ($request->ajax() || $request->wantsJson()) {
return new JsonResponse($errors, 422);
}
return redirect()->to($this->getRedirectUrl())
->withInput($request->input())
->withErrors($errors, $this->errorBag());
}
/**
* Format the validation errors to be returned.
*
* @param \Illuminate\Validation\Validator $validator
* @return array
*/
protected function formatValidationErrors(Validator $validator)
{
return $validator->errors()->getMessages();
}
/**
* Get the URL we should redirect to.
*
* @return string
*/
protected function getRedirectUrl()
{
return app('session')->previousUrl();
}
/**
* Get a validation factory instance.
*
* @return \Illuminate\Contracts\Validation\Factory
*/
protected function getValidationFactory()
{
return app('validator');
}
/**
* Get the key to be used for the view error bag.
*
* @return string
*/
protected function errorBag()
{
return 'default';
}
}
src/Routing/UrlGenerator.php 0000666 00000012366 13436751307 0012131 0 ustar 00 app = $app;
}
/**
* Get the full URL for the current request.
*
* @return string
*/
public function full()
{
return $this->app->make('request')->fullUrl();
}
/**
* Get the current URL for the request.
*
* @return string
*/
public function current()
{
return $this->to($this->app->make('request')->getPathInfo());
}
/**
* Generate a url for the application
*
* @param string $path
* @param array $extra
* @param bool $secure
* @return string
*/
public function to($path, $extra = array(), $secure = null)
{
// First we will check if the URL is already a valid URL. If it is we will not
// try to generate a new one but will simply return the URL as is, which is
// convenient since developers do not always have to check if it's valid.
if ($this->isValidUrl($path)) {
return $path;
}
$scheme = $this->getSchemeForUrl($secure);
$extra = $this->formatParametersForUrl($extra);
$tail = implode('/', array_map(
'rawurlencode', (array) $extra)
);
// Once we have the scheme we will compile the "tail" by collapsing the values
// into a single string delimited by slashes. This just makes it convenient
// for passing the array of parameters to this URL as a list of segments.
$root = $this->getRootUrl($scheme);
return $this->trimUrl($root, $path, $tail);
}
/**
* Get the URL to a named route.
*
* @param string $name
* @param mixed $parameters
* @return string
*
* @throws \InvalidArgumentException
*/
public function route($name, $parameters = array())
{
if (! isset($this->app->namedRoutes[$name])) {
throw new \InvalidArgumentException("Route [{$name}] not defined.");
}
$uri = $this->app->namedRoutes[$name];
foreach ($parameters as $key => $value) {
$uri = preg_replace('/\{'.$key.'.*?\}/', $value, $uri);
}
return $this->to($uri, []);
}
/**
* Determine if the given path is a valid URL.
*
* @param string $path
* @return bool
*/
protected function isValidUrl($path)
{
if (starts_with($path, ['#', '//', 'mailto:', 'tel:', 'http://', 'https://'])) {
return true;
}
return filter_var($path, FILTER_VALIDATE_URL) !== false;
}
/**
* Get the scheme for a raw URL.
*
* @param bool|null $secure
* @return string
*/
protected function getSchemeForUrl($secure)
{
if (is_null($secure)) {
if (is_null($this->cachedScheme)) {
$this->cachedScheme = $this->app->make('request')->getScheme().'://';
}
return $this->cachedScheme;
}
return $secure ? 'https://' : 'http://';
}
/**
* Format the array of URL parameters.
*
* @param mixed|array $parameters
* @return array
*/
protected function formatParametersForUrl($parameters)
{
return $this->replaceRoutableParametersForUrl($parameters);
}
/**
* Replace UrlRoutable parameters with their route parameter.
*
* @param array $parameters
* @return array
*/
protected function replaceRoutableParametersForUrl($parameters = array())
{
$parameters = is_array($parameters) ? $parameters : array($parameters);
foreach ($parameters as $key => $parameter) {
if ($parameter instanceof UrlRoutable) {
$parameters[$key] = $parameter->getRouteKey();
}
}
return $parameters;
}
/**
* Get the base URL for the request.
*
* @param string $scheme
* @param string $root
* @return string
*/
protected function getRootUrl($scheme, $root = null)
{
if (is_null($root)) {
if (is_null($this->cachedRoot)) {
$this->cachedRoot = $this->app->make('request')->root();
}
$root = $this->cachedRoot;
}
$start = starts_with($root, 'http://') ? 'http://' : 'https://';
return preg_replace('~'.$start.'~', $scheme, $root, 1);
}
/**
* Format the given URL segments into a single URL.
*
* @param string $root
* @param string $path
* @param string $tail
* @return string
*/
protected function trimUrl($root, $path, $tail = '')
{
return trim($root.'/'.trim($path.'/'.$tail, '/'), '/');
}
}
src/Routing/Closure.php 0000666 00000003361 13436751307 0011127 0 ustar 00 baseBuildFailedValidationResponse($request, $errors);
}
/**
* {@inheritdoc}
*/
protected function formatValidationErrors(Validator $validator)
{
if (isset(static::$errorFormatter)) {
return call_user_func(static::$errorFormatter, $validator);
}
return $this->baseFormatValidationErrors($validator);
}
}
src/Routing/Controller.php 0000666 00000002310 13436751307 0011627 0 ustar 00 middleware[$middleware] = $options;
}
/**
* Get the middleware for a given method.
*
* @param Request $request
* @param string $method
* @return array
*/
public function getMiddlewareForMethod(Request $request, $method)
{
$middleware = [];
foreach ($this->middleware as $name => $options) {
if (isset($options['only']) && ! in_array($method, (array) $options['only'])) {
continue;
}
if (isset($options['except']) && in_array($method, (array) $options['except'])) {
continue;
}
$middleware[] = $name;
}
return $middleware;
}
}
src/Routing/DispatchesCommands.php 0000666 00000002117 13436751307 0013262 0 ustar 00 dispatch($command);
}
/**
* Marshal a command and dispatch it to its appropriate handler.
*
* @param mixed $command
* @param array $array
* @return mixed
*/
protected function dispatchFromArray($command, array $array)
{
return app('Illuminate\Contracts\Bus\Dispatcher')->dispatchFromArray($command, $array);
}
/**
* Marshal a command and dispatch it to its appropriate handler.
*
* @param mixed $command
* @param \ArrayAccess $source
* @param array $extras
* @return mixed
*/
protected function dispatchFrom($command, ArrayAccess $source, $extras = [])
{
return app('Illuminate\Contracts\Bus\Dispatcher')->dispatchFrom($command, $source, $extras);
}
}
src/helpers.php 0000666 00000022567 13436751307 0007537 0 ustar 00 abort($code, $message, $headers);
}
}
if (! function_exists('app')) {
/**
* Get the available container instance.
*
* @param string $make
* @param array $parameters
* @return mixed|\Laravel\Lumen\Application
*/
function app($make = null, $parameters = [])
{
if (is_null($make)) {
return Container::getInstance();
}
return Container::getInstance()->make($make, $parameters);
}
}
if (! function_exists('base_path')) {
/**
* Get the path to the base of the install.
*
* @param string $path
* @return string
*/
function base_path($path = '')
{
return app()->basePath().($path ? '/'.$path : $path);
}
}
if (! function_exists('bcrypt')) {
/**
* Hash the given value.
*
* @param string $value
* @param array $options
* @return string
*/
function bcrypt($value, $options = array())
{
return app('hash')->make($value, $options);
}
}
if (! function_exists('config')) {
/**
* Get / set the specified configuration value.
*
* If an array is passed as the key, we will assume you want to set an array of values.
*
* @param array|string $key
* @param mixed $default
* @return mixed
*/
function config($key = null, $default = null)
{
if (is_null($key)) {
return app('config');
}
if (is_array($key)) {
return app('config')->set($key);
}
return app('config')->get($key, $default);
}
}
if (! function_exists('cookie')) {
/**
* Create a new cookie instance.
*
* @param string $name
* @param string $value
* @param int $minutes
* @param string $path
* @param string $domain
* @param bool $secure
* @param bool $httpOnly
* @return \Symfony\Component\HttpFoundation\Cookie
*/
function cookie($name = null, $value = null, $minutes = 0, $path = null, $domain = null, $secure = false, $httpOnly = true)
{
$cookie = app('cookie');
if (is_null($name)) {
return $cookie;
}
return $cookie->make($name, $value, $minutes, $path, $domain, $secure, $httpOnly);
}
}
if (! function_exists('csrf_token')) {
/**
* Get the CSRF token value.
*
* @return string
*
* @throws RuntimeException
*/
function csrf_token()
{
$session = app('session');
if (isset($session)) {
return $session->getToken();
}
throw new RuntimeException("Application session store not set.");
}
}
if (! function_exists('env')) {
/**
* Gets the value of an environment variable. Supports boolean, empty and null.
*
* @param string $key
* @param mixed $default
* @return mixed
*/
function env($key, $default = null)
{
$value = getenv($key);
if ($value === false) {
return value($default);
}
switch (strtolower($value)) {
case 'true':
case '(true)':
return true;
case 'false':
case '(false)':
return false;
case 'empty':
case '(empty)':
return '';
case 'null':
case '(null)':
return;
}
if (Str::startsWith($value, '"') && Str::endsWith($value, '"')) {
return substr($value, 1, -1);
}
return $value;
}
}
if (! function_exists('event')) {
/**
* Fire an event and call the listeners.
*
* @param string $event
* @param mixed $payload
* @param bool $halt
* @return array|null
*/
function event($event, $payload = array(), $halt = false)
{
return app('events')->fire($event, $payload, $halt);
}
}
if (! function_exists('info')) {
/**
* Write some information to the log.
*
* @param string $message
* @param array $context
* @return void
*/
function info($message, $context = array())
{
return app('Psr\Log\LoggerInterface')->info($message, $context);
}
}
if (! function_exists('old')) {
/**
* Retrieve an old input item.
*
* @param string $key
* @param mixed $default
* @return mixed
*/
function old($key = null, $default = null)
{
return app('request')->old($key, $default);
}
}
if (! function_exists('redirect')) {
/**
* Get an instance of the redirector.
*
* @param string|null $to
* @param int $status
* @param array $headers
* @param bool $secure
* @return \Laravel\Lumen\Http\Redirector|\Illuminate\Http\RedirectResponse
*/
function redirect($to = null, $status = 302, $headers = array(), $secure = null)
{
$redirector = new Laravel\Lumen\Http\Redirector(Container::getInstance()->make('app'));
if (is_null($to)) {
return $redirector;
}
return $redirector->to($to, $status, $headers, $secure);
}
}
if (! function_exists('response')) {
/**
* Return a new response from the application.
*
* @param string $content
* @param int $status
* @param array $headers
* @return \Symfony\Component\HttpFoundation\Response|\Laravel\Lumen\Http\ResponseFactory
*/
function response($content = '', $status = 200, array $headers = array())
{
$factory = new Laravel\Lumen\Http\ResponseFactory(Container::getInstance()->make('app'));
if (func_num_args() === 0) {
return $factory;
}
return $factory->make($content, $status, $headers);
}
}
if (! function_exists('route')) {
/**
* Generate a URL to a named route.
*
* @param string $name
* @param array $parameters
* @return string
*/
function route($name, $parameters = array())
{
return (new Laravel\Lumen\Routing\UrlGenerator(app()))
->route($name, $parameters);
}
}
if (! function_exists('session')) {
/**
* Get / set the specified session value.
*
* If an array is passed as the key, we will assume you want to set an array of values.
*
* @param array|string $key
* @param mixed $default
* @return mixed
*/
function session($key = null, $default = null)
{
if (is_null($key)) {
return Container::getInstance()->make('session');
}
if (is_array($key)) {
return Container::getInstance()->make('session')->put($key);
}
return Container::getInstance()->make('session')->get($key, $default);
}
}
if (! function_exists('storage_path')) {
/**
* Get the path to the storage folder.
*
* @param string $path
* @return string
*/
function storage_path($path = '')
{
return app()->storagePath($path);
}
}
if (! function_exists('trans')) {
/**
* Translate the given message.
*
* @param string $id
* @param array $parameters
* @param string $domain
* @param string $locale
* @return string
*/
function trans($id = null, $parameters = array(), $domain = 'messages', $locale = null)
{
if (is_null($id)) {
return app('translator');
}
return app('translator')->trans($id, $parameters, $domain, $locale);
}
}
if (! function_exists('trans_choice')) {
/**
* Translates the given message based on a count.
*
* @param string $id
* @param int $number
* @param array $parameters
* @param string $domain
* @param string $locale
* @return string
*/
function trans_choice($id, $number, array $parameters = array(), $domain = 'messages', $locale = null)
{
return app('translator')->transChoice($id, $number, $parameters, $domain, $locale);
}
}
if (! function_exists('url')) {
/**
* Generate a url for the application.
*
* @param string $path
* @param mixed $parameters
* @param bool $secure
* @return string
*/
function url($path = null, $parameters = array(), $secure = null)
{
return (new Laravel\Lumen\Routing\UrlGenerator(app()))
->to($path, $parameters, $secure);
}
}
if (! function_exists('view')) {
/**
* Get the evaluated view contents for the given view.
*
* @param string $view
* @param array $data
* @param array $mergeData
* @return \Illuminate\View\View
*/
function view($view = null, $data = array(), $mergeData = array())
{
$factory = Container::getInstance()->make('view');
if (func_num_args() === 0) {
return $factory;
}
return $factory->make($view, $data, $mergeData);
}
}
readme.md 0000666 00000003366 13436751307 0006350 0 ustar 00 ## Lumen Framework (Kernel)
[![Build Status](https://travis-ci.org/laravel/lumen-framework.svg)](https://travis-ci.org/laravel/lumen-framework)
[![Total Downloads](https://poser.pugx.org/laravel/lumen-framework/d/total.svg)](https://packagist.org/packages/laravel/lumen-framework)
[![Latest Stable Version](https://poser.pugx.org/laravel/lumen-framework/v/stable.svg)](https://packagist.org/packages/laravel/lumen-framework)
[![Latest Unstable Version](https://poser.pugx.org/laravel/lumen-framework/v/unstable.svg)](https://packagist.org/packages/laravel/lumen-framework)
[![License](https://poser.pugx.org/laravel/lumen-framework/license.svg)](https://packagist.org/packages/laravel/lumen-framework)
> **Note:** This repository contains the core code of the Laravel Lumen framework. If you want to build an application using Laravel Lumen, visit the main [Lumen repository](https://github.com/laravel/lumen).
## Lumen PHP Framework
Laravel Lumen is a stunningly fast PHP micro-framework for building web applications with expressive, elegant syntax. We believe development must be an enjoyable, creative experience to be truly fulfilling. Lumen attempts to take the pain out of development by easing common tasks used in the majority of web projects, such as routing, database abstraction, queueing, and caching.
## Official Documentation
Documentation for the framework can be found on the [Lumen website](http://lumen.laravel.com/docs).
## Security Vulnerabilities
If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell at taylor@laravel.com. All security vulnerabilities will be promptly addressed.
### License
The Lumen framework is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).
composer.json 0000666 00000004127 13436751307 0007307 0 ustar 00 {
"name": "laravel/lumen-framework",
"description": "The Laravel Lumen Framework.",
"keywords": ["framework", "laravel", "lumen"],
"license": "MIT",
"homepage": "http://laravel.com",
"support": {
"issues": "https://github.com/laravel/lumen-framework/issues",
"source": "https://github.com/laravel/lumen-framework"
},
"authors": [
{
"name": "Taylor Otwell",
"email": "taylorotwell@gmail.com"
}
],
"require": {
"php": ">=5.4.0",
"illuminate/auth": "5.0.*",
"illuminate/bus": "5.0.*",
"illuminate/config": "5.0.*",
"illuminate/container": "5.0.*",
"illuminate/contracts": "5.0.*",
"illuminate/cache": "5.0.*",
"illuminate/console": "5.0.*",
"illuminate/cookie": "5.0.*",
"illuminate/database": "5.0.*",
"illuminate/encryption": "5.0.*",
"illuminate/events": "5.0.*",
"illuminate/filesystem": "5.0.*",
"illuminate/hashing": "5.0.*",
"illuminate/http": "5.0.*",
"illuminate/pagination": "5.0.*",
"illuminate/queue": "5.0.*",
"illuminate/session": "5.0.*",
"illuminate/support": "5.0.*",
"illuminate/translation": "5.0.*",
"illuminate/validation": "5.0.*",
"illuminate/view": "5.0.*",
"monolog/monolog": "~1.0",
"mtdowling/cron-expression": "~1.0",
"nikic/fast-route": "0.4.*",
"symfony/http-kernel": "2.6.*",
"symfony/http-foundation": "2.6.*",
"symfony/security-core": "2.6.*",
"symfony/var-dumper": "2.6.*"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"mockery/mockery": "~0.9"
},
"suggest": {
"vlucas/phpdotenv": "Required to use .env files (~1.0)."
},
"autoload": {
"psr-4": {
"Laravel\\Lumen\\": "src/"
},
"classmap": [
"src/Foundation"
],
"files": [
"src/helpers.php"
]
},
"extra": {
"branch-alias": {
"dev-master": "5.0-dev"
}
}
}
phpunit.php 0000666 00000001746 13436751307 0006771 0 ustar 00 get('/', function () {
return response('Hello World');
});
$response = $app->handle(Request::create('/', 'GET'));
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('Hello World', $response->getContent());
}
public function testRequestWithoutSymfonyClass()
{
$app = new Application;
$app->get('/', function () {
return response('Hello World');
});
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/';
$response = $app->dispatch();
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('Hello World', $response->getContent());
unset($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']);
}
public function testRequestWithoutSymfonyClassTrailingSlash()
{
$app = new Application;
$app->get('/foo', function () {
return response('Hello World');
});
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/foo/';
$response = $app->dispatch();
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('Hello World', $response->getContent());
unset($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']);
}
public function testRequestWithParameters()
{
$app = new Application;
$app->get('/foo/{bar}/{baz}', function ($bar, $baz) {
return response($bar.$baz);
});
$response = $app->handle(Request::create('/foo/1/2', 'GET'));
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('12', $response->getContent());
}
public function testRequestToControllerWithParameters()
{
$app = new Application;
$app->get('/foo/{bar}', 'LumenTestController@actionWithParameter');
$response = $app->handle(Request::create('/foo/1', 'GET'));
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('1', $response->getContent());
}
public function testCallbackRouteWithDefaultParameter()
{
$app = new Application;
$app->get('/foo-bar/{baz}', function ($baz = 'default-value') {
return response($baz);
});
$response = $app->handle(Request::create('/foo-bar/something', 'GET'));
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('something', $response->getContent());
}
public function testControllerRouteWithDefaultParameter()
{
$app = new Application;
$app->get('/foo-bar/{baz}', 'LumenTestController@actionWithDefaultParameter');
$response = $app->handle(Request::create('/foo-bar/something2', 'GET'));
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('something2', $response->getContent());
}
public function testGlobalMiddleware()
{
$app = new Application;
$app->middleware(['LumenTestMiddleware']);
$app->get('/', function () {
return response('Hello World');
});
$response = $app->handle(Request::create('/', 'GET'));
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('Middleware', $response->getContent());
}
public function testRouteMiddleware()
{
$app = new Application;
$app->routeMiddleware(['foo' => 'LumenTestMiddleware']);
$app->get('/', function () {
return response('Hello World');
});
$app->get('/foo', ['middleware' => 'foo', function() {
return response('Hello World');
}]);
$response = $app->handle(Request::create('/', 'GET'));
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('Hello World', $response->getContent());
$response = $app->handle(Request::create('/foo', 'GET'));
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('Middleware', $response->getContent());
}
public function testGroupRouteMiddleware()
{
$app = new Application;
$app->routeMiddleware(['foo' => 'LumenTestMiddleware']);
$app->group(['middleware' => 'foo'], function($app) {
$app->get('/', function () {
return response('Hello World');
});
});
$app->get('/foo', function() {
return response('Hello World');
});
$response = $app->handle(Request::create('/', 'GET'));
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('Middleware', $response->getContent());
$response = $app->handle(Request::create('/foo', 'GET'));
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('Hello World', $response->getContent());
}
public function testGroupPrefixRoutes()
{
$app = new Application;
$app->group(['prefix' => 'user'], function($app) {
$app->get('/', function () {
return response('User Index');
});
$app->get('profile', function () {
return response('User Profile');
});
$app->get('/show', function () {
return response('User Show');
});
});
$response = $app->handle(Request::create('/user', 'GET'));
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('User Index', $response->getContent());
$response = $app->handle(Request::create('/user/profile', 'GET'));
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('User Profile', $response->getContent());
$response = $app->handle(Request::create('/user/show', 'GET'));
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('User Show', $response->getContent());
}
public function testNotFoundResponse()
{
$app = new Application;
$app->instance('Illuminate\Contracts\Debug\ExceptionHandler', $mock = m::mock('Laravel\Lumen\Exceptions\Handler[report]'));
$mock->shouldIgnoreMissing();
$app->get('/', function () {
return response('Hello World');
});
$response = $app->handle(Request::create('/foo', 'GET'));
$this->assertEquals(404, $response->getStatusCode());
}
public function testMethodNotAllowedResponse()
{
$app = new Application;
$app->instance('Illuminate\Contracts\Debug\ExceptionHandler', $mock = m::mock('Laravel\Lumen\Exceptions\Handler[report]'));
$mock->shouldIgnoreMissing();
$app->post('/', function () {
return response('Hello World');
});
$response = $app->handle(Request::create('/', 'GET'));
$this->assertEquals(405, $response->getStatusCode());
}
public function testControllerResponse()
{
$app = new Application;
$app->get('/', 'LumenTestController@action');
$response = $app->handle(Request::create('/', 'GET'));
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('LumenTestController', $response->getContent());
}
public function testNamespacedControllerResponse()
{
$app = new Application;
require_once __DIR__.'/fixtures/TestController.php';
$app->group(['namespace' => 'Lumen\Tests'], function($app) {
$app->get('/', 'TestController@action');
});
$response = $app->handle(Request::create('/', 'GET'));
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('Lumen\Tests\TestController', $response->getContent());
}
public function testGeneratingUrls()
{
$app = new Application;
$app->instance('request', Request::create('http://lumen.laravel.com', 'GET'));
unset($app->availableBindings['request']);
$app->get('/foo-bar', ['as' => 'foo', function() {
//
}]);
$app->get('/foo-bar/{baz}/{boom}', ['as' => 'bar', function() {
//
}]);
$this->assertEquals('http://lumen.laravel.com/something', url('something'));
$this->assertEquals('http://lumen.laravel.com/foo-bar', route('foo'));
$this->assertEquals('http://lumen.laravel.com/foo-bar/1/2', route('bar', ['baz' => 1, 'boom' => 2]));
}
public function testGeneratingUrlsForRegexParameters()
{
$app = new Application;
$app->instance('request', Request::create('http://lumen.laravel.com', 'GET'));
unset($app->availableBindings['request']);
$app->get('/foo-bar', ['as' => 'foo', function() {
//
}]);
$app->get('/foo-bar/{baz:[0-9]+}/{boom}', ['as' => 'bar', function() {
//
}]);
$app->get('/foo-bar/{baz:[0-9]+}/{boom:[0-9]+}', ['as' => 'baz', function() {
//
}]);
$this->assertEquals('http://lumen.laravel.com/something', url('something'));
$this->assertEquals('http://lumen.laravel.com/foo-bar', route('foo'));
$this->assertEquals('http://lumen.laravel.com/foo-bar/1/2', route('bar', ['baz' => 1, 'boom' => 2]));
$this->assertEquals('http://lumen.laravel.com/foo-bar/1/2', route('baz', ['baz' => 1, 'boom' => 2]));
}
public function testRegisterServiceProvider()
{
$app = new Application;
$provider = new LumenTestServiceProvider($app);
$app->register($provider);
}
public function testUsingCustomDispatcher()
{
$routes = new FastRoute\RouteCollector(new FastRoute\RouteParser\Std, new FastRoute\DataGenerator\GroupCountBased);
$routes->addRoute('GET', '/', [function () {
return response('Hello World');
}]);
$app = new Application;
$app->setDispatcher(new FastRoute\Dispatcher\GroupCountBased($routes->getData()));
$response = $app->handle(Request::create('/', 'GET'));
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('Hello World', $response->getContent());
}
}
class LumenTestService {}
class LumenTestServiceProvider extends Illuminate\Support\ServiceProvider
{
public function register() {}
}
class LumenTestMiddleware {
public function handle($request, $next) {
return response('Middleware');
}
}
class LumenTestController {
public $service;
public function __construct(LumenTestService $service) {
$this->service = $service;
}
public function action() {
return response(__CLASS__);
}
public function actionWithParameter($baz) {
return response($baz);
}
public function actionWithDefaultParameter($baz = 'default-value') {
return response($baz);
}
}
LICENSE.txt 0000666 00000002065 13436751307 0006407 0 ustar 00 The MIT License (MIT)
Copyright (c)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
.gitignore 0000666 00000000046 13436751307 0006551 0 ustar 00 /lumen.log
/vendor
composer.lock
.env
lang/en/validation.php 0000666 00000012634 13436751307 0010755 0 ustar 00 "The :attribute must be accepted.",
"active_url" => "The :attribute is not a valid URL.",
"after" => "The :attribute must be a date after :date.",
"alpha" => "The :attribute may only contain letters.",
"alpha_dash" => "The :attribute may only contain letters, numbers, and dashes.",
"alpha_num" => "The :attribute may only contain letters and numbers.",
"array" => "The :attribute must be an array.",
"before" => "The :attribute must be a date before :date.",
"between" => [
"numeric" => "The :attribute must be between :min and :max.",
"file" => "The :attribute must be between :min and :max kilobytes.",
"string" => "The :attribute must be between :min and :max characters.",
"array" => "The :attribute must have between :min and :max items.",
],
"boolean" => "The :attribute field must be true or false.",
"confirmed" => "The :attribute confirmation does not match.",
"date" => "The :attribute is not a valid date.",
"date_format" => "The :attribute does not match the format :format.",
"different" => "The :attribute and :other must be different.",
"digits" => "The :attribute must be :digits digits.",
"digits_between" => "The :attribute must be between :min and :max digits.",
"email" => "The :attribute must be a valid email address.",
"filled" => "The :attribute field is required.",
"exists" => "The selected :attribute is invalid.",
"image" => "The :attribute must be an image.",
"in" => "The selected :attribute is invalid.",
"integer" => "The :attribute must be an integer.",
"ip" => "The :attribute must be a valid IP address.",
"max" => [
"numeric" => "The :attribute may not be greater than :max.",
"file" => "The :attribute may not be greater than :max kilobytes.",
"string" => "The :attribute may not be greater than :max characters.",
"array" => "The :attribute may not have more than :max items.",
],
"mimes" => "The :attribute must be a file of type: :values.",
"min" => [
"numeric" => "The :attribute must be at least :min.",
"file" => "The :attribute must be at least :min kilobytes.",
"string" => "The :attribute must be at least :min characters.",
"array" => "The :attribute must have at least :min items.",
],
"not_in" => "The selected :attribute is invalid.",
"numeric" => "The :attribute must be a number.",
"regex" => "The :attribute format is invalid.",
"required" => "The :attribute field is required.",
"required_if" => "The :attribute field is required when :other is :value.",
"required_with" => "The :attribute field is required when :values is present.",
"required_with_all" => "The :attribute field is required when :values is present.",
"required_without" => "The :attribute field is required when :values is not present.",
"required_without_all" => "The :attribute field is required when none of :values are present.",
"same" => "The :attribute and :other must match.",
"size" => [
"numeric" => "The :attribute must be :size.",
"file" => "The :attribute must be :size kilobytes.",
"string" => "The :attribute must be :size characters.",
"array" => "The :attribute must contain :size items.",
],
"unique" => "The :attribute has already been taken.",
"url" => "The :attribute format is invalid.",
"timezone" => "The :attribute must be a valid zone.",
/*
|--------------------------------------------------------------------------
| Custom Validation Language Lines
|--------------------------------------------------------------------------
|
| Here you may specify custom validation messages for attributes using the
| convention "attribute.rule" to name the lines. This makes it quick to
| specify a specific custom language line for a given attribute rule.
|
*/
'custom' => [
'attribute-name' => [
'rule-name' => 'custom-message',
],
],
/*
|--------------------------------------------------------------------------
| Custom Validation Attributes
|--------------------------------------------------------------------------
|
| The following language lines are used to swap attribute place-holders
| with something more reader friendly such as E-Mail Address instead
| of "email". This simply helps us make messages a little cleaner.
|
*/
'attributes' => [],
];