1 | <?php |
||
49 | class Factory implements FactoryInterface |
||
50 | { |
||
51 | /** |
||
52 | * The list containing the possible factories |
||
53 | * |
||
54 | * @var \SplPriorityQueue |
||
55 | */ |
||
56 | protected $factoryList; |
||
57 | |||
58 | /** |
||
59 | * Returns a default factory |
||
60 | * |
||
61 | * includes: |
||
62 | * - CommitFactory |
||
63 | * - HeadFileFactory |
||
64 | * - DefaultFactory |
||
65 | * |
||
66 | * @return Factory |
||
67 | */ |
||
68 | 116 | public static function getDefault() |
|
77 | |||
78 | /** |
||
79 | * Creates a new factory resolver |
||
80 | */ |
||
81 | 119 | public function __construct() |
|
85 | |||
86 | /** |
||
87 | * Adds a factory to the list of possible factories |
||
88 | * |
||
89 | * @param FactoryInterface $factory The factory to add |
||
90 | * @param integer $priority The priority |
||
91 | * @return Factory The factory |
||
92 | */ |
||
93 | 119 | public function addFactory(FactoryInterface $factory, $priority = 10) |
|
98 | |||
99 | /** |
||
100 | * Returns the file stream factory to handle the requested path |
||
101 | * |
||
102 | * @param PathInformationInterface $path The path information |
||
103 | * @param string $mode The mode used to open the path |
||
104 | * @return Factory The file buffer factory to handle the path |
||
105 | * @throws \RuntimeException If no factory is found to handle to the path |
||
106 | */ |
||
107 | 55 | public function findFactory(PathInformationInterface $path, $mode) |
|
108 | { |
||
109 | 55 | $factoryList = clone $this->factoryList; |
|
110 | 55 | foreach ($factoryList as $factory) { |
|
111 | /** @var $factory Factory */ |
||
112 | 55 | if ($factory->canHandle($path, $mode)) { |
|
113 | 55 | return $factory; |
|
114 | } |
||
115 | } |
||
116 | 1 | throw new \RuntimeException('No factory found to handle the requested path'); |
|
117 | } |
||
118 | |||
119 | /** |
||
120 | * Returns true if this factory can handle the requested path |
||
121 | * |
||
122 | * @param PathInformationInterface $path The path information |
||
123 | * @param string $mode The mode used to open the file |
||
124 | * @return boolean True if this factory can handle the path |
||
125 | */ |
||
126 | public function canHandle(PathInformationInterface $path, $mode) |
||
135 | |||
136 | /** |
||
137 | * Returns the file stream to handle the requested path |
||
138 | * |
||
139 | * @param PathInformationInterface $path The path information |
||
140 | * @param string $mode The mode used to open the path |
||
141 | * @return FileBufferInterface The file buffer to handle the path |
||
142 | */ |
||
143 | 52 | public function createFileBuffer(PathInformationInterface $path, $mode) |
|
148 | } |
||
149 |