1 | <?php |
||
18 | class Factory |
||
19 | { |
||
20 | |||
21 | /** |
||
22 | * @var \Psr\Log\LoggerInterface |
||
23 | */ |
||
24 | protected $logger; |
||
25 | |||
26 | /** |
||
27 | * @var \FeedIo\Adapter\ClientInterface |
||
28 | */ |
||
29 | protected $client; |
||
30 | |||
31 | /** |
||
32 | * @var FeedIo\Factory\LoggerBuilderInterface |
||
33 | */ |
||
34 | protected $loggerBuilder; |
||
35 | |||
36 | 3 | static public function create( |
|
37 | array $loggerConfig = [ |
||
38 | 'builder' => 'NullLogger', |
||
39 | 'config' => [], |
||
40 | ], |
||
41 | array $clientConfig = [ |
||
42 | 'builder' => 'GuzzleClient', |
||
43 | 'config' => [], |
||
44 | ] |
||
45 | |||
46 | ) |
||
47 | { |
||
48 | 3 | $factory = new static(); |
|
49 | |||
50 | 3 | $factory->setClientBuilder( |
|
51 | 3 | $factory->getBuilder($clientConfig['builder'], $factory->extractConfig($clientConfig))) |
|
52 | 3 | ->setLoggerBuilder( |
|
53 | 3 | $factory->getBuilder($loggerConfig['builder'],$factory->extractConfig($loggerConfig))); |
|
54 | |||
55 | |||
56 | 3 | return $factory; |
|
57 | } |
||
58 | |||
59 | /** |
||
60 | * @param $builderConfig |
||
61 | * @return array |
||
62 | */ |
||
63 | 5 | public function extractConfig(array $builderConfig) |
|
67 | |||
68 | /** |
||
69 | * @return \FeedIo\FeedIo |
||
70 | */ |
||
71 | 2 | public function getFeedIo() |
|
72 | { |
||
73 | 2 | return new FeedIo( |
|
74 | 2 | $this->clientBuilder->getClient(), |
|
|
|||
75 | 2 | $this->loggerBuilder->getLogger() |
|
76 | 2 | ); |
|
77 | } |
||
78 | |||
79 | 5 | public function getBuilder($builder, array $args = []) |
|
80 | { |
||
81 | 5 | $class = "\FeedIo\Factory\Builder\\{$builder}Builder"; |
|
82 | |||
83 | 5 | if ( ! class_exists($class) ) { |
|
84 | 1 | $class = $builder; |
|
85 | 1 | } |
|
86 | |||
87 | 5 | $reflection = new \ReflectionClass($class); |
|
88 | |||
89 | 5 | return $reflection->newInstanceArgs($args); |
|
90 | } |
||
91 | |||
92 | 5 | public function setLoggerBuilder(LoggerBuilderInterface $loggerBuilder) |
|
98 | |||
99 | 5 | public function setClientBuilder(ClientBuilderInterface $clientBuilder) |
|
100 | { |
||
101 | 5 | $this->clientBuilder = $clientBuilder; |
|
105 | |||
106 | /** |
||
107 | * @param BuilderInterface $builder |
||
108 | * @return boolean true if the dependency is met |
||
109 | */ |
||
110 | 2 | public function checkDependency(BuilderInterface $builder) |
|
119 | } |
||
120 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.