[李景山php]每天laravel-20160925|Pipeline.php
2016-07-23 09:15
483 查看
<?php namespace Illuminate\Pipeline; use Closure; use Illuminate\Contracts\Container\Container; use Illuminate\Contracts\Pipeline\Pipeline as PipelineContract; // use name space like Pipeline Contract class Pipeline implements PipelineContract {//class Pipeline implements PipelineContract /** * The container implementation. * * @var \Illuminate\Contracts\Container\Container */ protected $container;// The container implementation. // one instance of this implements // about this Pipeline Contract /** * The object being passed through the pipeline. * * @var mixed */ protected $passable;//a flag about this The object being passed through the pipeline. /** * The array of class pipes. * * @var array */ protected $pipes = [];//The array of class pipes. /** * The method to call on each pipe. * * @var string */ protected $method = 'handle';// The method to call on each pipe. // get this 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 about this container /** * Set the object being sent through the pipeline. * * @param mixed $passable * @return $this */ public function send($passable) { $this->passable = $passable;// a passable return $this;// use this pipeline class instance back or return this }//Set the object being sent through the pipeline. /** * Set the array of pipes. * * @param array|mixed $pipes * @return $this */ public function through($pipes) { $this->pipes = is_array($pipes) ? $pipes : func_get_args();//this is a array return $this;//return this }// Set the array of pipes /** * Set the method to call on the pipes. * * @param string $method * @return $this */ public function via($method) { $this->method = $method;//like via like return $this; }//Set the method to call on the pipes. /** * Run the pipeline with a final destination callback. * * @param \Closure $destination * @return mixed */ public function then(Closure $destination) { $firstSlice = $this->getInitialSlice($destination);//first Slice $pipes = array_reverse($this->pipes);// array_reverse get a un sort array return call_user_func(// call a function array_reduce($pipes, $this->getSlice(), $firstSlice), $this->passable ); }//Run the pipeline with a final destination callback. /** * Get a Closure that represents a slice of the application onion. * * @return \Closure */ protected function getSlice() {// Get a Closure that represent a slice of the application onion 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);// call a function } else { list($name, $parameters) = $this->parsePipeString($pipe);// get a list return call_user_func_array([$this->container->make($name), $this->method], array_merge([$passable, $stack], $parameters)); }//call function };//other return a function };//just a function } /** * 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); };// return function as a use way,never use like it }// Get the initial slice to begin the stack call protected function jingshan(Closure $a){ return function ($c) use($a){ return call_user_func($a,$c); }; }//maybe it is a good type , a method about this function /** * 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, []);// very good way to make it! if (is_string($parameters)) { $parameters = explode(',', $parameters); }// if a parameters return [$name, $parameters];// return array }//Parse full pipe string to get name and parameters. // }
相关文章推荐
- PHP对象在内存中的分配
- [李景山php]每天laravel-20160924|PiplineServiceProvider.php
- [李景山php]每天laravel-20160924|PiplineServiceProvider.php
- [李景山php]每天laravel-20160923|Hub.php
- [李景山php]每天laravel-20160923|Hub.php
- DroidPlugin源码分析插件进程管理以及预注册Activity,Service,ContentProvide的选择
- 系统吞吐量、TPS(QPS)、用户并发量、性能测试概念和公式
- windows php 所有版本ftp 下载站点
- 插件框架一之ContentProvider和BroadcastReceiver
- php类模块引擎PDO操作MySQL数据库简单阐述
- vsftp详细配置——/etc/vsftpd/vsftpd.conf
- JHTP自测题_第十一章_深入理解异常(Exception Handling)
- yii框架如何引入css、img、js文件
- php实现批量修改文件名称的方法
- PHP实现清除MySQL死连接的方法
- yii2控制器Controller Ajax操作示例
- Yii2简单实现多语言配置的方法
- yii2 RBAC使用DbManager实现后台权限判断的方法
- Yii2验证器(Validator)用法分析
- Yii2创建表单(ActiveForm)方法详解