1 |
cb15593b
|
Cajova-Houba
|
<?php
|
2 |
|
|
|
3 |
|
|
namespace Illuminate\Pipeline;
|
4 |
|
|
|
5 |
|
|
use Closure;
|
6 |
|
|
use Illuminate\Contracts\Container\Container;
|
7 |
|
|
use Illuminate\Contracts\Pipeline\Hub as HubContract;
|
8 |
|
|
|
9 |
|
|
class Hub implements HubContract
|
10 |
|
|
{
|
11 |
|
|
/**
|
12 |
|
|
* The container implementation.
|
13 |
|
|
*
|
14 |
|
|
* @var \Illuminate\Contracts\Container\Container
|
15 |
|
|
*/
|
16 |
|
|
protected $container;
|
17 |
|
|
|
18 |
|
|
/**
|
19 |
|
|
* All of the available pipelines.
|
20 |
|
|
*
|
21 |
|
|
* @var array
|
22 |
|
|
*/
|
23 |
|
|
protected $pipelines = [];
|
24 |
|
|
|
25 |
|
|
/**
|
26 |
|
|
* Create a new Hub instance.
|
27 |
|
|
*
|
28 |
|
|
* @param \Illuminate\Contracts\Container\Container $container
|
29 |
|
|
* @return void
|
30 |
|
|
*/
|
31 |
|
|
public function __construct(Container $container)
|
32 |
|
|
{
|
33 |
|
|
$this->container = $container;
|
34 |
|
|
}
|
35 |
|
|
|
36 |
|
|
/**
|
37 |
|
|
* Define the default named pipeline.
|
38 |
|
|
*
|
39 |
|
|
* @param \Closure $callback
|
40 |
|
|
* @return void
|
41 |
|
|
*/
|
42 |
|
|
public function defaults(Closure $callback)
|
43 |
|
|
{
|
44 |
|
|
return $this->pipeline('default', $callback);
|
45 |
|
|
}
|
46 |
|
|
|
47 |
|
|
/**
|
48 |
|
|
* Define a new named pipeline.
|
49 |
|
|
*
|
50 |
|
|
* @param string $name
|
51 |
|
|
* @param \Closure $callback
|
52 |
|
|
* @return void
|
53 |
|
|
*/
|
54 |
|
|
public function pipeline($name, Closure $callback)
|
55 |
|
|
{
|
56 |
|
|
$this->pipelines[$name] = $callback;
|
57 |
|
|
}
|
58 |
|
|
|
59 |
|
|
/**
|
60 |
|
|
* Send an object through one of the available pipelines.
|
61 |
|
|
*
|
62 |
|
|
* @param mixed $object
|
63 |
|
|
* @param string|null $pipeline
|
64 |
|
|
* @return mixed
|
65 |
|
|
*/
|
66 |
|
|
public function pipe($object, $pipeline = null)
|
67 |
|
|
{
|
68 |
|
|
$pipeline = $pipeline ?: 'default';
|
69 |
|
|
|
70 |
|
|
return call_user_func(
|
71 |
|
|
$this->pipelines[$pipeline], new Pipeline($this->container), $object
|
72 |
|
|
);
|
73 |
|
|
}
|
74 |
|
|
}
|