update v 1.0.7.5

This commit is contained in:
Sujit Prasad
2016-06-13 20:41:55 +05:30
parent aa9786d829
commit 283d97e3ea
5078 changed files with 339851 additions and 175995 deletions

View File

@@ -1,73 +1,74 @@
<?php namespace Illuminate\Pipeline;
<?php
namespace Illuminate\Pipeline;
use Closure;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Pipeline\Hub as HubContract;
class Hub implements HubContract {
class Hub implements HubContract
{
/**
* The container implementation.
*
* @var \Illuminate\Contracts\Container\Container
*/
protected $container;
/**
* The container implementation.
*
* @var \Illuminate\Contracts\Container\Container
*/
protected $container;
/**
* All of the available pipelines.
*
* @var array
*/
protected $pipelines = [];
/**
* All of the available pipelines.
*
* @var array
*/
protected $pipelines = [];
/**
* Create a new Hub instance.
*
* @param \Illuminate\Contracts\Container\Container $container
* @return void
*/
public function __construct(Container $container)
{
$this->container = $container;
}
/**
* Create a new Depot instance.
*
* @param \Illuminate\Contracts\Container\Container $container
* @return void
*/
public function __construct(Container $container)
{
$this->container = $container;
}
/**
* Define the default named pipeline.
*
* @param \Closure $callback
* @return void
*/
public function defaults(Closure $callback)
{
return $this->pipeline('default', $callback);
}
/**
* Define the default named pipeline.
*
* @param \Closure $callback
* @return void
*/
public function defaults(Closure $callback)
{
return $this->pipeline('default', $callback);
}
/**
* Define a new named pipeline.
*
* @param string $name
* @param \Closure $callback
* @return void
*/
public function pipeline($name, Closure $callback)
{
$this->pipelines[$name] = $callback;
}
/**
* Define a new named pipeline.
*
* @param string $name
* @param \Closure $callback
* @return void
*/
public function pipeline($name, Closure $callback)
{
$this->pipelines[$name] = $callback;
}
/**
* Send an object through one of the available pipelines.
*
* @param mixed $object
* @param string|null $pipeline
* @return mixed
*/
public function pipe($object, $pipeline = null)
{
$pipeline = $pipeline ?: 'default';
return call_user_func(
$this->pipelines[$pipeline], new Pipeline($this->container), $object
);
}
/**
* Send an object through one of the available pipelines.
*
* @param mixed $object
* @param string|null $pipeline
* @return mixed
*/
public function pipe($object, $pipeline = null)
{
$pipeline = $pipeline ?: 'default';
return call_user_func(
$this->pipelines[$pipeline], new Pipeline($this->container), $object
);
}
}

View File

@@ -1,145 +1,170 @@
<?php namespace Illuminate\Pipeline;
<?php
namespace Illuminate\Pipeline;
use Closure;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Pipeline\Pipeline as PipelineContract;
class Pipeline implements PipelineContract {
class Pipeline implements PipelineContract
{
/**
* The container implementation.
*
* @var \Illuminate\Contracts\Container\Container
*/
protected $container;
/**
* The container implementation.
*
* @var \Illuminate\Contracts\Container\Container
*/
protected $container;
/**
* The object being passed through the pipeline.
*
* @var mixed
*/
protected $passable;
/**
* The object being passed through the pipeline.
*
* @var mixed
*/
protected $passable;
/**
* The array of class pipes.
*
* @var array
*/
protected $pipes = [];
/**
* The array of class pipes.
*
* @var array
*/
protected $pipes = array();
/**
* The method to call on each pipe.
*
* @var string
*/
protected $method = 'handle';
/**
* The method to call on each pipe.
*
* @var string
*/
protected $method = 'handle';
/**
* Create a new class instance.
*
* @param \Illuminate\Contracts\Container\Container $container
* @return void
*/
public function __construct(Container $container)
{
$this->container = $container;
}
/**
* Create a new class instance.
*
* @param \Illuminate\Contracts\Container\Container $container
* @return void
*/
public function __construct(Container $container)
{
$this->container = $container;
}
/**
* Set the object being sent through the pipeline.
*
* @param mixed $passable
* @return $this
*/
public function send($passable)
{
$this->passable = $passable;
/**
* Set the object being sent through the pipeline.
*
* @param mixed $passable
* @return $this
*/
public function send($passable)
{
$this->passable = $passable;
return $this;
}
return $this;
}
/**
* Set the array of pipes.
*
* @param array|mixed $pipes
* @return $this
*/
public function through($pipes)
{
$this->pipes = is_array($pipes) ? $pipes : func_get_args();
/**
* Set the array of pipes.
*
* @param dynamic|array $pipes
* @return $this
*/
public function through($pipes)
{
$this->pipes = is_array($pipes) ? $pipes : func_get_args();
return $this;
}
return $this;
}
/**
* Set the method to call on the pipes.
*
* @param string $method
* @return $this
*/
public function via($method)
{
$this->method = $method;
/**
* Set the method to call on the pipes.
*
* @param string $method
* @return $this
*/
public function via($method)
{
$this->method = $method;
return $this;
}
return $this;
}
/**
* Run the pipeline with a final destination callback.
*
* @param \Closure $destination
* @return mixed
*/
public function then(Closure $destination)
{
$firstSlice = $this->getInitialSlice($destination);
/**
* Run the pipeline with a final destination callback.
*
* @param \Closure $destination
* @return mixed
*/
public function then(Closure $destination)
{
$firstSlice = $this->getInitialSlice($destination);
$pipes = array_reverse($this->pipes);
$pipes = array_reverse($this->pipes);
return call_user_func(
array_reduce($pipes, $this->getSlice(), $firstSlice), $this->passable
);
}
return call_user_func(
array_reduce($pipes, $this->getSlice(), $firstSlice), $this->passable
);
}
/**
* Get a Closure that represents a slice of the application onion.
*
* @return \Closure
*/
protected function getSlice()
{
return function ($stack, $pipe) {
return function ($passable) use ($stack, $pipe) {
if ($pipe instanceof Closure) {
// If the pipe is an instance of a Closure, we will just call it directly but
// otherwise we'll resolve the pipes out of the container and call it with
// the appropriate method and arguments, returning the results back out.
return call_user_func($pipe, $passable, $stack);
} elseif (! is_object($pipe)) {
list($name, $parameters) = $this->parsePipeString($pipe);
/**
* Get a Closure that represents a slice of the application onion.
*
* @return \Closure
*/
protected function getSlice()
{
return function($stack, $pipe)
{
return function($passable) use ($stack, $pipe)
{
// If the pipe is an instance of a Closure, we will just call it directly but
// otherwise we'll resolve the pipes out of the container and call it with
// the appropriate method and arguments, returning the results back out.
if ($pipe instanceof Closure)
{
return call_user_func($pipe, $passable, $stack);
}
else
{
return $this->container->make($pipe)
->{$this->method}($passable, $stack);
}
};
};
}
// If the pipe is a string we will parse the string and resolve the class out
// of the dependency injection container. We can then build a callable and
// execute the pipe function giving in the parameters that are required.
$pipe = $this->container->make($name);
/**
* Get the initial slice to begin the stack call.
*
* @param \Closure $destination
* @return \Closure
*/
protected function getInitialSlice(Closure $destination)
{
return function($passable) use ($destination)
{
return call_user_func($destination, $passable);
};
}
$parameters = array_merge([$passable, $stack], $parameters);
} else {
// If the pipe is already an object we'll just make a callable and pass it to
// the pipe as-is. There is no need to do any extra parsing and formatting
// since the object we're given was already a fully instantiated object.
$parameters = [$passable, $stack];
}
return call_user_func_array([$pipe, $this->method], $parameters);
};
};
}
/**
* Get the initial slice to begin the stack call.
*
* @param \Closure $destination
* @return \Closure
*/
protected function getInitialSlice(Closure $destination)
{
return function ($passable) use ($destination) {
return call_user_func($destination, $passable);
};
}
/**
* Parse full pipe string to get name and parameters.
*
* @param string $pipe
* @return array
*/
protected function parsePipeString($pipe)
{
list($name, $parameters) = array_pad(explode(':', $pipe, 2), 2, []);
if (is_string($parameters)) {
$parameters = explode(',', $parameters);
}
return [$name, $parameters];
}
}

View File

@@ -1,38 +1,39 @@
<?php namespace Illuminate\Pipeline;
<?php
namespace Illuminate\Pipeline;
use Illuminate\Support\ServiceProvider;
class PipelineServiceProvider extends ServiceProvider {
class PipelineServiceProvider extends ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = true;
/**
* 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(
'Illuminate\Contracts\Pipeline\Hub', 'Illuminate\Pipeline\Hub'
);
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return [
'Illuminate\Contracts\Pipeline\Hub',
];
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->singleton(
'Illuminate\Contracts\Pipeline\Hub', 'Illuminate\Pipeline\Hub'
);
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return [
'Illuminate\Contracts\Pipeline\Hub',
];
}
}

View File

@@ -14,9 +14,9 @@
}
],
"require": {
"php": ">=5.4.0",
"illuminate/contracts": "5.0.*",
"illuminate/support": "5.0.*"
"php": ">=5.5.9",
"illuminate/contracts": "5.2.*",
"illuminate/support": "5.2.*"
},
"autoload": {
"psr-4": {
@@ -25,7 +25,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "5.0-dev"
"dev-master": "5.2-dev"
}
},
"minimum-stability": "dev"