/**
  * Returns classpath to parent class.
  * @return     string
  */
 protected function getParentClassName()
 {
     $ancestorClassName = ClassTools::classname($this->getChild()->getAncestor());
     if ($this->getDatabase()->hasTableByPhpName($ancestorClassName)) {
         return $this->getNewStubQueryBuilder($this->getDatabase()->getTableByPhpName($ancestorClassName))->getClassname();
     } else {
         // find the inheritance for the parent class
         foreach ($this->getTable()->getChildrenColumn()->getChildren() as $child) {
             if ($child->getClassName() == $ancestorClassName) {
                 return $this->getNewStubQueryInheritanceBuilder($child)->getClassname();
             }
         }
     }
 }
Exemplo n.º 2
0
 protected function addClassOpen(&$script)
 {
     $table = $this->getTable();
     $tableName = $table->getName();
     $tableDesc = $table->getDescription();
     $interface = $this->getInterface();
     $script .= "\n/**\n * Base class that represents a row from the '{$tableName}' table.\n *\n * {$tableDesc}\n *";
     if ($this->getBuildProperty('addTimeStamp')) {
         $now = strftime('%c');
         $script .= "\n * This class was autogenerated by Propel " . $this->getBuildProperty('version') . " on:\n *\n * {$now}\n *";
     }
     $script .= "\n * @package " . $this->getPackage() . "\n * @subpackage " . $this->getSubpackage() . "\n */\nabstract class " . $this->getClassname() . " extends " . ClassTools::classname($this->getBaseClass()) . " ";
     $interface = ClassTools::getInterface($table);
     if ($interface) {
         $script .= " implements " . ClassTools::classname($interface);
     }
     $script .= " {\n\n";
 }
Exemplo n.º 3
0
 /**
  * Returns the name of the current class being built.
  * @return string
  */
 public function getUnprefixedClassname()
 {
     return ClassTools::classname($this->getInterface());
 }
Exemplo n.º 4
0
 /**
  * Adds class phpdoc comment and openning of class.
  * @param      string &$script The script will be modified in this method.
  */
 protected function addClassOpen(&$script)
 {
     $table = $this->getTable();
     $tableName = $table->getName();
     $tableDesc = $table->getDescription();
     $interface = $this->getInterface();
     $parentClass = $this->getBehaviorContent('parentClass');
     $parentClass = null !== $parentClass ? $parentClass : ClassTools::classname($this->getBaseClass());
     $script .= "\n/**\n * Base class that represents a row from the '{$tableName}' table.\n *\n * {$tableDesc}\n *";
     if ($this->getBuildProperty('addTimeStamp')) {
         $now = strftime('%c');
         $script .= "\n * This class was autogenerated by Propel " . $this->getBuildProperty('version') . " on:\n *\n * {$now}\n *";
     }
     $script .= "\n * @package    propel.generator." . $this->getPackage() . "\n */\nabstract class " . $this->getClassname() . " extends " . $parentClass . " ";
     $interface = ClassTools::getInterface($table);
     if ($interface) {
         $script .= " implements " . ClassTools::classname($interface);
     }
     if ($this->getTable()->getInterface()) {
         $this->declareClassFromBuilder($this->getInterfaceBuilder());
     }
     $script .= "\n{\n";
 }
