<?php
namespace Illuminate\Pipeline;
use Closure;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Pipeline\Hub as HubContract;
// amespace
class Hub implements HubContract
{// Class Hub implements HubContract
/**
* The container implementation.
*
* @var \Illuminate\Contracts\Container\Container
*/
protected $container;// The container implementation
/**
* All of the available pipelines.
*
* @var array
*/
protected $pipelines = [];//All of the available 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 Hub instance
// use this parameter as container
/**
* Define the default named pipeline.
*
* @param \Closure $callback
* @return void
*/
public function defaults(Closure $callback)
{
return $this->pipeline('default', $callback);//set default
}//Define the default named pipeline
/**
* Define a new named pipeline.
*
* @param string $name
* @param \Closure $callback
* @return void
*/
public function pipeline($name, Closure $callback)
{
$this->pipelines[$name] = $callback;// this pipelines be set
}//Define a new named pipeline.
/**
* 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
);// just call a function use instanceof Pipeline
}//Send an object through
}
本文出自 “专注php 群号:414194301” 博客,请务必保留此出处http://jingshanls.blog.51cto.com/3357095/1829007