Version 1
[yaffs-website] / vendor / alchemy / zippy / src / Resource / ResourceTeleporter.php
1 <?php
2 /*
3  * This file is part of Zippy.
4  *
5  * (c) Alchemy <info@alchemy.fr>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10 namespace Alchemy\Zippy\Resource;
11
12 use Alchemy\Zippy\Resource\Resource as ZippyResource;
13
14 class ResourceTeleporter
15 {
16     private $container;
17
18     /**
19      * Constructor
20      *
21      * @param TeleporterContainer $container
22      */
23     public function __construct(TeleporterContainer $container)
24     {
25         $this->container = $container;
26     }
27
28     /**
29      * Teleports a resource to its target in the context
30      *
31      * @param string        $context
32      * @param ZippyResource $resource
33      *
34      * @return ResourceTeleporter
35      */
36     public function teleport($context, ZippyResource $resource)
37     {
38         $this
39             ->container
40             ->fromResource($resource)
41             ->teleport($resource, $context);
42
43         return $this;
44     }
45
46     /**
47      * Creates the ResourceTeleporter with the default TeleporterContainer
48      *
49      * @return ResourceTeleporter
50      */
51     public static function create()
52     {
53         return new static(TeleporterContainer::load());
54     }
55 }