/** * @return Manager */ public static function getInstance() { if (!self::$instance instanceof Manager) { self::$instance = new static(); self::$instance->reset(); } return self::$instance; }
protected function setUp() { //begin of setting runtime environments $fileSystem = vfsStream::setup(); $this->className = 'ExampleInstantiator'; $this->extends = '\\stdClass'; $this->indention = ' '; $this->namespace = 'Test\\Net\\Bazzline\\Propel'; $this->path = $fileSystem->url(); $this->prefix = 'create'; //end of setting runtime environments $buildIsNeeded = !class_exists('TableOne') || !class_exists('TableTwo'); if ($buildIsNeeded) { $schema = <<<EOF <database name="example_database" defaultIdMethod="native"> <behavior name="add_to_entity_instantiator"> <parameter name="entity_instantiator_class_name" value="{$this->className}" /> <parameter name="entity_instantiator_extends" value="{$this->extends}" /> <parameter name="entity_instantiator_indention" value="{$this->indention}" /> <parameter name="entity_instantiator_namespace" value="{$this->namespace}" /> <parameter name="entity_instantiator_path_to_output" value="{$this->path}" /> <parameter name="entity_method_name_prefix" value="{$this->prefix}" /> <parameter name="entity_add_to_entity_instantiator" value="true" /> </behavior> <table name="table_one"> <column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" /> </table> <table name="table_two"> <column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" /> <behavior name="add_to_entity_instantiator"> <parameter name="entity_add_to_entity_instantiator" value="false" /> </behavior> </table> </database> EOF; $builder = new PropelQuickBuilder(); $configuration = $builder->getConfig(); $configuration->setBuildProperty('behavior.add_to_entity_instantiator.class', __DIR__ . '/../source/AddToEntityInstantiatorBehavior'); $builder->setConfig($configuration); $builder->setSchema($schema); $builder->build(); //we have to call generate manually since it is called only when php execution is finished Manager::getInstance()->generate(); } }
/** * @return Manager */ private function resetGenerator() { $singleton = Manager::getInstance(); $reflection = new ReflectionClass($singleton); $instance = $reflection->getProperty('instance'); $instance->setAccessible(true); $instance->setValue(null, null); $instance->setAccessible(false); return $singleton; }
/** * @return Manager */ private function getManager() { $manager = Manager::getInstance(); if ($manager->isNotConfigured()) { $pathToOutput = $this->parameters[self::PARAMETER_ENTITY_INSTANTIATOR_PATH_TO_OUTPUT]; $isAbsolutePath = strncmp($pathToOutput, DIRECTORY_SEPARATOR, strlen(DIRECTORY_SEPARATOR)) === 0; //like /foo/bar $isResource = strpos($pathToOutput, '://') !== false; //like vfs:// $isAbsolutePathOrResource = $isAbsolutePath || $isResource; $absolutePathToOutput = $isAbsolutePathOrResource ? $pathToOutput : getcwd() . str_repeat(DIRECTORY_SEPARATOR . '..', 4) . DIRECTORY_SEPARATOR . $pathToOutput; $className = $this->parameters[self::PARAMETER_ENTITY_INSTANTIATOR_CLASS_NAME]; $extends = $this->parameters[self::PARAMETER_ENTITY_INSTANTIATOR_EXTENDS]; $indention = $this->parameters[self::PARAMETER_ENTITY_INSTANTIATOR_INDENTION]; $namespace = $this->parameters[self::PARAMETER_ENTITY_INSTANTIATOR_NAMESPACE]; $manager->configure($className, $indention, $absolutePathToOutput, $namespace, $extends); } return $manager; }