1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* Copyright (c) 2015 Juan José Torroglosa Ramón |
4
|
|
|
* |
5
|
|
|
* This file is part of the Cliphar package. |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view |
8
|
|
|
* the LICENSE file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Cliphar\Container\Laravel; |
12
|
|
|
|
13
|
|
|
use Cliphar\Binder; |
14
|
|
|
use Cliphar\Container\Exception\ContainerException; |
15
|
|
|
use Illuminate\Container\Container as LaravelContainer; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class LaravelBinderAdapter |
20
|
|
|
*/ |
21
|
|
|
class LaravelBinderAdapter implements Binder |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var LaravelContainer |
25
|
|
|
*/ |
26
|
|
|
private $container; |
27
|
|
|
|
28
|
|
|
public function __construct(LaravelContainer $container) |
29
|
|
|
{ |
30
|
|
|
$this->container = $container; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @inheritdoc |
35
|
|
|
*/ |
36
|
|
|
public function bind($abstract, $concrete) |
37
|
|
|
{ |
38
|
|
|
if ($concrete instanceof \Closure || is_string($concrete)) { |
39
|
|
|
$this->container->bind($abstract, $concrete); |
40
|
|
|
} else { |
41
|
|
|
throw new ContainerException("Invalid parameter. This method only accepts Closure or string for \$to parameter"); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @inheritdoc |
47
|
|
|
*/ |
48
|
|
|
public function bindSingleton($abstract, $concrete) |
49
|
|
|
{ |
50
|
|
|
if ($concrete instanceof \Closure) { |
51
|
|
|
$this->container->bindShared($abstract, $concrete); |
52
|
|
|
} else if (is_object($concrete)) { |
53
|
|
|
$this->container->instance($abstract, $concrete); |
54
|
|
|
} else if (is_string($concrete)) { |
55
|
|
|
$this->container->singleton($abstract, $concrete); |
56
|
|
|
} else { |
57
|
|
|
throw new ContainerException("Invalid parameter. This method only accepts Closure, string or object \$to parameter"); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @inheritdoc |
63
|
|
|
*/ |
64
|
|
|
public function bindToInstance($abstract, $instance) |
65
|
|
|
{ |
66
|
|
|
$this->container->instance($abstract, $instance); |
67
|
|
|
} |
68
|
|
|
} |