Exemplo n.º 5
0
 /**
  * Lists data model classes and builds an associative array className => classPath
  * To be used for autoloading
  * @return array
  */
 protected function getClassMap()
 {
     $phpconfClassmap = array();
     $generatorConfig = $this->getGeneratorConfig();
     foreach ($this->getDataModels() as $dataModel) {
         foreach ($dataModel->getDatabases() as $database) {
             $classMap = array();
             foreach ($database->getTables() as $table) {
                 if (!$table->isForReferenceOnly()) {
                     // -----------------------------------------------------
                     // Add TableMap class,
                     //     Peer, Object & Query stub classes,
                     // and Peer, Object & Query base classes
                     // -----------------------------------------------------
                     // (this code is based on PropelOMTask)
                     foreach (array('tablemap', 'peerstub', 'objectstub', 'querystub', 'peer', 'object', 'query') as $target) {
                         $builder = $generatorConfig->getConfiguredBuilder($table, $target);
                         $this->log("Adding class mapping: " . $builder->getClassname() . ' => ' . $builder->getClassFilePath());
                         $classMap[$builder->getClassname()] = $builder->getClassFilePath();
                     }
                     // -----------------------------------------------------
                     // Add children classes for object and query,
                     // as well as base child query,
                     // for single tabel inheritance tables.
                     // -----------------------------------------------------
                     if ($col = $table->getChildrenColumn()) {
                         if ($col->isEnumeratedClasses()) {
                             foreach ($col->getChildren() as $child) {
                                 foreach (array('objectmultiextend', 'queryinheritance', 'queryinheritancestub') as $target) {
                                     $builder = $generatorConfig->getConfiguredBuilder($table, $target);
                                     $builder->setChild($child);
                                     $this->log("Adding class mapping: " . $builder->getClassname() . ' => ' . $builder->getClassFilePath());
                                     $classMap[$builder->getClassname()] = $builder->getClassFilePath();
                                 }
                             }
                         }
                     }
                     // -----------------------------------------------------
                     // Add base classes for alias tables (undocumented)
                     // -----------------------------------------------------
                     $baseClass = $table->getBaseClass();
                     if ($baseClass !== null) {
                         $className = ClassTools::classname($baseClass);
                         if (!isset($classMap[$className])) {
                             $classPath = ClassTools::getFilePath($baseClass);
                             $this->log('Adding class mapping: ' . $className . ' => ' . $classPath);
                             $classMap[$className] = $classPath;
                         }
                     }
                     $basePeer = $table->getBasePeer();
                     if ($basePeer !== null) {
                         $className = ClassTools::classname($basePeer);
                         if (!isset($classMap[$className])) {
                             $classPath = ClassTools::getFilePath($basePeer);
                             $this->log('Adding class mapping: ' . $className . ' => ' . $classPath);
                             $classMap[$className] = $classPath;
                         }
                     }
                     // ----------------------------------------------
                     // Add classes for interface
                     // ----------------------------------------------
                     if ($table->getInterface()) {
                         $builder = $generatorConfig->getConfiguredBuilder($table, 'interface');
                         $this->log("Adding class mapping: " . $builder->getClassname() . ' => ' . $builder->getClassFilePath());
                         $classMap[$builder->getClassname()] = $builder->getClassFilePath();
                     }
                     // ----------------------------------------------
                     // Add classes from old treeMode implementations
                     // ----------------------------------------------
                     if ($table->treeMode() == 'MaterializedPath') {
                         foreach (array('nodepeerstub', 'nodestub', 'nodepeer', 'node') as $target) {
                             $builder = $generatorConfig->getConfiguredBuilder($table, $target);
                             $this->log("Adding class mapping: " . $builder->getClassname() . ' => ' . $builder->getClassFilePath());
                             $classMap[$builder->getClassname()] = $builder->getClassFilePath();
                         }
                     }
                     if ($table->treeMode() == 'NestedSet') {
                         foreach (array('nestedset', 'nestedsetpeer') as $target) {
                             $builder = $generatorConfig->getConfiguredBuilder($table, $target);
                             $this->log("Adding class mapping: " . $builder->getClassname() . ' => ' . $builder->getClassFilePath());
                             $classMap[$builder->getClassname()] = $builder->getClassFilePath();
                         }
                     }
                 }
                 // if (!$table->isReferenceOnly())
             }
             $phpconfClassmap = array_merge($phpconfClassmap, $classMap);
         }
     }
     return $phpconfClassmap;
 }
 /**
  * Returns classname of parent class.
  * @return     string
  */
 protected function getParentClassname()
 {
     return ClassTools::classname($this->getParentClasspath());
 }
	/**
	 * Adds class phpdoc comment and openning of class.
	 * @param      string &$script The script will be modified in this method.
	 */
	protected function addClassOpen(&$script)
	{

		$table = $this->getTable();
		$tableName = $table->getName();
		$tableDesc = $table->getDescription();
		$interface = $this->getInterface();

		$script .= "
/**
 * Base class that represents a row from the '$tableName' table.
 *
 * $tableDesc
 *";
		if ($this->getBuildProperty('addTimeStamp')) {
			$now = strftime('%c');
			$script .= "
 * This class was autogenerated by Propel on:
 *
 * $now
 *";
		}
		$script .= "
 * @package    ".$this->getPackage()."
 */
abstract class ".$this->getClassname()." extends ".ClassTools::classname($this->getBaseClass())." ";

		$interface = ClassTools::getInterface($table);
		if ($interface) {
			$script .= " implements " . ClassTools::classname($interface);
		}

		$script .= " {

";
	}
