Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSR-2 in production code #10

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 14 additions & 25 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,11 @@ protected function registerAuthBindings()
});

$this->singleton('auth.password', function () {
return $this->loadComponent('auth', 'Illuminate\Auth\Passwords\PasswordResetServiceProvider', 'auth.password');
return $this->loadComponent(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GrahamCampbell You can argue that PSR-2 does not require this…

'auth',
'Illuminate\Auth\Passwords\PasswordResetServiceProvider',
'auth.password'
);
});
}

Expand Down Expand Up @@ -445,9 +449,8 @@ protected function registerDatabaseBindings()
{
$this->singleton('db', function () {
return $this->loadComponent(
'database', [
'Illuminate\Database\DatabaseServiceProvider',
'Illuminate\Pagination\PaginationServiceProvider'],
'database',
['Illuminate\Database\DatabaseServiceProvider', 'Illuminate\Pagination\PaginationServiceProvider'],
'db'
);
});
Expand Down Expand Up @@ -487,9 +490,7 @@ protected function registerEventBindings()
protected function registerErrorBindings()
{
if (! $this->bound('Illuminate\Contracts\Debug\ExceptionHandler')) {
$this->singleton(
'Illuminate\Contracts\Debug\ExceptionHandler', 'Laravel\Lumen\Exceptions\Handler'
);
$this->singleton('Illuminate\Contracts\Debug\ExceptionHandler', 'Laravel\Lumen\Exceptions\Handler');
}
}

Expand Down Expand Up @@ -1030,9 +1031,7 @@ protected function callTerminableMiddleware($response)
$instance = $this->make($middleware);

if ($instance instanceof TerminableMiddleware) {
$instance->terminate(
$this->make('request'), $response
);
$instance->terminate($this->make('request'), $response);
}
}
}
Expand Down Expand Up @@ -1188,9 +1187,7 @@ protected function callControllerAction($routeInfo)
if ($instance instanceof Routing\Controller) {
return $this->callLumenController($instance, $method, $routeInfo);
} else {
return $this->callControllerCallable(
[$instance, $method], array_values($routeInfo[2])
);
return $this->callControllerCallable([$instance, $method], array_values($routeInfo[2]));
}
}

Expand All @@ -1204,18 +1201,12 @@ protected function callControllerAction($routeInfo)
*/
protected function callLumenController($instance, $method, $routeInfo)
{
$middleware = $instance->getMiddlewareForMethod(
$this->make('request'), $method
);
$middleware = $instance->getMiddlewareForMethod($this->make('request'), $method);

if (count($middleware) > 0) {
return $this->callLumenControllerWithMiddleware(
$instance, $method, $routeInfo, $middleware
);
return $this->callLumenControllerWithMiddleware($instance, $method, $routeInfo, $middleware);
} else {
return $this->callControllerCallable(
[$instance, $method], array_values($routeInfo[2])
);
return $this->callControllerCallable([$instance, $method], array_values($routeInfo[2]));
}
}

Expand All @@ -1233,9 +1224,7 @@ protected function callLumenControllerWithMiddleware($instance, $method, $routeI
$middleware = $this->gatherMiddlewareClassNames($middleware);

return $this->sendThroughPipeline($middleware, function () use ($instance, $method, $routeInfo) {
return $this->callControllerCallable(
[$instance, $method], array_values($routeInfo[2])
);
return $this->callControllerCallable([$instance, $method], array_values($routeInfo[2]));
});
}

Expand Down
4 changes: 1 addition & 3 deletions src/Console/Commands/RouteCacheCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ public function fire()
return $this->error("Your application doesn't have any routes.");
}

file_put_contents(
$this->laravel->getCachedRoutesPath(), $this->buildRouteCacheFile($routes)
);
file_put_contents($this->laravel->getCachedRoutesPath(), $this->buildRouteCacheFile($routes));

$this->info('Routes cached successfully!');
}
Expand Down
12 changes: 8 additions & 4 deletions src/Console/Commands/ServeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;

