When I read the Laravel 5.3's source code, I find the following codes
public function withGlobalScope($identifier, $scope)
{
$this->scopes[$identifier] = $scope;
if (method_exists($scope, 'extend')) {
$scope->extend($this);
}
return $this;
}
But the creation of GlobalScope is as followed
public static function addGlobalScope($scope, Closure $implementation = null)
{
if (is_string($scope) && ! is_null($implementation)) {
return static::$globalScopes[static::class][$scope] = $implementation;
}
if ($scope instanceof Closure) {
return static::$globalScopes[static::class][spl_object_hash($scope)] = $scope;
}
if ($scope instanceof Scope) {
return static::$globalScopes[static::class][get_class($scope)] = $scope;
}
throw new InvalidArgumentException('Global scope must be an instance of Closure or Scope.');
}
I am confused about why it is the following codes in the method withGlobalScope
if (method_exists($scope, 'extend')) {
$scope->extend($this);
}
Thanks!
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2lcuFgh
via IFTTT
Aucun commentaire:
Enregistrer un commentaire