language stringclasses 1
value | owner stringlengths 2 15 | repo stringlengths 2 21 | sha stringlengths 45 45 | message stringlengths 7 36.3k | path stringlengths 1 199 | patch stringlengths 15 102k | is_multipart bool 2
classes |
|---|---|---|---|---|---|---|---|
Other | laravel | framework | 854e6b231484715df2eb325ebf7ebd1b11cd8adf.json | Create access admission and unauthorized exception | src/Illuminate/Foundation/Auth/Access/AuthorizesRequests.php | @@ -3,6 +3,7 @@
namespace Illuminate\Foundation\Auth\Access;
use Illuminate\Contracts\Auth\Access\Gate;
+use Illuminate\Auth\Access\UnauthorizedException;
use Symfony\Component\HttpKernel\Exception\HttpException;
trait AuthorizesRequests
@@ -20,9 +21,7 @@ public function authorize($ability, $arguments = [])
{
list($ability, $arguments) = $this->parseAbilityAndArguments($ability, $arguments);
- if (! app(Gate::class)->check($ability, $arguments)) {
- throw $this->createGateUnauthorizedException($ability, $arguments);
- }
+ $this->authorizeAtGate(app(Gate::class), $ability, $arguments);
}
/**
@@ -39,10 +38,29 @@ public function authorizeForUser($user, $ability, $arguments = [])
{
list($ability, $arguments) = $this->parseAbilityAndArguments($ability, $arguments);
- $result = app(Gate::class)->forUser($user)->check($ability, $arguments);
+ $gate = app(Gate::class)->forUser($user);
+
+ $this->authorizeAtGate($gate, $ability, $arguments);
+ }
- if (! $result) {
- throw $this->createGateUnauthorizedException($ability, $arguments);
+ /**
+ * Authorize the request at the given gate.
+ *
+ * @param \Illuminate\Contracts\Auth\Access\Gate $gate
+ * @param mixed $ability
+ * @param mixed|array $arguments
+ * @return void
+ *
+ * @throws \Symfony\Component\HttpKernel\Exception\HttpException
+ */
+ public function authorizeAtGate(Gate $gate, $ability, $arguments)
+ {
+ try {
+ $gate->authorize($ability, $arguments);
+ } catch (UnauthorizedException $e) {
+ throw $this->createGateUnauthorizedException(
+ $ability, $arguments, $e->getMessage()
+ );
}
}
@@ -69,8 +87,8 @@ protected function parseAbilityAndArguments($ability, $arguments)
* @param array $arguments
* @return \Symfony\Component\HttpKernel\Exception\HttpException
*/
- protected function createGateUnauthorizedException($ability, $arguments)
+ protected function createGateUnauthorizedException($ability, $arguments, $reason = 'This action is unauthorized.')
{
- return new HttpException(403, 'This action is unauthorized.');
+ return new HttpException(403, $reason);
}
} | true |
Other | laravel | framework | 854e6b231484715df2eb325ebf7ebd1b11cd8adf.json | Create access admission and unauthorized exception | src/Illuminate/Foundation/Exceptions/Handler.php | @@ -5,6 +5,7 @@
use Exception;
use Psr\Log\LoggerInterface;
use Illuminate\Http\Response;
+use Illuminate\Auth\Access\UnauthorizedException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\Console\Application as ConsoleApplication;
use Symfony\Component\Debug\ExceptionHandler as SymfonyDisplayer;
@@ -87,6 +88,10 @@ protected function shouldntReport(Exception $e)
*/
public function render($request, Exception $e)
{
+ if ($this->isUnauthorizedException($e)) {
+ $e = new HttpException(403, $e->getMessage());
+ }
+
if ($this->isHttpException($e)) {
return $this->toIlluminateResponse($this->renderHttpException($e), $e);
} else {
@@ -150,6 +155,17 @@ protected function convertExceptionToResponse(Exception $e)
return (new SymfonyDisplayer(config('app.debug')))->createResponse($e);
}
+ /**
+ * Determine if the given exception is an access unauthorized exception.
+ *
+ * @param \Exception $e
+ * @return bool
+ */
+ protected function isUnauthorizedException(Exception $e)
+ {
+ return $e instanceof UnauthorizedException;
+ }
+
/**
* Determine if the given exception is an HTTP exception.
* | true |
Other | laravel | framework | ca66631b916063c1be8a594c58035e8e432c0277.json | Add depth and collection support to Arr::flatten | src/Illuminate/Support/Arr.php | @@ -149,15 +149,26 @@ public static function last($array, callable $callback, $default = null)
* Flatten a multi-dimensional array into a single level.
*
* @param array $array
+ * @param int $depth
* @return array
*/
- public static function flatten($array)
+ public static function flatten($array, $depth = INF)
{
- $return = [];
+ return array_reduce($array, function ($result, $item) use ($depth) {
+ $item = $item instanceof Collection ? $item->all() : $item;
- array_walk_recursive($array, function ($x) use (&$return) { $return[] = $x; });
+ if (is_array($item)) {
+ if ($depth === 1) {
+ return array_merge($result, $item);
+ }
+
+ return array_merge($result, static::flatten($item, $depth - 1));
+ }
+
+ $result[] = $item;
- return $return;
+ return $result;
+ }, []);
}
/** | true |
Other | laravel | framework | ca66631b916063c1be8a594c58035e8e432c0277.json | Add depth and collection support to Arr::flatten | src/Illuminate/Support/Collection.php | @@ -204,17 +204,7 @@ public function first(callable $callback = null, $default = null)
*/
public function flatten($depth = INF)
{
- return $this->reduce(function ($return, $item) use ($depth) {
- if ($item instanceof self || is_array($item)) {
- if ($depth === 1) {
- return $return->merge($item);
- }
-
- return $return->merge((new static($item))->flatten($depth - 1));
- }
-
- return $return->push($item);
- }, new static);
+ return new static(Arr::flatten($this->items, $depth));
}
/** | true |
Other | laravel | framework | ca66631b916063c1be8a594c58035e8e432c0277.json | Add depth and collection support to Arr::flatten | src/Illuminate/Support/helpers.php | @@ -163,11 +163,12 @@ function array_last($array, $callback, $default = null)
* Flatten a multi-dimensional array into a single level.
*
* @param array $array
+ * @param int $depth
* @return array
*/
- function array_flatten($array)
+ function array_flatten($array, $depth = INF)
{
- return Arr::flatten($array);
+ return Arr::flatten($array, $depth);
}
}
| true |
Other | laravel | framework | ca66631b916063c1be8a594c58035e8e432c0277.json | Add depth and collection support to Arr::flatten | tests/Support/SupportArrTest.php | @@ -1,6 +1,7 @@
<?php
use Illuminate\Support\Arr;
+use Illuminate\Support\Collection;
class SupportArrTest extends PHPUnit_Framework_TestCase
{
@@ -50,9 +51,51 @@ public function testLast()
public function testFlatten()
{
- $array = ['name' => 'Joe', 'languages' => ['PHP', 'Ruby']];
- $array = Arr::flatten($array);
- $this->assertEquals(['Joe', 'PHP', 'Ruby'], $array);
+ // Flat arrays are unaffected
+ $array = ['#foo', '#bar', '#baz'];
+ $this->assertEquals(['#foo', '#bar', '#baz'], Arr::flatten(['#foo', '#bar', '#baz']));
+
+ // Nested arrays are flattened with existing flat items
+ $array = [['#foo', '#bar'], '#baz'];
+ $this->assertEquals(['#foo', '#bar', '#baz'], Arr::flatten($array));
+
+ // Sets of nested arrays are flattened
+ $array = [['#foo', '#bar'], ['#baz']];
+ $this->assertEquals(['#foo', '#bar', '#baz'], Arr::flatten($array));
+
+ // Deeply nested arrays are flattened
+ $array = [['#foo', ['#bar']], ['#baz']];
+ $this->assertEquals(['#foo', '#bar', '#baz'], Arr::flatten($array));
+
+ // Nested collections are flattened alongside arrays
+ $array = [new Collection(['#foo', '#bar']), ['#baz']];
+ $this->assertEquals(['#foo', '#bar', '#baz'], Arr::flatten($array));
+
+ // Nested collections containing plain arrays are flattened
+ $array = [new Collection(['#foo', ['#bar']]), ['#baz']];
+ $this->assertEquals(['#foo', '#bar', '#baz'], Arr::flatten($array));
+
+ // Nested arrays containing collections are flattened
+ $array = [['#foo', new Collection(['#bar'])], ['#baz']];
+ $this->assertEquals(['#foo', '#bar', '#baz'], Arr::flatten($array));
+
+ // Nested arrays containing collections containing arrays are flattened
+ $array = [['#foo', new Collection(['#bar', ['#zap']])], ['#baz']];
+ $this->assertEquals(['#foo', '#bar', '#zap', '#baz'], Arr::flatten($array));
+ }
+
+ public function testFlattenWithDepth()
+ {
+ // No depth flattens recursively
+ $array = [['#foo', ['#bar', ['#baz']]], '#zap'];
+ $this->assertEquals(['#foo', '#bar', '#baz', '#zap'], Arr::flatten($array));
+
+ // Specifying a depth only flattens to that depth
+ $array = [['#foo', ['#bar', ['#baz']]], '#zap'];
+ $this->assertEquals(['#foo', ['#bar', ['#baz']], '#zap'], Arr::flatten($array, 1));
+
+ $array = [['#foo', ['#bar', ['#baz']]], '#zap'];
+ $this->assertEquals(['#foo', '#bar', ['#baz'], '#zap'], Arr::flatten($array, 2));
}
public function testGet() | true |
Other | laravel | framework | 73301e3c5e8bbcdbdbd43706a13ccd644c0b8ba2.json | Add depth parameter doc block | src/Illuminate/Support/Collection.php | @@ -199,6 +199,7 @@ public function first(callable $callback = null, $default = null)
/**
* Get a flattened array of the items in the collection.
*
+ * @param int $depth
* @return static
*/
public function flatten($depth = INF) | false |
Other | laravel | framework | 605668517da68b4d58e94d966a41dc044271639c.json | Remove duplicated tests | tests/Support/SupportCollectionTest.php | @@ -221,14 +221,6 @@ public function testFlatten()
// Nested arrays containing collections containing arrays are flattened
$c = new Collection([['#foo', new Collection(['#bar', ['#zap']])], ['#baz']]);
$this->assertEquals(['#foo', '#bar', '#zap', '#baz'], $c->flatten()->all());
-
- // Can specify depth to flatten to
- $c = new Collection([['#foo', ['#bar']], '#baz']);
- $this->assertEquals(['#foo', ['#bar'], '#baz'], $c->flatten(1)->all());
-
- // Can specify depth to flatten to
- $c = new Collection([['#foo', ['#bar']], '#baz']);
- $this->assertEquals(['#foo', '#bar', '#baz'], $c->flatten(2)->all());
}
public function testFlattenWithDepth() | false |
Other | laravel | framework | 86d36fa12f19720c9e018db647812eb3d02ebaab.json | Use array as is | src/Illuminate/Support/Collection.php | @@ -206,7 +206,7 @@ public function flatten($depth = INF)
return $this->reduce(function ($return, $item) use ($depth) {
if ($item instanceof self || is_array($item)) {
if ($depth === 1) {
- return $return->merge(new static($item));
+ return $return->merge($item);
}
return $return->merge((new static($item))->flatten($depth - 1)); | false |
Other | laravel | framework | 0f4325eb7fa4b2cf5a2fd91cfb1299d64d88f09f.json | Add empty comments to empty classes | src/Illuminate/Container/BindingResolutionException.php | @@ -9,4 +9,5 @@
*/
class BindingResolutionException extends Exception
{
+ //
} | true |
Other | laravel | framework | 0f4325eb7fa4b2cf5a2fd91cfb1299d64d88f09f.json | Add empty comments to empty classes | src/Illuminate/Contracts/Bus/SelfHandling.php | @@ -4,4 +4,5 @@
interface SelfHandling
{
+ //
} | true |
Other | laravel | framework | 0f4325eb7fa4b2cf5a2fd91cfb1299d64d88f09f.json | Add empty comments to empty classes | src/Illuminate/Contracts/Container/BindingResolutionException.php | @@ -6,4 +6,5 @@
class BindingResolutionException extends BaseException
{
+ //
} | true |
Other | laravel | framework | 0f4325eb7fa4b2cf5a2fd91cfb1299d64d88f09f.json | Add empty comments to empty classes | src/Illuminate/Contracts/Encryption/DecryptException.php | @@ -6,4 +6,5 @@
class DecryptException extends RuntimeException
{
+ //
} | true |
Other | laravel | framework | 0f4325eb7fa4b2cf5a2fd91cfb1299d64d88f09f.json | Add empty comments to empty classes | src/Illuminate/Contracts/Encryption/EncryptException.php | @@ -6,4 +6,5 @@
class EncryptException extends RuntimeException
{
+ //
} | true |
Other | laravel | framework | 0f4325eb7fa4b2cf5a2fd91cfb1299d64d88f09f.json | Add empty comments to empty classes | src/Illuminate/Contracts/Filesystem/Cloud.php | @@ -4,4 +4,5 @@
interface Cloud extends Filesystem
{
+ //
} | true |
Other | laravel | framework | 0f4325eb7fa4b2cf5a2fd91cfb1299d64d88f09f.json | Add empty comments to empty classes | src/Illuminate/Contracts/Filesystem/FileNotFoundException.php | @@ -6,4 +6,5 @@
class FileNotFoundException extends Exception
{
+ //
} | true |
Other | laravel | framework | 0f4325eb7fa4b2cf5a2fd91cfb1299d64d88f09f.json | Add empty comments to empty classes | src/Illuminate/Contracts/Queue/ShouldBeQueued.php | @@ -7,4 +7,5 @@
*/
interface ShouldBeQueued extends ShouldQueue
{
+ //
} | true |
Other | laravel | framework | 0f4325eb7fa4b2cf5a2fd91cfb1299d64d88f09f.json | Add empty comments to empty classes | src/Illuminate/Contracts/Queue/ShouldQueue.php | @@ -4,4 +4,5 @@
interface ShouldQueue
{
+ //
} | true |
Other | laravel | framework | 0f4325eb7fa4b2cf5a2fd91cfb1299d64d88f09f.json | Add empty comments to empty classes | src/Illuminate/Contracts/Validation/UnauthorizedException.php | @@ -6,4 +6,5 @@
class UnauthorizedException extends RuntimeException
{
+ //
} | true |
Other | laravel | framework | 0f4325eb7fa4b2cf5a2fd91cfb1299d64d88f09f.json | Add empty comments to empty classes | src/Illuminate/Database/Eloquent/MassAssignmentException.php | @@ -6,4 +6,5 @@
class MassAssignmentException extends RuntimeException
{
+ //
} | true |
Other | laravel | framework | 0f4325eb7fa4b2cf5a2fd91cfb1299d64d88f09f.json | Add empty comments to empty classes | src/Illuminate/Http/Exception/PostTooLargeException.php | @@ -6,4 +6,5 @@
class PostTooLargeException extends Exception
{
+ //
} | true |
Other | laravel | framework | 0f4325eb7fa4b2cf5a2fd91cfb1299d64d88f09f.json | Add empty comments to empty classes | src/Illuminate/Session/TokenMismatchException.php | @@ -6,4 +6,5 @@
class TokenMismatchException extends Exception
{
+ //
} | true |
Other | laravel | framework | 1361c23a1be302e0bed34add6c07adacfe8b5aa2.json | Remove deprecated file from symfony/finder
See symfony/Finder@2c3faa7
Signed-off-by: crynobone <crynobone@gmail.com> | src/Illuminate/Foundation/Console/Optimize/config.php | @@ -194,13 +194,6 @@
$basePath.'/vendor/symfony/finder/Iterator/RecursiveDirectoryIterator.php',
$basePath.'/vendor/symfony/finder/Iterator/FileTypeFilterIterator.php',
$basePath.'/vendor/symfony/finder/Iterator/FilenameFilterIterator.php',
- $basePath.'/vendor/symfony/finder/Shell/Shell.php',
- $basePath.'/vendor/symfony/finder/Adapter/AdapterInterface.php',
- $basePath.'/vendor/symfony/finder/Adapter/AbstractAdapter.php',
- $basePath.'/vendor/symfony/finder/Adapter/AbstractFindAdapter.php',
- $basePath.'/vendor/symfony/finder/Adapter/GnuFindAdapter.php',
- $basePath.'/vendor/symfony/finder/Adapter/PhpAdapter.php',
- $basePath.'/vendor/symfony/finder/Adapter/BsdFindAdapter.php',
$basePath.'/vendor/symfony/finder/Finder.php',
$basePath.'/vendor/symfony/finder/Glob.php',
$basePath.'/vendor/vlucas/phpdotenv/src/Dotenv.php', | false |
Other | laravel | framework | 52d126abce14b9b2152b74318f7e1f0e260c5246.json | Use is_callable() in Gate::resolvePolicyCallback()
The `method_exists()` function only checks for hard coded methods on objects. However using the `is_callable()` function will consider methods added to policies using `__call()`. | src/Illuminate/Auth/Access/Gate.php | @@ -275,7 +275,7 @@ protected function resolvePolicyCallback($user, $ability, array $arguments)
}
}
- if (! method_exists($instance, $ability)) {
+ if (! is_callable([$instance, $ability])) {
return false;
}
| false |
Other | laravel | framework | 2c3d10f41bbb8e960375df51d89d5c0d95330714.json | Add getAuthIdentifierName to Authenticable trait | src/Illuminate/Auth/Authenticatable.php | @@ -4,6 +4,16 @@
trait Authenticatable
{
+ /**
+ * Get the name of the unique identifier for the user.
+ *
+ * @return string
+ */
+ public function getAuthIdentifierName()
+ {
+ return $this->getKeyName();
+ }
+
/**
* Get the unique identifier for the user.
* | true |
Other | laravel | framework | 2c3d10f41bbb8e960375df51d89d5c0d95330714.json | Add getAuthIdentifierName to Authenticable trait | src/Illuminate/Auth/EloquentUserProvider.php | @@ -59,7 +59,7 @@ public function retrieveByToken($identifier, $token)
$model = $this->createModel();
return $model->newQuery()
- ->where($model->getKeyName(), $identifier)
+ ->where($model->getAuthIdentifierName(), $identifier)
->where($model->getRememberTokenName(), $token)
->first();
} | true |
Other | laravel | framework | 2c3d10f41bbb8e960375df51d89d5c0d95330714.json | Add getAuthIdentifierName to Authenticable trait | src/Illuminate/Auth/GenericUser.php | @@ -24,14 +24,26 @@ public function __construct(array $attributes)
$this->attributes = $attributes;
}
+ /**
+ * Get the name of the unique identifier for the user.
+ *
+ * @return string
+ */
+ public function getAuthIdentifierName()
+ {
+ return 'id';
+ }
+
/**
* Get the unique identifier for the user.
*
* @return mixed
*/
public function getAuthIdentifier()
{
- return $this->attributes['id'];
+ $name = $this->getAuthIdentifierName();
+
+ return $this->attributes[$name];
}
/** | true |
Other | laravel | framework | 2c3d10f41bbb8e960375df51d89d5c0d95330714.json | Add getAuthIdentifierName to Authenticable trait | src/Illuminate/Contracts/Auth/Authenticatable.php | @@ -4,6 +4,13 @@
interface Authenticatable
{
+ /**
+ * Get the name of the unique identifier for the user.
+ *
+ * @return string
+ */
+ public function getAuthIdentifierName();
+
/**
* Get the unique identifier for the user.
* | true |
Other | laravel | framework | b590a56904f1f79fa90d2d995b8ac49f51beb2a6.json | set the date format as the mock doesnt have one | tests/Database/DatabaseEloquentModelTest.php | @@ -1148,6 +1148,7 @@ public function testTimestampsAreNotUpdatedWithTimestampsFalseSaveOption()
public function testModelAttributesAreCastedWhenPresentInCastsArray()
{
$model = new EloquentModelCastingStub;
+ $model->setDateFormat('Y-m-d H:i:s');
$model->first = '3';
$model->second = '4.0';
$model->third = 2.5; | false |
Other | laravel | framework | 867135e52d1b4245d0bce393200723183fed37cd.json | Use FQCNs for DocBlocks | src/Illuminate/Routing/Console/stubs/controller.plain.stub | @@ -3,7 +3,6 @@
namespace DummyNamespace;
use Illuminate\Http\Request;
-
use DummyRootNamespaceHttp\Requests;
use DummyRootNamespaceHttp\Controllers\Controller;
| true |
Other | laravel | framework | 867135e52d1b4245d0bce393200723183fed37cd.json | Use FQCNs for DocBlocks | src/Illuminate/Routing/Console/stubs/controller.stub | @@ -3,7 +3,6 @@
namespace DummyNamespace;
use Illuminate\Http\Request;
-
use DummyRootNamespaceHttp\Requests;
use DummyRootNamespaceHttp\Controllers\Controller;
@@ -12,7 +11,7 @@ class DummyClass extends Controller
/**
* Display a listing of the resource.
*
- * @return Response
+ * @return \Illuminate\Http\Response
*/
public function index()
{
@@ -22,7 +21,7 @@ class DummyClass extends Controller
/**
* Show the form for creating a new resource.
*
- * @return Response
+ * @return \Illuminate\Http\Response
*/
public function create()
{
@@ -32,8 +31,8 @@ class DummyClass extends Controller
/**
* Store a newly created resource in storage.
*
- * @param Request $request
- * @return Response
+ * @param \Illuminate\Http\Request $request
+ * @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
@@ -44,7 +43,7 @@ class DummyClass extends Controller
* Display the specified resource.
*
* @param int $id
- * @return Response
+ * @return \Illuminate\Http\Response
*/
public function show($id)
{
@@ -55,7 +54,7 @@ class DummyClass extends Controller
* Show the form for editing the specified resource.
*
* @param int $id
- * @return Response
+ * @return \Illuminate\Http\Response
*/
public function edit($id)
{
@@ -65,9 +64,9 @@ class DummyClass extends Controller
/**
* Update the specified resource in storage.
*
- * @param Request $request
+ * @param \Illuminate\Http\Request $request
* @param int $id
- * @return Response
+ * @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
@@ -78,7 +77,7 @@ class DummyClass extends Controller
* Remove the specified resource from storage.
*
* @param int $id
- * @return Response
+ * @return \Illuminate\Http\Response
*/
public function destroy($id)
{ | true |
Other | laravel | framework | 9a3704826187a2983911144c584f7acf83ffa06f.json | Add some common files to the compile config | src/Illuminate/Foundation/Console/Optimize/config.php | @@ -32,9 +32,11 @@
$basePath.'/vendor/laravel/framework/src/Illuminate/Contracts/View/View.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Contracts/Http/Kernel.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Contracts/Auth/Guard.php',
+ $basePath.'/vendor/laravel/framework/src/Illuminate/Contracts/Auth/Access/Gate.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Contracts/Hashing/Hasher.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Auth/Guard.php',
+ $basePath.'/vendor/laravel/framework/src/Illuminate/Auth/Access/Gate.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Contracts/Auth/UserProvider.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Auth/EloquentUserProvider.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Container/Container.php',
@@ -181,6 +183,7 @@
$basePath.'/vendor/symfony/http-foundation/ResponseHeaderBag.php',
$basePath.'/vendor/symfony/http-foundation/Cookie.php',
$basePath.'/vendor/symfony/finder/SplFileInfo.php',
+ $basePath.'/vendor/symfony/finder/Expression/Glob.php',
$basePath.'/vendor/symfony/finder/Expression/Regex.php',
$basePath.'/vendor/symfony/finder/Expression/ValueInterface.php',
$basePath.'/vendor/symfony/finder/Expression/Expression.php',
@@ -190,6 +193,7 @@
$basePath.'/vendor/symfony/finder/Iterator/ExcludeDirectoryFilterIterator.php',
$basePath.'/vendor/symfony/finder/Iterator/RecursiveDirectoryIterator.php',
$basePath.'/vendor/symfony/finder/Iterator/FileTypeFilterIterator.php',
+ $basePath.'/vendor/symfony/finder/Iterator/FilenameFilterIterator.php',
$basePath.'/vendor/symfony/finder/Shell/Shell.php',
$basePath.'/vendor/symfony/finder/Adapter/AdapterInterface.php',
$basePath.'/vendor/symfony/finder/Adapter/AbstractAdapter.php',
@@ -198,4 +202,7 @@
$basePath.'/vendor/symfony/finder/Adapter/PhpAdapter.php',
$basePath.'/vendor/symfony/finder/Adapter/BsdFindAdapter.php',
$basePath.'/vendor/symfony/finder/Finder.php',
+ $basePath.'/vendor/symfony/finder/Glob.php',
+ $basePath.'/vendor/vlucas/phpdotenv/src/Dotenv.php',
+ $basePath.'/vendor/nesbot/carbon/src/Carbon/Carbon.php',
]); | false |
Other | laravel | framework | f51a59e7e18262874a4af20634da34430100876f.json | change method order. | src/Illuminate/Queue/SyncQueue.php | @@ -90,45 +90,45 @@ protected function resolveJob($payload)
}
/**
- * Handle the failed job.
+ * Raise the after queue job event.
*
* @param \Illuminate\Contracts\Queue\Job $job
- * @return array
+ * @return void
*/
- protected function handleFailedJob(Job $job)
+ protected function raiseAfterJobEvent(Job $job)
{
- $job->failed();
+ $data = json_decode($job->getRawBody(), true);
- $this->raiseFailedJobEvent($job);
+ if ($this->container->bound('events')) {
+ $this->container['events']->fire('illuminate.queue.after', ['sync', $job, $data]);
+ }
}
/**
- * Raise the failed queue job event.
+ * Handle the failed job.
*
* @param \Illuminate\Contracts\Queue\Job $job
- * @return void
+ * @return array
*/
- protected function raiseFailedJobEvent(Job $job)
+ protected function handleFailedJob(Job $job)
{
- $data = json_decode($job->getRawBody(), true);
+ $job->failed();
- if ($this->container->bound('events')) {
- $this->container['events']->fire('illuminate.queue.failed', ['sync', $job, $data]);
- }
+ $this->raiseFailedJobEvent($job);
}
/**
- * Raise the after queue job event.
+ * Raise the failed queue job event.
*
* @param \Illuminate\Contracts\Queue\Job $job
* @return void
*/
- protected function raiseAfterJobEvent(Job $job)
+ protected function raiseFailedJobEvent(Job $job)
{
$data = json_decode($job->getRawBody(), true);
if ($this->container->bound('events')) {
- $this->container['events']->fire('illuminate.queue.after', ['sync', $job, $data]);
+ $this->container['events']->fire('illuminate.queue.failed', ['sync', $job, $data]);
}
}
} | false |
Other | laravel | framework | 82068c2bfef86119434208a01bcf1f4fc3b03e1b.json | Add Request tests. | tests/Http/HttpRequestTest.php | @@ -537,4 +537,27 @@ public function testCreateFromBase()
$this->assertEquals($request->request->all(), $body);
}
+
+ public function testHttpRequestFlashCallsSessionFlashInputWithInputData()
+ {
+ $session = m::mock('Illuminate\Session\Store');
+ $session->shouldReceive('flashInput')->once()->with(['name' => 'Taylor', 'email' => 'foo']);
+ $request = Request::create('/', 'GET', ['name' => 'Taylor', 'email' => 'foo']);
+ $request->setSession($session);
+ $request->flash();
+ }
+
+ public function testHttpRequestFlashOnlyCallsFlashWithProperParameters()
+ {
+ $request = m::mock('Illuminate\Http\Request[flash]');
+ $request->shouldReceive('flash')->once()->with('only', ['key1', 'key2']);
+ $request->flashOnly(['key1', 'key2']);
+ }
+
+ public function testHttpRequestFlashExceptCallsFlashWithProperParameters()
+ {
+ $request = m::mock('Illuminate\Http\Request[flash]');
+ $request->shouldReceive('flash')->once()->with('except', ['key1', 'key2']);
+ $request->flashExcept(['key1', 'key2']);
+ }
} | false |
Other | laravel | framework | d51029a0870e874eff69ad91a5e36dc4d4595a44.json | Add pipeline test.
Fix style | tests/Pipeline/PipelineTest.php | @@ -43,6 +43,18 @@ public function testPipelineUsageWithParameters()
unset($_SERVER['__test.pipe.parameters']);
}
+
+ public function testPipelineViaChangesTheMethodBeingCalledOnThePipes()
+ {
+ $pipelineInstance = new Pipeline(new Illuminate\Container\Container);
+ $result = $pipelineInstance->send('data')
+ ->through('PipelineTestPipeOne')
+ ->via('differentMethod')
+ ->then(function ($piped) {
+ return $piped;
+ });
+ $this->assertEquals('data', $result);
+ }
}
class PipelineTestPipeOne
@@ -53,6 +65,11 @@ public function handle($piped, $next)
return $next($piped);
}
+
+ public function differentMethod($piped, $next)
+ {
+ return $next($piped);
+ }
}
class PipelineTestParameterPipe | false |
Other | laravel | framework | 1ffca77780e279b4160283dce7d88d203c4c8581.json | Fix tiny integer docs
Fix tiny integer docs | src/Illuminate/Database/Schema/Blueprint.php | @@ -535,7 +535,7 @@ public function bigInteger($column, $autoIncrement = false, $unsigned = false)
}
/**
- * Create a new unsigned small integer (2-byte) column on the table.
+ * Create a new unsigned tiny integer (1-byte) column on the table.
*
* @param string $column
* @param bool $autoIncrement | false |
Other | laravel | framework | a0673f2ac215066c80a4945c3c6510ab6aedb57a.json | Fix Pivot When Is Force Filled
This is related to Issue
[#10243](https://github.com/laravel/framework/issues/10243).
When an instance of Pivot is created and date attributes such as
created_at and updated_at at passed it tried to convert those to a
Carbon instance using the connection’s sql grammar from the parent.
As the time the pivot is being filled, no table neither connection is
already set by the parent model, so the pivot resolves a grammar from
the default connection.
The fix consist on moving `$this->setTable($table);` and
`$this->setConnection($parent->getConnectionName());` before
`$this->forceFill($attributes);` on the Pivot’s class constructor.
I tried to change the testPropertiesAreSetCorrectly test in
DatabaseEloquentPivotTest.php to reproduce the use case, as the current
test does not test that.
But got an error from PHP Unit pointing to this method in the Model
class:
```
/**
* Get the format for database stored dates.
*
* @return string
*/
protected function getDateFormat()
{
return $this->dateFormat ?:
$this->getConnection()->getQueryGrammar()->getDateFormat();
}
```
I think this is related to the mocking instance, but my testing
knowledge is not enough to fix it.
Hope this helps!, if you need more details i am able to give you if
needed. | src/Illuminate/Database/Eloquent/Relations/Pivot.php | @@ -51,14 +51,14 @@ public function __construct(Model $parent, $attributes, $table, $exists = false)
// The pivot model is a "dynamic" model since we will set the tables dynamically
// for the instance. This allows it work for any intermediate tables for the
// many to many relationship that are defined by this developer's classes.
- $this->forceFill($attributes);
-
- $this->syncOriginal();
-
$this->setTable($table);
$this->setConnection($parent->getConnectionName());
+ $this->forceFill($attributes);
+
+ $this->syncOriginal();
+
// We store off the parent instance so we will access the timestamp column names
// for the model, since the pivot model timestamps aren't easily configurable
// from the developer's point of view. We can use the parents to get these. | true |
Other | laravel | framework | a0673f2ac215066c80a4945c3c6510ab6aedb57a.json | Fix Pivot When Is Force Filled
This is related to Issue
[#10243](https://github.com/laravel/framework/issues/10243).
When an instance of Pivot is created and date attributes such as
created_at and updated_at at passed it tried to convert those to a
Carbon instance using the connection’s sql grammar from the parent.
As the time the pivot is being filled, no table neither connection is
already set by the parent model, so the pivot resolves a grammar from
the default connection.
The fix consist on moving `$this->setTable($table);` and
`$this->setConnection($parent->getConnectionName());` before
`$this->forceFill($attributes);` on the Pivot’s class constructor.
I tried to change the testPropertiesAreSetCorrectly test in
DatabaseEloquentPivotTest.php to reproduce the use case, as the current
test does not test that.
But got an error from PHP Unit pointing to this method in the Model
class:
```
/**
* Get the format for database stored dates.
*
* @return string
*/
protected function getDateFormat()
{
return $this->dateFormat ?:
$this->getConnection()->getQueryGrammar()->getDateFormat();
}
```
I think this is related to the mocking instance, but my testing
knowledge is not enough to fix it.
Hope this helps!, if you need more details i am able to give you if
needed. | tests/Database/DatabaseEloquentPivotTest.php | @@ -14,9 +14,9 @@ public function testPropertiesAreSetCorrectly()
{
$parent = m::mock('Illuminate\Database\Eloquent\Model[getConnectionName]');
$parent->shouldReceive('getConnectionName')->once()->andReturn('connection');
- $pivot = new Pivot($parent, ['foo' => 'bar'], 'table', true);
+ $pivot = new Pivot($parent, ['foo' => 'bar', 'created_at' => '2015-09-12'], 'table', true);
- $this->assertEquals(['foo' => 'bar'], $pivot->getAttributes());
+ $this->assertEquals(['foo' => 'bar', 'created_at' => '2015-09-12'], $pivot->getAttributes());
$this->assertEquals('connection', $pivot->getConnectionName());
$this->assertEquals('table', $pivot->getTable());
$this->assertTrue($pivot->exists); | true |
Other | laravel | framework | 22126ac39c371adca21698535020bc61aa19a3ad.json | Add Container flush test.
Style fix. | tests/Container/ContainerTest.php | @@ -493,6 +493,23 @@ public function testForgetInstancesForgetsAllInstances()
$this->assertFalse($container->isShared('Instance2'));
$this->assertFalse($container->isShared('Instance3'));
}
+
+ public function testContainerFlushFlushesAllBindingsAliasesAndResolvedInstances()
+ {
+ $container = new Container;
+ $container->bind('ConcreteStub', function () { return new ContainerConcreteStub; }, true);
+ $container->alias('ConcreteStub', 'ContainerConcreteStub');
+ $concreteStubInstance = $container->make('ConcreteStub');
+ $this->assertTrue($container->resolved('ConcreteStub'));
+ $this->assertTrue($container->isAlias('ContainerConcreteStub'));
+ $this->assertArrayHasKey('ConcreteStub', $container->getBindings());
+ $this->assertTrue($container->isShared('ConcreteStub'));
+ $container->flush();
+ $this->assertFalse($container->resolved('ConcreteStub'));
+ $this->assertFalse($container->isAlias('ContainerConcreteStub'));
+ $this->assertEmpty($container->getBindings());
+ $this->assertFalse($container->isShared('ConcreteStub'));
+ }
}
class ContainerConcreteStub | false |
Other | laravel | framework | e0fef32f5167e764fdd09ff882fd947800edbeaf.json | Remove extraneous docs | src/Illuminate/Database/Query/JoinClause.php | @@ -55,10 +55,10 @@ public function __construct($type, $table)
*
* on `contacts`.`user_id` = `users`.`id` and `contacts`.`info_id` = `info`.`id`
*
- * @param string $first The first argument (column) to compare with
- * @param string $operator The comparator
- * @param string $second The second argument (column) to compare with
- * @param string $boolean The string to intercalate multiple `on` clauses with
+ * @param string $first
+ * @param string $operator
+ * @param string $second
+ * @param string $boolean
* @param bool $where
* @return $this
*/ | false |
Other | laravel | framework | 6bffe4eb623ec9235f4e290bb4a7c95dd25e4a76.json | Add Container tests.
Add testForgetInstanceForgetsInstance
testForgetInstancesForgetsAllInstances
Style fixes. | tests/Container/ContainerTest.php | @@ -54,7 +54,6 @@ public function testSharedConcreteResolution()
{
$container = new Container;
$container->singleton('ContainerConcreteStub');
- $bindings = $container->getBindings();
$var1 = $container->make('ContainerConcreteStub');
$var2 = $container->make('ContainerConcreteStub');
@@ -466,6 +465,34 @@ public function testContainerTags()
$this->assertEmpty($container->tagged('this_tag_does_not_exist'));
}
+
+ public function testForgetInstanceForgetsInstance()
+ {
+ $container = new Container;
+ $containerConcreteStub = new ContainerConcreteStub;
+ $container->instance('ContainerConcreteStub', $containerConcreteStub);
+ $this->assertTrue($container->isShared('ContainerConcreteStub'));
+ $container->forgetInstance('ContainerConcreteStub');
+ $this->assertFalse($container->isShared('ContainerConcreteStub'));
+ }
+
+ public function testForgetInstancesForgetsAllInstances()
+ {
+ $container = new Container;
+ $containerConcreteStub1 = new ContainerConcreteStub;
+ $containerConcreteStub2 = new ContainerConcreteStub;
+ $containerConcreteStub3 = new ContainerConcreteStub;
+ $container->instance('Instance1', $containerConcreteStub1);
+ $container->instance('Instance2', $containerConcreteStub2);
+ $container->instance('Instance3', $containerConcreteStub3);
+ $this->assertTrue($container->isShared('Instance1'));
+ $this->assertTrue($container->isShared('Instance2'));
+ $this->assertTrue($container->isShared('Instance3'));
+ $container->forgetInstances();
+ $this->assertFalse($container->isShared('Instance1'));
+ $this->assertFalse($container->isShared('Instance2'));
+ $this->assertFalse($container->isShared('Instance3'));
+ }
}
class ContainerConcreteStub | false |
Other | laravel | framework | b57eb65a6f499e5c32b80eccd2dd25935aba7f4d.json | Remove unused import
Based on changes 996d6c3
Signed-off-by: crynobone <crynobone@gmail.com> | src/Illuminate/Cache/CacheServiceProvider.php | @@ -4,7 +4,6 @@
use Illuminate\Support\ServiceProvider;
use Illuminate\Cache\Console\ClearCommand;
-use Illuminate\Cache\Console\CacheTableCommand;
class CacheServiceProvider extends ServiceProvider
{ | true |
Other | laravel | framework | b57eb65a6f499e5c32b80eccd2dd25935aba7f4d.json | Remove unused import
Based on changes 996d6c3
Signed-off-by: crynobone <crynobone@gmail.com> | src/Illuminate/Database/MigrationServiceProvider.php | @@ -6,12 +6,11 @@
use Illuminate\Database\Migrations\Migrator;
use Illuminate\Database\Migrations\MigrationCreator;
use Illuminate\Database\Console\Migrations\ResetCommand;
-use Illuminate\Database\Console\Migrations\RefreshCommand;
+use Illuminate\Database\Console\Migrations\StatusCommand;
use Illuminate\Database\Console\Migrations\InstallCommand;
use Illuminate\Database\Console\Migrations\MigrateCommand;
+use Illuminate\Database\Console\Migrations\RefreshCommand;
use Illuminate\Database\Console\Migrations\RollbackCommand;
-use Illuminate\Database\Console\Migrations\MigrateMakeCommand;
-use Illuminate\Database\Console\Migrations\StatusCommand;
use Illuminate\Database\Migrations\DatabaseMigrationRepository;
class MigrationServiceProvider extends ServiceProvider | true |
Other | laravel | framework | b57eb65a6f499e5c32b80eccd2dd25935aba7f4d.json | Remove unused import
Based on changes 996d6c3
Signed-off-by: crynobone <crynobone@gmail.com> | src/Illuminate/Database/SeedServiceProvider.php | @@ -4,7 +4,6 @@
use Illuminate\Support\ServiceProvider;
use Illuminate\Database\Console\Seeds\SeedCommand;
-use Illuminate\Database\Console\Seeds\SeederMakeCommand;
class SeedServiceProvider extends ServiceProvider
{ | true |
Other | laravel | framework | 996d6c3677c560d369dde4b932778022556f1d41.json | Remove dev commands from prod console. | src/Illuminate/Auth/GeneratorServiceProvider.php | @@ -1,65 +0,0 @@
-<?php
-
-namespace Illuminate\Auth;
-
-use Illuminate\Support\ServiceProvider;
-use Illuminate\Auth\Console\ClearResetsCommand;
-
-class GeneratorServiceProvider extends ServiceProvider
-{
- /**
- * Indicates if loading of the provider is deferred.
- *
- * @var bool
- */
- protected $defer = true;
-
- /**
- * The commands to be registered.
- *
- * @var array
- */
- protected $commands = [
- 'ClearResets',
- ];
-
- /**
- * Register the service provider.
- *
- * @return void
- */
- public function register()
- {
- foreach ($this->commands as $command) {
- $this->{"register{$command}Command"}();
- }
-
- $this->commands(
- 'command.auth.resets.clear'
- );
- }
-
- /**
- * Register the command.
- *
- * @return void
- */
- protected function registerClearResetsCommand()
- {
- $this->app->singleton('command.auth.resets.clear', function () {
- return new ClearResetsCommand;
- });
- }
-
- /**
- * Get the services provided by the provider.
- *
- * @return array
- */
- public function provides()
- {
- return [
- 'command.auth.resets.clear',
- ];
- }
-} | true |
Other | laravel | framework | 996d6c3677c560d369dde4b932778022556f1d41.json | Remove dev commands from prod console. | src/Illuminate/Cache/CacheServiceProvider.php | @@ -48,11 +48,7 @@ public function registerCommands()
return new ClearCommand($app['cache']);
});
- $this->app->singleton('command.cache.table', function ($app) {
- return new CacheTableCommand($app['files'], $app['composer']);
- });
-
- $this->commands('command.cache.clear', 'command.cache.table');
+ $this->commands('command.cache.clear');
}
/**
@@ -63,7 +59,7 @@ public function registerCommands()
public function provides()
{
return [
- 'cache', 'cache.store', 'memcached.connector', 'command.cache.clear', 'command.cache.table',
+ 'cache', 'cache.store', 'memcached.connector', 'command.cache.clear',
];
}
} | true |
Other | laravel | framework | 996d6c3677c560d369dde4b932778022556f1d41.json | Remove dev commands from prod console. | src/Illuminate/Database/MigrationServiceProvider.php | @@ -37,6 +37,8 @@ public function register()
// so that they may be easily accessed for registering with the consoles.
$this->registerMigrator();
+ $this->registerCreator();
+
$this->registerCommands();
}
@@ -71,14 +73,26 @@ protected function registerMigrator()
});
}
+ /**
+ * Register the migration creator.
+ *
+ * @return void
+ */
+ protected function registerCreator()
+ {
+ $this->app->singleton('migration.creator', function ($app) {
+ return new MigrationCreator($app['files']);
+ });
+ }
+
/**
* Register all of the migration commands.
*
* @return void
*/
protected function registerCommands()
{
- $commands = ['Migrate', 'Rollback', 'Reset', 'Refresh', 'Install', 'Make', 'Status'];
+ $commands = ['Migrate', 'Rollback', 'Reset', 'Refresh', 'Install', 'Status'];
// We'll simply spin through the list of commands that are migration related
// and register each one of them with an application container. They will
@@ -91,7 +105,7 @@ protected function registerCommands()
// register them with the Artisan start event so that these are available
// when the Artisan application actually starts up and is getting used.
$this->commands(
- 'command.migrate', 'command.migrate.make',
+ 'command.migrate',
'command.migrate.install', 'command.migrate.rollback',
'command.migrate.reset', 'command.migrate.refresh',
'command.migrate.status'
@@ -165,39 +179,6 @@ protected function registerInstallCommand()
});
}
- /**
- * Register the "make" migration command.
- *
- * @return void
- */
- protected function registerMakeCommand()
- {
- $this->registerCreator();
-
- $this->app->singleton('command.migrate.make', function ($app) {
- // Once we have the migration creator registered, we will create the command
- // and inject the creator. The creator is responsible for the actual file
- // creation of the migrations, and may be extended by these developers.
- $creator = $app['migration.creator'];
-
- $composer = $app['composer'];
-
- return new MigrateMakeCommand($creator, $composer);
- });
- }
-
- /**
- * Register the migration creator.
- *
- * @return void
- */
- protected function registerCreator()
- {
- $this->app->singleton('migration.creator', function ($app) {
- return new MigrationCreator($app['files']);
- });
- }
-
/**
* Get the services provided by the provider.
*
@@ -210,7 +191,6 @@ public function provides()
'command.migrate.rollback', 'command.migrate.reset',
'command.migrate.refresh', 'command.migrate.install',
'command.migrate.status', 'migration.creator',
- 'command.migrate.make',
];
}
} | true |
Other | laravel | framework | 996d6c3677c560d369dde4b932778022556f1d41.json | Remove dev commands from prod console. | src/Illuminate/Database/SeedServiceProvider.php | @@ -22,15 +22,13 @@ class SeedServiceProvider extends ServiceProvider
*/
public function register()
{
- $this->registerSeedCommand();
-
- $this->registerMakeCommand();
-
$this->app->singleton('seeder', function () {
return new Seeder;
});
- $this->commands('command.seed', 'command.seeder.make');
+ $this->registerSeedCommand();
+
+ $this->commands('command.seed');
}
/**
@@ -45,25 +43,13 @@ protected function registerSeedCommand()
});
}
- /**
- * Register the seeder generator command.
- *
- * @return void
- */
- protected function registerMakeCommand()
- {
- $this->app->singleton('command.seeder.make', function ($app) {
- return new SeederMakeCommand($app['files'], $app['composer']);
- });
- }
-
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
- return ['seeder', 'command.seed', 'command.seeder.make'];
+ return ['seeder', 'command.seed'];
}
} | true |
Other | laravel | framework | 996d6c3677c560d369dde4b932778022556f1d41.json | Remove dev commands from prod console. | src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php | @@ -3,9 +3,12 @@
namespace Illuminate\Foundation\Providers;
use Illuminate\Support\ServiceProvider;
+use Illuminate\Queue\Console\TableCommand;
use Illuminate\Foundation\Console\UpCommand;
use Illuminate\Foundation\Console\DownCommand;
use Illuminate\Foundation\Console\ServeCommand;
+use Illuminate\Cache\Console\CacheTableCommand;
+use Illuminate\Queue\Console\FailedTableCommand;
use Illuminate\Foundation\Console\TinkerCommand;
use Illuminate\Foundation\Console\JobMakeCommand;
use Illuminate\Foundation\Console\AppNameCommand;
@@ -15,9 +18,12 @@
use Illuminate\Foundation\Console\EventMakeCommand;
use Illuminate\Foundation\Console\ModelMakeCommand;
use Illuminate\Foundation\Console\ViewClearCommand;
+use Illuminate\Session\Console\SessionTableCommand;
use Illuminate\Foundation\Console\PolicyMakeCommand;
use Illuminate\Foundation\Console\RouteCacheCommand;
use Illuminate\Foundation\Console\RouteClearCommand;
+use Illuminate\Routing\Console\ControllerMakeCommand;
+use Illuminate\Routing\Console\MiddlewareMakeCommand;
use Illuminate\Foundation\Console\CommandMakeCommand;
use Illuminate\Foundation\Console\ConfigCacheCommand;
use Illuminate\Foundation\Console\ConfigClearCommand;
@@ -30,6 +36,8 @@
use Illuminate\Foundation\Console\ClearCompiledCommand;
use Illuminate\Foundation\Console\EventGenerateCommand;
use Illuminate\Foundation\Console\VendorPublishCommand;
+use Illuminate\Database\Console\Seeds\SeederMakeCommand;
+use Illuminate\Database\Console\Migrations\MigrateMakeCommand;
class ArtisanServiceProvider extends ServiceProvider
{
@@ -68,16 +76,24 @@ class ArtisanServiceProvider extends ServiceProvider
*/
protected $devCommands = [
'AppName' => 'command.app.name',
+ 'CacheTable' => 'command.cache.table',
'CommandMake' => 'command.command.make',
'ConsoleMake' => 'command.console.make',
+ 'ControllerMake' => 'command.controller.make',
'EventGenerate' => 'command.event.generate',
'EventMake' => 'command.event.make',
'JobMake' => 'command.job.make',
'ListenerMake' => 'command.listener.make',
+ 'MiddlewareMake' => 'command.middleware.make',
+ 'MigrationMake' => 'command.migration.make',
'ModelMake' => 'command.model.make',
'PolicyMake' => 'command.policy.make',
'ProviderMake' => 'command.provider.make',
+ 'QueueFailedTable' => 'command.queue.failed-table',
+ 'QueueTable' => 'command.queue.table',
'RequestMake' => 'command.request.make',
+ 'SeederMake' => 'command.seeder.make',
+ 'SessionTable' => 'command.session.table',
'Serve' => 'command.serve',
'TestMake' => 'command.test.make',
'VendorPublish' => 'command.vendor.publish',
@@ -126,6 +142,18 @@ protected function registerAppNameCommand()
});
}
+ /**
+ * Register the command.
+ *
+ * @return void
+ */
+ protected function registerCacheTableCommand()
+ {
+ $this->app->singleton('command.cache.table', function ($app) {
+ return new CacheTableCommand($app['files'], $app['composer']);
+ });
+ }
+
/**
* Register the command.
*
@@ -186,6 +214,18 @@ protected function registerConsoleMakeCommand()
});
}
+ /**
+ * Register the command.
+ *
+ * @return void
+ */
+ protected function registerControllerMakeCommand()
+ {
+ $this->app->singleton('command.controller.make', function ($app) {
+ return new ControllerMakeCommand($app['files']);
+ });
+ }
+
/**
* Register the command.
*
@@ -270,6 +310,37 @@ protected function registerListenerMakeCommand()
});
}
+ /**
+ * Register the command.
+ *
+ * @return void
+ */
+ protected function registerMiddlewareMakeCommand()
+ {
+ $this->app->singleton('command.middleware.make', function ($app) {
+ return new MiddlewareMakeCommand($app['files']);
+ });
+ }
+
+ /**
+ * Register the command.
+ *
+ * @return void
+ */
+ protected function registerMigrationMakeCommand()
+ {
+ $this->app->singleton('command.migration.make', function ($app) {
+ // Once we have the migration creator registered, we will create the command
+ // and inject the creator. The creator is responsible for the actual file
+ // creation of the migrations, and may be extended by these developers.
+ $creator = $app['migration.creator'];
+
+ $composer = $app['composer'];
+
+ return new MigrateMakeCommand($creator, $composer);
+ });
+ }
+
/**
* Register the command.
*
@@ -306,6 +377,30 @@ protected function registerProviderMakeCommand()
});
}
+ /**
+ * Register the command.
+ *
+ * @return void
+ */
+ protected function registerQueueFailedTableCommand()
+ {
+ $this->app->singleton('command.queue.failed-table', function ($app) {
+ return new FailedTableCommand($app['files'], $app['composer']);
+ });
+ }
+
+ /**
+ * Register the command.
+ *
+ * @return void
+ */
+ protected function registerQueueTableCommand()
+ {
+ $this->app->singleton('command.queue.table', function ($app) {
+ return new TableCommand($app['files'], $app['composer']);
+ });
+ }
+
/**
* Register the command.
*
@@ -318,6 +413,30 @@ protected function registerRequestMakeCommand()
});
}
+ /**
+ * Register the command.
+ *
+ * @return void
+ */
+ protected function registerSeederMakeCommand()
+ {
+ $this->app->singleton('command.seeder.make', function ($app) {
+ return new SeederMakeCommand($app['files'], $app['composer']);
+ });
+ }
+
+ /**
+ * Register the command.
+ *
+ * @return void
+ */
+ protected function registerSessionTableCommand()
+ {
+ $this->app->singleton('command.session.table', function ($app) {
+ return new SessionTableCommand($app['files'], $app['composer']);
+ });
+ }
+
/**
* Register the command.
*
@@ -445,6 +564,10 @@ protected function registerPolicyMakeCommand()
*/
public function provides()
{
- return array_values($this->commands);
+ if ($this->app->environment('production')) {
+ return array_values($this->commands);
+ } else {
+ return array_merge(array_values($this->commands), array_values($this->devCommands));
+ }
}
} | true |
Other | laravel | framework | 996d6c3677c560d369dde4b932778022556f1d41.json | Remove dev commands from prod console. | src/Illuminate/Foundation/Providers/ConsoleSupportServiceProvider.php | @@ -19,13 +19,10 @@ class ConsoleSupportServiceProvider extends AggregateServiceProvider
* @var array
*/
protected $providers = [
- 'Illuminate\Auth\GeneratorServiceProvider',
'Illuminate\Console\ScheduleServiceProvider',
'Illuminate\Database\MigrationServiceProvider',
'Illuminate\Database\SeedServiceProvider',
'Illuminate\Foundation\Providers\ComposerServiceProvider',
'Illuminate\Queue\ConsoleServiceProvider',
- 'Illuminate\Routing\GeneratorServiceProvider',
- 'Illuminate\Session\CommandsServiceProvider',
];
} | true |
Other | laravel | framework | 996d6c3677c560d369dde4b932778022556f1d41.json | Remove dev commands from prod console. | src/Illuminate/Queue/ConsoleServiceProvider.php | @@ -3,11 +3,9 @@
namespace Illuminate\Queue;
use Illuminate\Support\ServiceProvider;
-use Illuminate\Queue\Console\TableCommand;
use Illuminate\Queue\Console\RetryCommand;
use Illuminate\Queue\Console\ListFailedCommand;
use Illuminate\Queue\Console\FlushFailedCommand;
-use Illuminate\Queue\Console\FailedTableCommand;
use Illuminate\Queue\Console\ForgetFailedCommand;
class ConsoleServiceProvider extends ServiceProvider
@@ -26,10 +24,6 @@ class ConsoleServiceProvider extends ServiceProvider
*/
public function register()
{
- $this->app->singleton('command.queue.table', function ($app) {
- return new TableCommand($app['files'], $app['composer']);
- });
-
$this->app->singleton('command.queue.failed', function () {
return new ListFailedCommand;
});
@@ -46,13 +40,9 @@ public function register()
return new FlushFailedCommand;
});
- $this->app->singleton('command.queue.failed-table', function ($app) {
- return new FailedTableCommand($app['files'], $app['composer']);
- });
-
$this->commands(
- 'command.queue.table', 'command.queue.failed', 'command.queue.retry',
- 'command.queue.forget', 'command.queue.flush', 'command.queue.failed-table'
+ 'command.queue.failed', 'command.queue.retry',
+ 'command.queue.forget', 'command.queue.flush'
);
}
@@ -64,8 +54,8 @@ public function register()
public function provides()
{
return [
- 'command.queue.table', 'command.queue.failed', 'command.queue.retry',
- 'command.queue.forget', 'command.queue.flush', 'command.queue.failed-table',
+ 'command.queue.failed', 'command.queue.retry',
+ 'command.queue.forget', 'command.queue.flush',
];
}
} | true |
Other | laravel | framework | 996d6c3677c560d369dde4b932778022556f1d41.json | Remove dev commands from prod console. | src/Illuminate/Routing/GeneratorServiceProvider.php | @@ -1,67 +0,0 @@
-<?php
-
-namespace Illuminate\Routing;
-
-use Illuminate\Support\ServiceProvider;
-use Illuminate\Routing\Console\MiddlewareMakeCommand;
-use Illuminate\Routing\Console\ControllerMakeCommand;
-
-class GeneratorServiceProvider extends ServiceProvider
-{
- /**
- * Indicates if loading of the provider is deferred.
- *
- * @var bool
- */
- protected $defer = true;
-
- /**
- * Register the service provider.
- *
- * @return void
- */
- public function register()
- {
- $this->registerControllerGenerator();
-
- $this->registerMiddlewareGenerator();
-
- $this->commands('command.controller.make', 'command.middleware.make');
- }
-
- /**
- * Register the controller generator command.
- *
- * @return void
- */
- protected function registerControllerGenerator()
- {
- $this->app->singleton('command.controller.make', function ($app) {
- return new ControllerMakeCommand($app['files']);
- });
- }
-
- /**
- * Register the middleware generator command.
- *
- * @return void
- */
- protected function registerMiddlewareGenerator()
- {
- $this->app->singleton('command.middleware.make', function ($app) {
- return new MiddlewareMakeCommand($app['files']);
- });
- }
-
- /**
- * Get the services provided by the provider.
- *
- * @return array
- */
- public function provides()
- {
- return [
- 'command.controller.make', 'command.middleware.make',
- ];
- }
-} | true |
Other | laravel | framework | 996d6c3677c560d369dde4b932778022556f1d41.json | Remove dev commands from prod console. | src/Illuminate/Session/CommandsServiceProvider.php | @@ -1,40 +0,0 @@
-<?php
-
-namespace Illuminate\Session;
-
-use Illuminate\Support\ServiceProvider;
-use Illuminate\Session\Console\SessionTableCommand;
-
-class CommandsServiceProvider extends ServiceProvider
-{
- /**
- * Indicates if loading of the provider is deferred.
- *
- * @var bool
- */
- protected $defer = true;
-
- /**
- * Register the service provider.
- *
- * @return void
- */
- public function register()
- {
- $this->app->singleton('command.session.database', function ($app) {
- return new SessionTableCommand($app['files'], $app['composer']);
- });
-
- $this->commands('command.session.database');
- }
-
- /**
- * Get the services provided by the provider.
- *
- * @return array
- */
- public function provides()
- {
- return ['command.session.database'];
- }
-} | true |
Other | laravel | framework | 66102c18d2cdb1fad4a37b311c4fc1e722535a34.json | Add testBeforeBootstrappingAddsClosure test. | tests/Foundation/FoundationApplicationTest.php | @@ -132,6 +132,16 @@ public function testMethodAfterLoadingEnvironmentAddsClosure()
$this->assertArrayHasKey(0, $app['events']->getListeners('bootstrapped: Illuminate\Foundation\Bootstrap\DetectEnvironment'));
$this->assertSame($closure, $app['events']->getListeners('bootstrapped: Illuminate\Foundation\Bootstrap\DetectEnvironment')[0]);
}
+
+ public function testBeforeBootstrappingAddsClosure()
+ {
+ $app = new Application;
+ $closure = function () {};
+ $app->beforeBootstrapping('Illuminate\Foundation\Bootstrap\RegisterFacades', $closure);
+ $this->assertArrayHasKey(0, $app['events']->getListeners('bootstrapping: Illuminate\Foundation\Bootstrap\RegisterFacades'));
+ $this->assertSame($closure, $app['events']->getListeners('bootstrapping: Illuminate\Foundation\Bootstrap\RegisterFacades')[0]);
+ }
+
}
class ApplicationDeferredSharedServiceProviderStub extends Illuminate\Support\ServiceProvider | false |
Other | laravel | framework | a75a9cdadac503b7c2d6e03ccd5d67b38d25d6fc.json | Fix bug with assigning middleware. | src/Illuminate/Routing/Route.php | @@ -271,7 +271,9 @@ public function middleware($middleware = null)
$middleware = [$middleware];
}
- $this->action['middleware'] = array_merge($this->action['middleware'], $middleware);
+ $this->action['middleware'] = array_merge(
+ array_get($this->action['middleware'], []), $middleware
+ );
return $this;
} | false |
Other | laravel | framework | 1c095f839d3b983784b360a4899a743a0a472243.json | Add some fluent methods to routes | src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php | @@ -28,6 +28,12 @@ public function boot(Router $router)
$this->loadCachedRoutes();
} else {
$this->loadRoutes();
+
+ // We still want name look-ups to be fast, even if names were specified fluently
+ // on the route itself. This will update the name look-up table just in case.
+ $this->app->booted(function () use ($router) {
+ $router->getRoutes()->refreshNameLookup();
+ });
}
}
| true |
Other | laravel | framework | 1c095f839d3b983784b360a4899a743a0a472243.json | Add some fluent methods to routes | src/Illuminate/Routing/Route.php | @@ -256,13 +256,25 @@ protected function extractOptionalParameters()
}
/**
- * Get the middlewares attached to the route.
+ * Set or get the middlewares attached to the route.
+ *
+ * @param array|string|null $middleware
*
* @return array
*/
- public function middleware()
+ public function middleware($middleware = null)
{
- return (array) Arr::get($this->action, 'middleware', []);
+ if (is_null($middleware)) {
+ return (array) Arr::get($this->action, 'middleware', []);
+ }
+
+ if (is_string($middleware)) {
+ $middleware = [$middleware];
+ }
+
+ $this->action['middleware'] = array_merge($this->action['middleware'], $middleware);
+
+ return $this;
}
/**
@@ -905,6 +917,20 @@ public function getName()
return isset($this->action['as']) ? $this->action['as'] : null;
}
+ /**
+ * Add or change the route name.
+ *
+ * @param $name
+ *
+ * @return $this
+ */
+ public function name($name)
+ {
+ $this->action['as'] = $name;
+
+ return $this;
+ }
+
/**
* Get the action name for the route.
* | true |
Other | laravel | framework | 1c095f839d3b983784b360a4899a743a0a472243.json | Add some fluent methods to routes | src/Illuminate/Routing/RouteCollection.php | @@ -98,6 +98,22 @@ protected function addLookups($route)
}
}
+ /**
+ * Refresh the name look-up table, in case any names have been defined fluently.
+ *
+ * @return void
+ */
+ public function refreshNameLookup()
+ {
+ $this->nameList = [];
+
+ foreach ($this->allRoutes as $route) {
+ if ($route->getName()) {
+ $this->nameList[$route->getName()] = $route;
+ }
+ }
+ }
+
/**
* Add a route to the controller action dictionary.
* | true |
Other | laravel | framework | d110568342f42a92b9bdd045f074756cf18f0ba3.json | Use assertArrayHasKey instead of isset. | tests/Foundation/FoundationApplicationTest.php | @@ -129,7 +129,7 @@ public function testMethodAfterLoadingEnvironmentAddsClosure()
$app = new Application;
$closure = function () {};
$app->afterLoadingEnvironment($closure);
- $this->assertTrue(isset($app['events']->getListeners('bootstrapped: Illuminate\Foundation\Bootstrap\DetectEnvironment')[0]));
+ $this->assertArrayHasKey(0, $app['events']->getListeners('bootstrapped: Illuminate\Foundation\Bootstrap\DetectEnvironment'));
$this->assertSame($closure, $app['events']->getListeners('bootstrapped: Illuminate\Foundation\Bootstrap\DetectEnvironment')[0]);
}
} | false |
Other | laravel | framework | daa6894a628f596f79edf861ef4f11ba69ef2be4.json | Add afterLoadingEnvironment() test. | tests/Foundation/FoundationApplicationTest.php | @@ -123,6 +123,17 @@ public function testEnvironment()
$this->assertFalse($app->environment('qux', 'bar'));
$this->assertFalse($app->environment(['qux', 'bar']));
}
+
+ public function testMethodAfterLoadingEnvironmentAddsClosure()
+ {
+ $app = new Application;
+ $closure = function(){};
+ $app->afterLoadingEnvironment($closure);
+ $eventName = 'bootstrapped: '
+ .'Illuminate\Foundation\Bootstrap\DetectEnvironment';
+ $this->assertTrue(isset($app['events']->getListeners($eventName)[0]));
+ $this->assertSame($closure, $app['events']->getListeners($eventName)[0]);
+ }
}
class ApplicationDeferredSharedServiceProviderStub extends Illuminate\Support\ServiceProvider | false |
Other | laravel | framework | 6d33dca4bd09829bb0de4b6e3e3f6f067c5579ba.json | Fix return value for getRelatedIds | src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php | @@ -528,7 +528,7 @@ public function touch()
/**
* Get all of the IDs for the related models.
*
- * @return array
+ * @return Illuminate\Support\Collection
*/
public function getRelatedIds()
{ | false |
Other | laravel | framework | cf2a9386b31b28019f744c66ba995ee6ae149aff.json | Use table name as default for morph map | src/Illuminate/Database/Eloquent/Relations/Relation.php | @@ -3,6 +3,7 @@
namespace Illuminate\Database\Eloquent\Relations;
use Closure;
+use Illuminate\Support\Arr;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Query\Expression;
@@ -288,13 +289,34 @@ public function wrap($value)
*/
public static function morphMap(array $map = null, $merge = true)
{
+ $map = static::buildMorphMapFromModels($map);
+
if (is_array($map)) {
static::$morphMap = $merge ? array_merge(static::$morphMap, $map) : $map;
}
return static::$morphMap;
}
+ /**
+ * Builds a table-keyed array from model class names.
+ *
+ * @param string[]|null $models
+ * @return array|null
+ */
+ protected static function buildMorphMapFromModels(array $models = null)
+ {
+ if (is_null($models) || Arr::isAssoc($models)) {
+ return $models;
+ }
+
+ $tables = array_map(function ($model) {
+ return (new $model)->getTable();
+ }, $models);
+
+ return array_combine($tables, $models);
+ }
+
/**
* Handle dynamic method calls to the relationship.
* | true |
Other | laravel | framework | cf2a9386b31b28019f744c66ba995ee6ae149aff.json | Use table name as default for morph map | tests/Database/DatabaseEloquentRelationTest.php | @@ -5,6 +5,7 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\HasOne;
+use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Database\Query\Builder as QueryBuilder;
class DatabaseEloquentRelationTest extends PHPUnit_Framework_TestCase
@@ -41,6 +42,17 @@ public function testTouchMethodUpdatesRelatedTimestamps()
$relation->touch();
}
+ public function testSettingMorphMapWithNumericArrayUsesTheTableNames()
+ {
+ Relation::morphMap([EloquentRelationResetModelStub::class]);
+
+ $this->assertEquals([
+ 'reset' => 'EloquentRelationResetModelStub',
+ ], Relation::morphMap());
+
+ Relation::morphMap([], false);
+ }
+
/**
* Testing to ensure loop does not occur during relational queries in global scopes.
*
@@ -71,7 +83,9 @@ public function testDonNotRunParentModelGlobalScopes()
class EloquentRelationResetModelStub extends Model
{
- //Override method call which would normally go through __call()
+ protected $table = 'reset';
+
+ // Override method call which would normally go through __call()
public function getQuery()
{ | true |
Other | laravel | framework | a51d068a3a3f1acc547a9802f247917bd4a11bd4.json | Reset morph map after each test | tests/Database/DatabaseEloquentMorphTest.php | @@ -10,6 +10,8 @@ class DatabaseEloquentMorphTest extends PHPUnit_Framework_TestCase
{
public function tearDown()
{
+ Relation::morphMap([], false);
+
m::close();
}
| false |
Other | laravel | framework | 9faca8e8e126222371314686729c05129d431420.json | Add trailing period in `seeLink` & `dontSeeLink`
See PR #10164. | src/Illuminate/Foundation/Testing/CrawlerTrait.php | @@ -300,13 +300,13 @@ protected function dontSee($text)
*/
public function seeLink($text, $url = null)
{
- $message = "No links were found with expected text [{$text}].";
+ $message = "No links were found with expected text [{$text}]";
if ($url) {
$message .= " and URL [{$url}]";
}
- $this->assertTrue($this->hasLink($text, $url), $message);
+ $this->assertTrue($this->hasLink($text, $url), "{$message}.");
return $this;
}
@@ -326,7 +326,7 @@ public function dontSeeLink($text, $url = null)
$message .= " and URL [{$url}]";
}
- $this->assertFalse($this->hasLink($text, $url), $message);
+ $this->assertFalse($this->hasLink($text, $url), "{$message}.");
return $this;
} | false |
Other | laravel | framework | 7154df4686249e83da85c3239fcea7a604518f91.json | Move ability check into the backtrace method | src/Illuminate/Foundation/Auth/Access/AuthorizesRequests.php | @@ -10,17 +10,15 @@ trait AuthorizesRequests
/**
* Authorize a given action against a set of arguments.
*
- * @param string $ability
+ * @param mixed $ability
* @param mixed|array $arguments
* @return void
*
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
*/
public function authorize($ability, $arguments = [])
{
- if (! is_string($ability)) {
- list($arguments, $ability) = [$ability, $this->guessAbilityName()];
- }
+ list($ability, $arguments) = $this->parseAbilityAndArguments($ability, $arguments);
if (! app(Gate::class)->check($ability, $arguments)) {
throw $this->createGateUnauthorizedException($ability, $arguments);
@@ -31,17 +29,15 @@ public function authorize($ability, $arguments = [])
* Authorize a given action for a user.
*
* @param \Illuminate\Contracts\Auth\Authenticatable|mixed $user
- * @param string $ability
- * @param array $arguments
+ * @param mixed $ability
+ * @param mixed|array $arguments
* @return void
*
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
*/
public function authorizeForUser($user, $ability, $arguments = [])
{
- if (! is_string($ability)) {
- list($arguments, $ability) = [$ability, $this->guessAbilityName()];
- }
+ list($ability, $arguments) = $this->parseAbilityAndArguments($ability, $arguments);
$result = app(Gate::class)->forUser($user)->check($ability, $arguments);
@@ -51,13 +47,19 @@ public function authorizeForUser($user, $ability, $arguments = [])
}
/**
- * Guesses the ability's name from the original method name.
+ * Guesses the ability's name if it wasn't provided.
*
- * @return string
+ * @param mixed $ability
+ * @param mixed|array $arguments
+ * @return array
*/
- protected function guessAbilityName()
+ protected function parseAbilityAndArguments($ability, $arguments)
{
- return debug_backtrace(false, 3)[2]['function'];
+ if (is_string($ability)) {
+ return [$ability, $arguments];
+ }
+
+ return [debug_backtrace(false, 3)[2]['function'], $ability];
}
/** | false |
Other | laravel | framework | ca6e89710a9a4d8956268cc9477162f46865976a.json | Fix code explanation
Since we are in the `rememberForever()` method, it is incorrect to say that data will be stored for a given amount of minutes. | src/Illuminate/Cache/TaggedCache.php | @@ -199,7 +199,7 @@ public function rememberForever($key, Closure $callback)
{
// If the item exists in the cache we will just return this immediately
// otherwise we will execute the given Closure and cache the result
- // of that execution for the given number of minutes. It's easy.
+ // of that execution for an indefinite amount of time. It's easy.
if (! is_null($value = $this->get($key))) {
return $value;
} | false |
Other | laravel | framework | 9c41aa0d53412e3008285e89ff9764fa51b42469.json | Add @cannot Blade directive | src/Illuminate/View/Compilers/BladeCompiler.php | @@ -550,6 +550,17 @@ protected function compileCan($expression)
return "<?php if (Gate::check{$expression}): ?>";
}
+ /**
+ * Compile the cannot statements into valid PHP.
+ *
+ * @param string $expression
+ * @return string
+ */
+ protected function compileCannot($expression)
+ {
+ return "<?php if (Gate::denies{$expression}): ?>";
+ }
+
/**
* Compile the if statements into valid PHP.
*
@@ -640,6 +651,17 @@ protected function compileEndcan($expression)
return '<?php endif; ?>';
}
+ /**
+ * Compile the end-cannot statements into valid PHP.
+ *
+ * @param string $expression
+ * @return string
+ */
+ protected function compileEndcannot($expression)
+ {
+ return '<?php endif; ?>';
+ }
+
/**
* Compile the end-if statements into valid PHP.
* | true |
Other | laravel | framework | 9c41aa0d53412e3008285e89ff9764fa51b42469.json | Add @cannot Blade directive | tests/View/ViewBladeCompilerTest.php | @@ -233,6 +233,18 @@ public function testCanStatementsAreCompiled()
$this->assertEquals($expected, $compiler->compileString($string));
}
+ public function testCannotStatementsAreCompiled()
+ {
+ $compiler = new BladeCompiler($this->getFiles(), __DIR__);
+ $string = '@cannot (\'update\', [$post])
+breeze
+@endcannot';
+ $expected = '<?php if (Gate::denies(\'update\', [$post])): ?>
+breeze
+<?php endif; ?>';
+ $this->assertEquals($expected, $compiler->compileString($string));
+ }
+
public function testElseStatementsAreCompiled()
{
$compiler = new BladeCompiler($this->getFiles(), __DIR__); | true |
Other | laravel | framework | d3f083a892e753bf4bd68e6dd1d30ffcb0fcbadd.json | Guess ability name for authorizeForUser | src/Illuminate/Foundation/Auth/Access/AuthorizesRequests.php | @@ -19,9 +19,7 @@ trait AuthorizesRequests
public function authorize($ability, $arguments = [])
{
if (func_num_args() === 1) {
- $arguments = $ability;
-
- $ability = debug_backtrace(false, 2)[1]['function'];
+ list($arguments, $ability) = [$ability, $this->guessAbilityName()];
}
if (! app(Gate::class)->check($ability, $arguments)) {
@@ -41,13 +39,27 @@ public function authorize($ability, $arguments = [])
*/
public function authorizeForUser($user, $abiility, $arguments = [])
{
+ if (func_num_args() === 2) {
+ list($arguments, $ability) = [$ability, $this->guessAbilityName()];
+ }
+
$result = app(Gate::class)->forUser($user)->check($ability, $arguments);
if (! $result) {
throw $this->createGateUnauthorizedException($ability, $arguments);
}
}
+ /**
+ * Guesses the ability's name from the original method name.
+ *
+ * @return string
+ */
+ protected function guessAbilityName()
+ {
+ return debug_backtrace(false, 3)[2]['function'];
+ }
+
/**
* Throw an unauthorized exception based on gate results.
* | false |
Other | laravel | framework | cbe2a6acc94c96a39003b1509fdfe5b1546b5217.json | remove scrutinizer file | .scrutinizer.yml | @@ -1,55 +0,0 @@
-filter:
- excluded_paths: [tests/*]
-
-checks:
- php:
- code_rating: true
- duplication: true
- variable_existence: true
- useless_calls: true
- use_statement_alias_conflict: true
- unused_variables: true
- unused_properties: true
- unused_parameters: true
- unused_methods: true
- unreachable_code: true
- sql_injection_vulnerabilities: true
- security_vulnerabilities: true
- precedence_mistakes: true
- precedence_in_conditions: true
- parameter_non_unique: true
- no_property_on_interface: true
- no_non_implemented_abstract_methods: true
- deprecated_code_usage: true
- closure_use_not_conflicting: true
- closure_use_modifiable: true
- avoid_useless_overridden_methods: true
- avoid_conflicting_incrementers: true
- assignment_of_null_return: true
- avoid_usage_of_logical_operators: true
- ensure_lower_case_builtin_functions: true
- foreach_traversable: true
- function_in_camel_caps: true
- instanceof_class_exists: true
- lowercase_basic_constants: true
- lowercase_php_keywords: true
- missing_arguments: true
- no_commented_out_code: true
- no_duplicate_arguments: true
- no_else_if_statements: true
- no_space_between_concatenation_operator: true
- no_space_inside_cast_operator: true
- no_trailing_whitespace: true
- no_underscore_prefix_in_properties: true
- no_unnecessary_if: true
- no_unnecessary_function_call_in_for_loop: true
- non_commented_empty_catch_block: true
- php5_style_constructor: true
- parameters_in_camelcaps: true
- prefer_while_loop_over_for_loop: true
- properties_in_camelcaps: true
- require_scope_for_methods: true
- require_scope_for_properties: true
- spacing_around_conditional_operators: true
- spacing_around_non_conditional_operators: true
- spacing_of_function_arguments: true | false |
Other | laravel | framework | 30c032849e083e01cd8042091ddded72bf7cf8d4.json | Add missing throws in docblock | src/Illuminate/Foundation/helpers.php | @@ -712,6 +712,8 @@ function event($event, $payload = [], $halt = false)
*
* @param string $file
* @return string
+ *
+ * @throws \InvalidArgumentException
*/
function elixir($file)
{ | false |
Other | laravel | framework | f25833f216ca208550b00cf19ae5806cbe419822.json | extract method for readability | src/Illuminate/Auth/Access/Gate.php | @@ -156,8 +156,8 @@ public function check($ability, $arguments = [])
$arguments = [$arguments];
}
- if (isset($arguments[0]) && isset($this->policies[$argumentClass = get_class($arguments[0])])) {
- $callback = [$this->resolvePolicy($this->policies[$argumentClass]), $ability];
+ if ($this->firstArgumentCorrespondsToPolicy($arguments)) {
+ $callback = [$this->resolvePolicy($this->policies[get_class($arguments[0])]), $ability];
} elseif (isset($this->abilities[$ability])) {
$callback = $this->abilities[$ability];
} else {
@@ -169,6 +169,18 @@ public function check($ability, $arguments = [])
return call_user_func_array($callback, $arguments);
}
+ /**
+ * Determine if the first argument in the array corresponds to a policy.
+ *
+ * @param array $arguments
+ * @return bool
+ */
+ protected function firstArgumentCorrespondsToPolicy(array $arguments)
+ {
+ return isset($arguments[0]) && is_object($arguments[0]) &&
+ isset($this->policies[get_class($arguments[0])]);
+ }
+
/**
* Get a policy instance for a given class.
* | false |
Other | laravel | framework | 8327416018d07568b39aeddc8a594eb7f430090b.json | Use user resolver. | src/Illuminate/Auth/Access/Gate.php | @@ -16,11 +16,11 @@ class Gate implements GateContract
protected $container;
/**
- * The user instance.
+ * The user resolver callable.
*
- * @var \Illuminate\Contracts\Auth\Authenticatable
+ * @var callable
*/
- protected $user;
+ protected $userResolver;
/**
* All of the defined abilities.
@@ -40,17 +40,17 @@ class Gate implements GateContract
* Create a new gate instance.
*
* @param \Illuminate\Contracts\Container\Container $container
- * @param \Illuminate\Contracts\Auth\Authenticatable|mixed $user
+ * @param callable $userResolver
* @param array $abilities
* @param array $policies
* @return void
*/
- public function __construct(Container $container, $user, array $abilities = [], array $policies = [])
+ public function __construct(Container $container, callable $userResolver, array $abilities = [], array $policies = [])
{
- $this->user = $user;
$this->policies = $policies;
$this->container = $container;
$this->abilities = $abilities;
+ $this->userResolver = $userResolver;
}
/**
@@ -146,7 +146,9 @@ public function denies($ability, $arguments = [])
*/
public function check($ability, $arguments = [])
{
- if (! $this->user) {
+ $user = $this->resolveUser();
+
+ if (! $user) {
return false;
}
@@ -162,7 +164,7 @@ public function check($ability, $arguments = [])
return false;
}
- array_unshift($arguments, $this->user);
+ array_unshift($arguments, $user);
return call_user_func_array($callback, $arguments);
}
@@ -207,7 +209,17 @@ public function resolvePolicy($class)
public function forUser($user)
{
return new static(
- $this->container, $user, $this->abilities, $this->policies
+ $this->container, function () use ($user) { return $user; }, $this->abilities, $this->policies
);
}
+
+ /**
+ * Resolve the user from the user resolver.
+ *
+ * @return mixed
+ */
+ protected function resolveUser()
+ {
+ return call_user_func($this->userResolver);
+ }
} | true |
Other | laravel | framework | 8327416018d07568b39aeddc8a594eb7f430090b.json | Use user resolver. | src/Illuminate/Auth/AuthServiceProvider.php | @@ -65,7 +65,7 @@ protected function registerUserResolver()
protected function registerAccessGate()
{
$this->app->singleton(GateContract::class, function ($app) {
- return new Gate($app, $app['auth']->user());
+ return new Gate($app, function () use ($app) { return $app['auth']->user(); });
});
}
| true |
Other | laravel | framework | 8327416018d07568b39aeddc8a594eb7f430090b.json | Use user resolver. | tests/Auth/AuthAccessGateTest.php | @@ -83,7 +83,7 @@ public function test_for_user_method_attaches_a_new_user_to_a_new_gate_instance(
protected function getBasicGate()
{
- return new Gate(new Container, (object) ['id' => 1]);
+ return new Gate(new Container, function () { return (object) ['id' => 1]; });
}
}
| true |
Other | laravel | framework | b1c79a9a8478b8950d1d23ffbea7eaba3dfc1d2e.json | Add an authorizable contract. | src/Illuminate/Contracts/Auth/Access/Authorizable.php | @@ -0,0 +1,15 @@
+<?php
+
+namespace Illuminate\Contracts\Auth\Access;
+
+interface Authorizable
+{
+ /**
+ * Determine if the entity has a given ability.
+ *
+ * @param string $ability
+ * @param array|mixed $arguments
+ * @return bool
+ */
+ public function can($ability, $arguments = []);
+} | false |
Other | laravel | framework | 49dd3461d5ce49de98d570a128f11a8ac5c1974a.json | Ignore .editorconfig and .php_cs | .gitattributes | @@ -2,8 +2,10 @@
/build export-ignore
/tests export-ignore
+.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
+.php_cs export-ignore
.scrutinizer.yml export-ignore
.travis.yml export-ignore
phpunit.php export-ignore | false |
Other | laravel | framework | b5f48a89525550a6ece15c52af0e4758c0cc90a8.json | Clarify documentation of Collection diff method
The documentation was previously not clear about whether diff computes
the symmetric or asymmetric difference. | src/Illuminate/Support/Collection.php | @@ -86,7 +86,7 @@ public function contains($key, $value = null)
}
/**
- * Diff the collection with the given items.
+ * Get the items in the collection that are not present in the given items.
*
* @param mixed $items
* @return static | false |
Other | laravel | framework | 4684c8a48705c78aed2ad3c891429569d2e381a0.json | Ignore .editorconfig and .php_cs | .gitattributes | @@ -2,8 +2,10 @@
/build export-ignore
/tests export-ignore
+.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
+.php_cs export-ignore
.scrutinizer.yml export-ignore
.travis.yml export-ignore
phpunit.php export-ignore | false |
Other | laravel | framework | e569dc47a72fd2b4d322c5a96b2ca334ac18c89f.json | adjust comment spacing | src/Illuminate/Database/Schema/Grammars/Grammar.php | @@ -327,7 +327,7 @@ protected function getTableWithColumnChanges(Blueprint $blueprint, Table $table)
$column = $this->getDoctrineColumnForChange($table, $fluent);
// Here we will spin through each fluent column definition and map it to the proper
- // Doctrine column definitions, which is necessary because Laravel and Doctrine
+ // Doctrine column definitions - which is necessary because Laravel and Doctrine
// use some different terminology for various column attributes on the tables.
foreach ($fluent->getAttributes() as $key => $value) {
if (! is_null($option = $this->mapFluentOptionToDoctrine($key))) { | false |
Other | laravel | framework | e38782302566cbe42262e15411f00f0e9769017e.json | Fix double word in comments | src/Illuminate/Container/Container.php | @@ -185,8 +185,8 @@ public function bind($abstract, $concrete = null, $shared = false)
}
// If the factory is not a Closure, it means it is just a class name which is
- // is bound into this container to the abstract type and we will just wrap
- // it up inside a Closure to make things more convenient when extending.
+ // bound into this container to the abstract type and we will just wrap it
+ // up inside its own Closure to give us more convenience when extending.
if (! $concrete instanceof Closure) {
$concrete = $this->getClosure($abstract, $concrete);
} | false |
Other | laravel | framework | 9611a25144f5bb23a72b75e7029fb0d1dd64a116.json | Fix tests for collection reverse | tests/Support/SupportCollectionTest.php | @@ -345,12 +345,12 @@ public function testReverse()
$data = new Collection(['zaeed', 'alan']);
$reversed = $data->reverse();
- $this->assertEquals(['alan', 'zaeed'], array_values($reversed->all()));
+ $this->assertSame([1 => 'alan', 0 => 'zaeed'], $reversed->all());
- $data = new Collection(['zaeed', 'alan']);
- $reversed = $data->reverse(true);
+ $data = new Collection(['name' => 'taylor', 'framework' => 'laravel']);
+ $reversed = $data->reverse();
- $this->assertEquals([1 => 'alan', 0 => 'zaeed'], $reversed->all());
+ $this->assertSame(['framework' => 'laravel', 'name' => 'taylor'], $reversed->all());
}
public function testFlip() | false |
Other | laravel | framework | 85a96a40833289b6419661b3df46466304f4436e.json | Fix PHP cs | src/Illuminate/Database/Eloquent/Builder.php | @@ -3,9 +3,9 @@
namespace Illuminate\Database\Eloquent;
use Closure;
-use InvalidArgumentException;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
+use InvalidArgumentException;
use Illuminate\Pagination\Paginator;
use Illuminate\Database\Query\Expression;
use Illuminate\Pagination\LengthAwarePaginator;
@@ -267,7 +267,7 @@ public function lists($column, $key = null)
* @param int|null $page
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
*
- * @throws InvalidArgumentException
+ * @throws \InvalidArgumentException
*/
public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
{ | false |
Other | laravel | framework | 812bbd7525166b2fecbb10f66b7eaaae7e4ea378.json | Add dontSeeJson() to CrawlerTrait | src/Illuminate/Foundation/Testing/CrawlerTrait.php | @@ -511,9 +511,10 @@ public function seeJsonEquals(array $data)
* Assert that the response contains JSON.
*
* @param array|null $data
+ * @param bool $negate
* @return $this
*/
- public function seeJson(array $data = null)
+ public function seeJson(array $data = null, $negate = false)
{
if (is_null($data)) {
$this->assertJson(
@@ -523,27 +524,41 @@ public function seeJson(array $data = null)
return $this;
}
- return $this->seeJsonContains($data);
+ return $this->seeJsonContains($data, $negate);
+ }
+
+ /**
+ * Assert that the response doesn't contain JSON.
+ *
+ * @param array|null $data
+ * @return $this
+ */
+ public function dontSeeJson(array $data = null)
+ {
+ return $this->seeJson($data, true);
}
/**
* Assert that the response contains the given JSON.
*
* @param array $data
+ * @param bool $negate
* @return $this
*/
- protected function seeJsonContains(array $data)
+ protected function seeJsonContains(array $data, $negate = false)
{
+ $method = $negate ? 'assertFalse' : 'assertTrue';
+
$actual = json_encode(array_sort_recursive(
json_decode($this->response->getContent(), true)
));
foreach (array_sort_recursive($data) as $key => $value) {
$expected = $this->formatToExpectedJson($key, $value);
- $this->assertTrue(
+ $this->{$method}(
Str::contains($actual, $expected),
- "Unable to find JSON fragment [{$expected}] within [{$actual}]."
+ ($negate ? 'Found' : 'Unable to find')." JSON fragment [{$expected}] within [{$actual}]."
);
}
| false |
Other | laravel | framework | 5836395757e7e5f595be072876920e6ad8449b3a.json | Fix PHP cs | src/Illuminate/Database/Eloquent/Builder.php | @@ -298,8 +298,6 @@ public function paginate($perPage = null, $columns = ['*'], $pageName = 'page',
*/
public function simplePaginate($perPage = null, $columns = ['*'], $pageName = 'page')
{
-
-
$page = Paginator::resolveCurrentPage($pageName);
$perPage = $perPage ?: $this->model->getPerPage(); | false |
Other | laravel | framework | 94e55961871d1f0be8869efecb55e5089de26dc0.json | Fix PHP cs | src/Illuminate/Database/Eloquent/Builder.php | @@ -271,7 +271,7 @@ public function lists($column, $key = null)
*/
public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
{
- if( $perPage <= 0) {
+ if ($perPage <= 0) {
throw new InvalidArgumentException("Negative values can't be used to query results");
}
| false |
Other | laravel | framework | 2c76a733715b8754d8752658f743032947cf746c.json | Fix negative validation for pagination | src/Illuminate/Database/Eloquent/Builder.php | @@ -3,6 +3,7 @@
namespace Illuminate\Database\Eloquent;
use Closure;
+use InvalidArgumentException;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Pagination\Paginator;
@@ -265,9 +266,15 @@ public function lists($column, $key = null)
* @param string $pageName
* @param int|null $page
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
+ *
+ * @throws InvalidArgumentException
*/
public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
{
+ if( $perPage <= 0) {
+ throw new InvalidArgumentException("Negative values can't be used to query results");
+ }
+
$total = $this->query->getCountForPagination();
$this->query->forPage(
@@ -291,6 +298,8 @@ public function paginate($perPage = null, $columns = ['*'], $pageName = 'page',
*/
public function simplePaginate($perPage = null, $columns = ['*'], $pageName = 'page')
{
+
+
$page = Paginator::resolveCurrentPage($pageName);
$perPage = $perPage ?: $this->model->getPerPage(); | false |
Other | laravel | framework | b0ad3f667b1b9bfbab4a8d6903488acf0194f042.json | Fix json validator | src/Illuminate/Validation/Validator.php | @@ -837,7 +837,8 @@ protected function validateString($attribute, $value)
*/
protected function validateJson($attribute, $value)
{
- return ! is_null(json_decode($value));
+ json_decode($value);
+ return json_last_error() === JSON_ERROR_NONE;
}
/** | false |
Other | laravel | framework | 3919621558e1635db4327c4b54cafa4f9cba9c82.json | revert some unnecessary changes | src/Illuminate/Database/Query/Builder.php | @@ -189,7 +189,7 @@ class Builder
'&', '|', '^', '<<', '>>',
'rlike', 'regexp', 'not regexp',
'~', '~*', '!~', '!~*', 'similar to',
- 'not similar to',
+ 'not similar to',
];
/**
@@ -1400,14 +1400,13 @@ protected function runSelect()
*/
public function paginate($perPage = 15, $columns = ['*'], $pageName = 'page', $page = null)
{
+ $page = $page ?: Paginator::resolveCurrentPage($pageName);
+
$total = $this->getCountForPagination($columns);
- $this->forPage(
- $page = $page ?: Paginator::resolveCurrentPage($pageName),
- $perPage
- );
+ $results = $this->forPage($page, $perPage)->get($columns);
- return new LengthAwarePaginator($this->get($columns), $total, $perPage, $page, [
+ return new LengthAwarePaginator($results, $total, $perPage, $page, [
'path' => Paginator::resolveCurrentPath(),
'pageName' => $pageName,
]); | false |
Other | laravel | framework | fb665f526ceb4bb1e21166911e8924ad2be99c57.json | Add id() method to Guard interface | src/Illuminate/Contracts/Auth/Guard.php | @@ -25,6 +25,13 @@ public function guest();
*/
public function user();
+ /**
+ * Get the ID for the currently authenticated user.
+ *
+ * @return int|null
+ */
+ public function id();
+
/**
* Log a user into the application without sessions or cookies.
* | false |
Other | laravel | framework | 53c6e48ed030f9c8a4d79579b9f411e937967581.json | add page argument on paginate | src/Illuminate/Database/Query/Builder.php | @@ -173,7 +173,7 @@ class Builder
/**
* The binding backups currently in use.
- *
+ *
* @var array
*/
protected $bindingBackups = [];
@@ -1395,17 +1395,19 @@ protected function runSelect()
* @param int $perPage
* @param array $columns
* @param string $pageName
+ * @param int|null $page
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
*/
- public function paginate($perPage = 15, $columns = ['*'], $pageName = 'page')
+ public function paginate($perPage = 15, $columns = ['*'], $pageName = 'page', $page = null)
{
- $page = Paginator::resolveCurrentPage($pageName);
-
$total = $this->getCountForPagination($columns);
- $results = $this->forPage($page, $perPage)->get($columns);
+ $this->forPage(
+ $page = $page ?: Paginator::resolveCurrentPage($pageName),
+ $perPage
+ );
- return new LengthAwarePaginator($results, $total, $perPage, $page, [
+ return new LengthAwarePaginator($this->get($columns), $total, $perPage, $page, [
'path' => Paginator::resolveCurrentPath(),
'pageName' => $pageName,
]); | false |
Other | laravel | framework | 8ea72714480e03c0288f80ac0bed5265381222ba.json | Prevent repeated calls
Remove unnecessary repeated call to formatToExpectedJson(). | src/Illuminate/Foundation/Testing/CrawlerTrait.php | @@ -415,7 +415,7 @@ protected function seeJsonContains(array $data)
$expected = $this->formatToExpectedJson($key, $value);
$this->assertTrue(
- Str::contains($actual, $this->formatToExpectedJson($key, $value)),
+ Str::contains($actual, $expected),
"Unable to find JSON fragment [{$expected}] within [{$actual}]."
);
} | false |
Other | laravel | framework | 0dd091ed8f8c2416628bf245d0bc6e81232a9a07.json | Provide hook into job creation for SQS. | src/Illuminate/Queue/SqsQueue.php | @@ -22,6 +22,13 @@ class SqsQueue extends Queue implements QueueContract
*/
protected $default;
+ /**
+ * The job creator callback.
+ *
+ * @var callable|null
+ */
+ protected $jobCreator;
+
/**
* Create a new Amazon SQS queue instance.
*
@@ -100,10 +107,27 @@ public function pop($queue = null)
);
if (count($response['Messages']) > 0) {
- return new SqsJob($this->container, $this->sqs, $queue, $response['Messages'][0]);
+ if ($this->jobCreator) {
+ return call_user_func($this->jobCreator, $this->container, $this->sqs, $queue, $response);
+ } else {
+ return new SqsJob($this->container, $this->sqs, $queue, $response['Messages'][0]);
+ }
}
}
+ /**
+ * Define the job creator callback for the connection.
+ *
+ * @param callable $callback
+ * @return $this
+ */
+ public function createJobsUsing(callable $callback)
+ {
+ $this->jobCreator = $callback;
+
+ return $this;
+ }
+
/**
* Get the queue or return the default.
* | true |
Other | laravel | framework | 0dd091ed8f8c2416628bf245d0bc6e81232a9a07.json | Provide hook into job creation for SQS. | tests/Queue/QueueSqsQueueTest.php | @@ -54,6 +54,17 @@ public function testPopProperlyPopsJobOffOfSqs()
$this->assertInstanceOf('Illuminate\Queue\Jobs\SqsJob', $result);
}
+ public function testPopProperlyPopsJobOffOfSqsWithCustomJobCreator()
+ {
+ $queue = $this->getMock('Illuminate\Queue\SqsQueue', ['getQueue'], [$this->sqs, $this->queueName, $this->account]);
+ $queue->createJobsUsing(function () { return 'job!'; });
+ $queue->setContainer(m::mock('Illuminate\Container\Container'));
+ $queue->expects($this->once())->method('getQueue')->with($this->queueName)->will($this->returnValue($this->queueUrl));
+ $this->sqs->shouldReceive('receiveMessage')->once()->with(['QueueUrl' => $this->queueUrl, 'AttributeNames' => ['ApproximateReceiveCount']])->andReturn($this->mockedReceiveMessageResponseModel);
+ $result = $queue->pop($this->queueName);
+ $this->assertEquals('job!', $result);
+ }
+
public function testDelayedPushWithDateTimeProperlyPushesJobOntoSqs()
{
$now = Carbon\Carbon::now(); | true |
Other | laravel | framework | 9032d1aa4583c6de258f54aa7b67f05897b45bf3.json | Add more methods to collection | src/Illuminate/Support/Collection.php | @@ -113,6 +113,37 @@ public function each(callable $callback)
return $this;
}
+ /**
+ * Create a new collection consisting of even elements.
+ *
+ * @return static
+ */
+ public function even()
+ {
+ return $this->every(2);
+ }
+
+ /**
+ * Create a new collection consisting of every n-th element.
+ *
+ * @param int $step
+ * @param int $offset
+ * @return static
+ */
+ public function every($step, $offset = 0)
+ {
+ $new = [];
+ $position = 0;
+ foreach ($this->items as $key => $item) {
+ if ($position % $step === $offset) {
+ $new[] = $item;
+ }
+ $position++;
+ }
+
+ return new static($new);
+ }
+
/**
* Fetch a nested element of the collection.
*
@@ -446,6 +477,16 @@ public function min($key = null)
});
}
+ /**
+ * Create a new collection consisting of odd elements.
+ *
+ * @return static
+ */
+ public function odd()
+ {
+ return $this->every(2, 1);
+ }
+
/**
* "Paginate" the collection by slicing it into a smaller collection.
* | true |
Other | laravel | framework | 9032d1aa4583c6de258f54aa7b67f05897b45bf3.json | Add more methods to collection | tests/Support/SupportCollectionTest.php | @@ -369,6 +369,37 @@ public function testChunk()
$this->assertEquals([10], $data[3]->toArray());
}
+ public function testEven()
+ {
+ $data = new Collection(['a', 'b', 'c', 'd', 'e', 'f']);
+
+ $this->assertEquals(['a', 'c', 'e'], $data->even()->all());
+ }
+
+ public function testOdd()
+ {
+ $data = new Collection(['a', 'b', 'c', 'd', 'e', 'f']);
+
+ $this->assertEquals(['b', 'd', 'f'], $data->odd()->all());
+ }
+
+ public function testEvery()
+ {
+ $data = new Collection([
+ 6 => 'a',
+ 4 => 'b',
+ 7 => 'c',
+ 1 => 'd',
+ 5 => 'e',
+ 3 => 'f',
+ ]);
+
+ $this->assertEquals(['a', 'e'], $data->every(4)->all());
+ $this->assertEquals(['b', 'f'], $data->every(4, 1)->all());
+ $this->assertEquals(['c'], $data->every(4, 2)->all());
+ $this->assertEquals(['d'], $data->every(4, 3)->all());
+ }
+
public function testPluckWithArrayAndObjectValues()
{
$data = new Collection([(object) ['name' => 'taylor', 'email' => 'foo'], ['name' => 'dayle', 'email' => 'bar']]); | true |
Other | laravel | framework | 3b65a33206f426612d68eba7fb0e501833a1651d.json | Preserve keys in collection reverse | src/Illuminate/Support/Collection.php | @@ -564,11 +564,12 @@ public function reject($callback)
/**
* Reverse items order.
*
+ * @param bool $preserveKeys
* @return static
*/
- public function reverse()
+ public function reverse($preserveKeys = false)
{
- return new static(array_reverse($this->items));
+ return new static(array_reverse($this->items, $preserveKeys));
}
/** | true |
Other | laravel | framework | 3b65a33206f426612d68eba7fb0e501833a1651d.json | Preserve keys in collection reverse | tests/Support/SupportCollectionTest.php | @@ -346,6 +346,11 @@ public function testReverse()
$reversed = $data->reverse();
$this->assertEquals(['alan', 'zaeed'], array_values($reversed->all()));
+
+ $data = new Collection(['zaeed', 'alan']);
+ $reversed = $data->reverse(true);
+
+ $this->assertEquals([1 => 'alan', 0 => 'zaeed'], $reversed->all());
}
public function testFlip() | true |
Other | laravel | framework | ef359c9845e1850af7d3b58779c8b84ba4d3dff9.json | Add getters and setters to EloquentUserProvider | src/Illuminate/Auth/EloquentUserProvider.php | @@ -125,4 +125,50 @@ public function createModel()
return new $class;
}
+
+ /**
+ * Gets the hasher implementation.
+ *
+ * @return \Illuminate\Contracts\Hashing\Hasher
+ */
+ public function getHasher()
+ {
+ return $this->hasher;
+ }
+
+ /**
+ * Sets the hasher implementation.
+ *
+ * @param \Illuminate\Contracts\Hashing\Hasher $hasher
+ * @return $this
+ */
+ public function setHasher(HasherContract $hasher)
+ {
+ $this->hasher = $hasher;
+
+ return $this;
+ }
+
+ /**
+ * Gets the name of the Eloquent user model.
+ *
+ * @return string
+ */
+ public function getModel()
+ {
+ return $this->model;
+ }
+
+ /**
+ * Sets the name of the Eloquent user model.
+ *
+ * @param string $model
+ * @return $this
+ */
+ public function setModel($model)
+ {
+ $this->model = $model;
+
+ return $this;
+ }
} | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.