Exemplo n.º 8
0
 /**
  * Lists data model classes and builds an associative array className => classPath
  * To be used for autoloading
  * @return array
  */
 protected function getClassMap()
 {
     $phpconfClassmap = array();
     $generatorConfig = $this->getGeneratorConfig();
     foreach ($this->getDataModels() as $dataModel) {
         foreach ($dataModel->getDatabases() as $database) {
             $classMap = array();
             foreach ($database->getTables() as $table) {
                 if (!$table->isForReferenceOnly()) {
                     // Classes that I'm assuming do not need to be mapped (because they will be required by subclasses):
                     //	- base peer and object classes
                     //	- interfaces
                     //	- base node peer and object classes
                     // -----------------------------------------------------
                     // Add Peer & Object stub classes and MapBuilder classes
                     // -----------------------------------------------------
                     // (this code is based on PropelOMTask)
                     foreach (array('tablemap', 'peerstub', 'objectstub') as $target) {
                         $builder = $generatorConfig->getConfiguredBuilder($table, $target);
                         $this->log("Adding class mapping: " . $builder->getClassname() . ' => ' . $builder->getClassFilePath());
                         $classMap[$builder->getClassname()] = $builder->getClassFilePath();
                     }
                     if ($col = $table->getChildrenColumn()) {
                         if ($col->isEnumeratedClasses()) {
                             foreach ($col->getChildren() as $child) {
                                 $builder = $generatorConfig->getConfiguredBuilder($table, 'objectmultiextend');
                                 $builder->setChild($child);
                                 $this->log("Adding class mapping: " . $builder->getClassname() . ' => ' . $builder->getClassFilePath());
                                 $classMap[$builder->getClassname()] = $builder->getClassFilePath();
                             }
                         }
                     }
                     $baseClass = $table->getBaseClass();
                     if ($baseClass !== null) {
                         $className = ClassTools::classname($baseClass);
                         if (!isset($classMap[$className])) {
                             $classPath = ClassTools::getFilePath($baseClass);
                             $this->log('Adding class mapping: ' . $className . ' => ' . $classPath);
                             $classMap[$className] = $classPath;
                         }
                     }
                     $basePeer = $table->getBasePeer();
                     if ($basePeer !== null) {
                         $className = ClassTools::classname($basePeer);
                         if (!isset($classMap[$className])) {
                             $classPath = ClassTools::getFilePath($basePeer);
                             $this->log('Adding class mapping: ' . $className . ' => ' . $classPath);
                             $classMap[$className] = $classPath;
                         }
                     }
                     // ------------------------
                     // Create tree Node classes
                     // ------------------------
                     if ('MaterializedPath' == $table->treeMode()) {
                         foreach (array('nodepeerstub', 'nodestub') as $target) {
                             $builder = $generatorConfig->getConfiguredBuilder($table, $target);
                             $this->log("Adding class mapping: " . $builder->getClassname() . ' => ' . $builder->getClassFilePath());
                             $classMap[$builder->getClassname()] = $builder->getClassFilePath();
                         }
                     }
                 }
                 // if (!$table->isReferenceOnly())
             }
             $phpconfClassmap = array_merge($phpconfClassmap, $classMap);
         }
     }
     return $phpconfClassmap;
 }
 /**
  * The main method does the work of the task.
  */
 public function main()
 {
     // Check to make sure the input and output files were specified and that the input file exists.
     if (!$this->xmlConfFile || !$this->xmlConfFile->exists()) {
         throw new BuildException("No valid xmlConfFile specified.", $this->getLocation());
     }
     if (!$this->outputFile) {
         throw new BuildException("No outputFile specified.", $this->getLocation());
     }
     if (!$this->outputClassmapFile) {
         // We'll create a default one for BC
         $this->outputClassmapFile = 'classmap-' . $this->outputFile;
     }
     // Create a PHP array from the XML file
     $xmlDom = new DOMDocument();
     $xmlDom->load($this->xmlConfFile->getAbsolutePath());
     $xml = simplexml_load_string($xmlDom->saveXML());
     $phpconf = self::simpleXmlToArray($xml);
     $phpconfClassmap = array();
     // $this->log(var_export($phpconf,true));
     // Create a map of all PHP classes and their filepaths for this data model
     $generatorConfig = $this->getGeneratorConfig();
     foreach ($this->getDataModels() as $dataModel) {
         foreach ($dataModel->getDatabases() as $database) {
             $classMap = array();
             // $this->log("Processing class mappings in database: " . $database->getName());
             //print the tables
             foreach ($database->getTables() as $table) {
                 if (!$table->isForReferenceOnly()) {
                     // $this->log("\t+ " . $table->getName());
                     // Classes that I'm assuming do not need to be mapped (because they will be required by subclasses):
                     //	- base peer and object classes
                     //	- interfaces
                     //	- base node peer and object classes
                     // -----------------------------------------------------------------------------------------
                     // Add Peer & Object stub classes and MapBuilder classes
                     // -----------------------------------------------------------------------------------------
                     // (this code is based on PropelOMTask)
                     foreach (array('mapbuilder', 'peerstub', 'objectstub') as $target) {
                         $builder = $generatorConfig->getConfiguredBuilder($table, $target);
                         $this->log("Adding class mapping: " . $builder->getClassname() . ' => ' . $builder->getClassFilePath());
                         $classMap[$builder->getClassname()] = $builder->getClassFilePath();
                     }
                     if ($table->getChildrenColumn()) {
                         $col = $table->getChildrenColumn();
                         if ($col->isEnumeratedClasses()) {
                             foreach ($col->getChildren() as $child) {
                                 $builder = $generatorConfig->getConfiguredBuilder($table, 'objectmultiextend');
                                 $builder->setChild($child);
                                 $this->log("Adding class mapping: " . $builder->getClassname() . ' => ' . $builder->getClassFilePath());
                                 $classMap[$builder->getClassname()] = $builder->getClassFilePath();
                             }
                         }
                     }
                     $baseClass = $table->getBaseClass();
                     if ($baseClass !== null) {
                         $className = ClassTools::classname($baseClass);
                         if (!isset($classMap[$className])) {
                             $classPath = ClassTools::getFilePath($baseClass);
                             $this->log('Adding class mapping: ' . $className . ' => ' . $classPath);
                             $classMap[$className] = $classPath;
                         }
                     }
                     $basePeer = $table->getBasePeer();
                     if ($basePeer !== null) {
                         $className = ClassTools::classname($basePeer);
                         if (!isset($classMap[$className])) {
                             $classPath = ClassTools::getFilePath($basePeer);
                             $this->log('Adding class mapping: ' . $className . ' => ' . $classPath);
                             $classMap[$className] = $classPath;
                         }
                     }
                     // -----------------------------------------------------------------------------------------
                     // Create tree Node classes
                     // -----------------------------------------------------------------------------------------
                     if ('MaterializedPath' == $table->treeMode()) {
                         foreach (array('nodepeerstub', 'nodestub') as $target) {
                             $builder = $generatorConfig->getConfiguredBuilder($table, $target);
                             $this->log("Adding class mapping: " . $builder->getClassname() . ' => ' . $builder->getClassFilePath());
                             $classMap[$builder->getClassname()] = $builder->getClassFilePath();
                         }
                     }
                     // if Table->treeMode() == 'MaterializedPath'
                 }
                 // if (!$table->isReferenceOnly())
             }
             $phpconfClassmap['propel']['datasources'][$database->getName()]['classes'] = $classMap;
         }
     }
     //		$phpconf['propel']['classes'] = $classMap;
     $phpconf['propel']['generator_version'] = $this->getGeneratorConfig()->getBuildProperty('version');
     // Write resulting PHP data to output file:
     $outfile = new PhingFile($this->outputDirectory, $this->outputFile);
     $output = '<' . '?' . "php\n";
     $output .= "// This file generated by Propel " . $phpconf['propel']['generator_version'] . " convert-props target" . ($this->getGeneratorConfig()->getBuildProperty('addTimestamp') ? " on " . strftime("%c") : '') . "\n";
     $output .= "// from XML runtime conf file " . $this->xmlConfFile->getPath() . "\n";
     $output .= "return array_merge_recursive(";
     $output .= var_export($phpconf, true);
     $output .= ", include(dirname(__FILE__) . DIRECTORY_SEPARATOR . '" . $this->outputClassmapFile . "'));";
     $this->log("Creating PHP runtime conf file: " . $outfile->getPath());
     if (!file_put_contents($outfile->getAbsolutePath(), $output)) {
         throw new BuildException("Error creating output file: " . $outfile->getAbsolutePath(), $this->getLocation());
     }
     $outfile = new PhingFile($this->outputDirectory, $this->outputClassmapFile);
     $output = '<' . '?' . "php\n";
     $output .= "// This file generated by Propel " . $phpconf['propel']['generator_version'] . " convert-props target" . ($this->getGeneratorConfig()->getBuildProperty('addTimestamp') ? " on " . strftime("%c") : '') . "\n";
     $output .= "return ";
     $output .= var_export($phpconfClassmap, true);
     $output .= ";";
     $this->log("Creating PHP classmap runtime file: " . $outfile->getPath());
     if (!file_put_contents($outfile->getAbsolutePath(), $output)) {
         throw new BuildException("Error creating output file: " . $outfile->getAbsolutePath(), $this->getLocation());
     }
 }