1 | <?php |
||
14 | class JSONCatalogProvider implements CatalogProviderInterface |
||
15 | { |
||
16 | /** |
||
17 | * @var FilesystemInterface $filesystem The filesystem this Catalog instance works on |
||
18 | */ |
||
19 | private $filesystem; |
||
20 | |||
21 | /** |
||
22 | * @var string $catalogFilePath The path to the JSON file containing the catalog in the given $filesystem |
||
23 | */ |
||
24 | private $catalogFilePath; |
||
25 | |||
26 | /** |
||
27 | * @var CatalogMapper A catalog mapper for converting unstructured catalog data into Catalog models |
||
28 | */ |
||
29 | private $catalogMapper; |
||
30 | |||
31 | /** |
||
32 | * Creates a new instance of the JSONCatalogProvider class. |
||
33 | * |
||
34 | * @param FilesystemInterface $filesystem The filesystem this Catalog instance works on |
||
35 | * @param string $catalogFilePath The path to the JSON file containing the catalog in the given |
||
36 | * $filesystem |
||
37 | * |
||
38 | * @param CatalogMapper $catalogMapper A catalog mapper for converting unstructured catalog data into |
||
39 | * Catalog models |
||
40 | */ |
||
41 | public function __construct(FilesystemInterface $filesystem, string $catalogFilePath, CatalogMapper $catalogMapper) |
||
47 | |||
48 | /** |
||
49 | * Get the product catalog. |
||
50 | * |
||
51 | * @return Catalog |
||
52 | * |
||
53 | * @throws CatalogException If the catalog could not be created. |
||
54 | */ |
||
55 | public function getCatalog() |
||
76 | |||
77 | /** |
||
78 | * Parse the given JSON and convert it into an array. |
||
79 | * |
||
80 | * @param string $json JSON code |
||
81 | * |
||
82 | * @return array |
||
83 | * |
||
84 | * @throws JSONException If the given JSON could not be parsed |
||
85 | */ |
||
86 | private function parseJSON($json) |
||
112 | } |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: