Puli\Manager\Factory\FactoryManagerImpl::generateFactoryClass PHP Метод

generateFactoryClass() публичный Метод

public generateFactoryClass ( $path = null, $className = null )
    public function generateFactoryClass($path = null, $className = null)
    {
        Assert::nullOrStringNotEmpty($path, 'The path to the generated factory file must be a non-empty string or null. Got: %s');
        Assert::nullOrStringNotEmpty($className, 'The class name of the generated factory must be a non-empty string or null. Got: %s');
        $path = Path::makeAbsolute($path ?: $this->config->get(Config::FACTORY_OUT_FILE), $this->rootDir);
        $className = $className ?: $this->config->get(Config::FACTORY_OUT_CLASS);
        $dispatcher = $this->context->getEventDispatcher();
        $class = new Clazz($className);
        $class->setFilePath($path);
        $class->setDescription(<<<'EOF'
Creates Puli's core services.

This class was auto-generated by Puli.

IMPORTANT: Before modifying the code below, set the "factory.auto-generate"
configuration key to false:

    $ puli config factory.auto-generate false

Otherwise any modifications will be overwritten!
EOF
);
        $this->addCreateRepositoryMethod($class);
        $this->addCreateDiscoveryMethod($class);
        $this->addCreateUrlGeneratorMethod($class);
        $this->addGetModuleOrderMethod($class);
        if ($dispatcher->hasListeners(PuliEvents::GENERATE_FACTORY)) {
            $dispatcher->dispatch(PuliEvents::GENERATE_FACTORY, new GenerateFactoryEvent($class));
        }
        $this->classWriter->writeClass($class);
    }

Usage Example

Пример #1
0
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testGenerateFactoryClassFailsIfClassNameNoString()
 {
     $this->manager->generateFactoryClass(null, 1234);
 }