TQ\Vcs\StreamWrapper\FileBuffer\Factory::findFactory PHP Méthode

findFactory() public méthode

Returns the file stream factory to handle the requested path
public findFactory ( TQ\Vcs\StreamWrapper\PathInformationInterface $path, string $mode ) : Factory
$path TQ\Vcs\StreamWrapper\PathInformationInterface The path information
$mode string The mode used to open the path
Résultat Factory The file buffer factory to handle the path
    public function findFactory(PathInformationInterface $path, $mode)
    {
        $factoryList = clone $this->factoryList;
        foreach ($factoryList as $factory) {
            /** @var $factory Factory */
            if ($factory->canHandle($path, $mode)) {
                return $factory;
            }
        }
        throw new \RuntimeException('No factory found to handle the requested path');
    }

Usage Example

 /**
  * @expectedException \RuntimeException
  */
 public function testFailsWithoutAnyFactoryResponsible()
 {
     $factory = new Factory();
     $factory1 = $this->createFactoryMock();
     $factory1->expects($this->any())->method('canHandle')->will($this->returnValue(false));
     $factory2 = $this->createFactoryMock();
     $factory2->expects($this->any())->method('canHandle')->will($this->returnValue(false));
     $factory->addFactory($factory1, 10);
     $factory->addFactory($factory2, 30);
     $path = $this->createPathMock();
     $factory->findFactory($path, 'r+');
 }