Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/Illuminate/Contracts/Pipeline/Hub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Illuminate\Contracts\Pipeline;

interface Hub
{
/**
* Send an object through one of the available pipelines.
*
* @param mixed $object
* @param string|null $pipeline
* @return mixed
*/
public function pipe($object, $pipeline = null);
}
40 changes: 40 additions & 0 deletions src/Illuminate/Contracts/Pipeline/Pipeline.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Illuminate\Contracts\Pipeline;

use Closure;

interface Pipeline
{
/**
* Set the object being sent through the pipeline.
*
* @param mixed $passable
* @return $this
*/
public function send($passable);

/**
* Set the array of pipes.
*
* @param mixed $pipes
* @return $this
*/
public function through($pipes);

/**
* Set the method to call on the pipes.
*
* @param string $method
* @return $this
*/
public function via($method);

/**
* Run the pipeline with a final destination callback.
*
* @param \Closure $destination
* @return mixed
*/
public function then(Closure $destination);
}
13 changes: 13 additions & 0 deletions src/Illuminate/Contracts/Support/DeferrableProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Illuminate\Contracts\Support;

interface DeferrableProvider
{
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides();
}
101 changes: 101 additions & 0 deletions src/Illuminate/Pipeline/Hub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php

namespace Illuminate\Pipeline;

use Closure;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Pipeline\Hub as HubContract;
use InvalidArgumentException;

class Hub implements HubContract
{
/**
* The container implementation.
*
* @var \Illuminate\Contracts\Container\Container|null
*/
protected $container;

/**
* All of the available pipelines.
*
* @var array
*/
protected $pipelines = [];

/**
* Create a new Hub instance.
*
* @param \Illuminate\Contracts\Container\Container|null $container
*/
public function __construct(?Container $container = null)
{
$this->container = $container;
}

/**
* Define the default named pipeline.
*
* @param \Closure $callback
* @return void
*/
public function defaults(Closure $callback)
{
$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;
}

/**
* 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';

if (! isset($this->pipelines[$pipeline])) {
throw new InvalidArgumentException("Pipeline [{$pipeline}] is not defined.");
}

return call_user_func(
$this->pipelines[$pipeline], new Pipeline($this->container), $object
);
}

/**
* Get the container instance used by the hub.
*
* @return \Illuminate\Contracts\Container\Container
*/
public function getContainer()
{
return $this->container;
}

/**
* Set the container instance used by the hub.
*
* @param \Illuminate\Contracts\Container\Container $container
* @return $this
*/
public function setContainer(Container $container)
{
$this->container = $container;

return $this;
}
}
Loading
Loading