class ServeCommand extends Command {
class ServeCommand extends Command
{

/**
* The console command name.
Expand Down Expand Up @@ -47,10 +48,13 @@ public function fire()
protected function getOptions()
{
return array(
array('host', null, InputOption::VALUE_OPTIONAL, 'The host address to serve the application on.', 'localhost'),

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),
);
}

}
4 changes: 1 addition & 3 deletions src/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ public function __construct(Application $app)
*/
protected function defineConsoleSchedule()
{
$this->app->instance(
'Illuminate\Console\Scheduling\Schedule', $schedule = new Schedule
);
$this->app->instance('Illuminate\Console\Scheduling\Schedule', $schedule = new Schedule);

$this->schedule($schedule);
}
Expand Down
7 changes: 3 additions & 4 deletions src/Foundation/Composer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
use Illuminate\Filesystem\Filesystem;
use Symfony\Component\Process\Process;

class Composer {
class Composer
{

/**
* The filesystem instance.
Expand Down Expand Up @@ -64,8 +65,7 @@ public function dumpOptimized()
*/
protected function findComposer()
{
if ($this->files->exists($this->workingPath.'/composer.phar'))
{
if ($this->files->exists($this->workingPath.'/composer.phar')) {
return '"'.PHP_BINARY.'" composer.phar';
}

Expand Down Expand Up @@ -94,5 +94,4 @@ public function setWorkingPath($path)

return $this;
}

}
7 changes: 3 additions & 4 deletions src/Providers/CacheServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
use Illuminate\Cache\Console\ClearCommand;
use Illuminate\Cache\CacheServiceProvider as BaseProvider;

class CacheServiceProvider extends BaseProvider {
class CacheServiceProvider extends BaseProvider
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@taylorotwell @GrahamCampbell …but this clearly is a violation.

{

/**
* Register the cache related console commands.
Expand All @@ -12,12 +13,10 @@ class CacheServiceProvider extends BaseProvider {
*/
public function registerCommands()
{
$this->app->singleton('command.cache.clear', function($app)
{
$this->app->singleton('command.cache.clear', function ($app) {
return new ClearCommand($app['cache']);
});

$this->commands('command.cache.clear');
}

}
4 changes: 1 addition & 3 deletions src/Routing/UrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ public function to($path, $extra = array(), $secure = null)

$extra = $this->formatParametersForUrl($extra);

$tail = implode('/', array_map(
'rawurlencode', (array) $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
Expand Down
6 changes: 3 additions & 3 deletions src/Routing/ValidatesRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public function validate(Request $request, array $rules, array $messages = array
*/
protected function throwValidationException(Request $request, $validator)
{
throw new HttpResponseException($this->buildFailedValidationResponse(
$request, $this->formatValidationErrors($validator)
));
throw new HttpResponseException(
$this->buildFailedValidationResponse($request, $this->formatValidationErrors($validator))
);
}

/**
Expand Down
23 changes: 19 additions & 4 deletions src/Testing/ApplicationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,15 @@ public function call($method, $uri, $parameters = [], $cookies = [], $files = []
* @param string $content
* @return \Illuminate\Http\Response
*/
public function callSecure($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null)
{
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);
Expand All @@ -90,8 +97,16 @@ public function callSecure($method, $uri, $parameters = [], $cookies = [], $file
* @param string $content
* @return \Illuminate\Http\Response
*/
public function route($method, $name, $routeParameters = [], $parameters = [], $cookies = [], $files = [], $server = [], $content = null)
{
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);
Expand Down
6 changes: 5 additions & 1 deletion src/Testing/AssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ public function assertResponseStatus($code)
{
$actual = $this->response->getStatusCode();

return PHPUnit::assertEquals($code, $this->response->getStatusCode(), "Expected status code {$code}, got {$actual}.");
return PHPUnit::assertEquals(
$code,
$this->response->getStatusCode(),
"Expected status code {$code}, got {$actual}."
);
}

/**
Expand Down
11 changes: 9 additions & 2 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,15 @@ function config($key = null, $default = null)
* @param bool $httpOnly
* @return \Symfony\Component\HttpFoundation\Cookie
*/
function cookie($name = null, $value = null, $minutes = 0, $path = null, $domain = null, $secure = false, $httpOnly = true)
{
function cookie(
$name = null,
$value = null,
$minutes = 0,
$path = null,
$domain = null,
$secure = false,
$httpOnly = true
) {
$cookie = app('cookie');

if (is_null($name)) {
Expand Down