Ejemplo n.º 1
0
 private static function instance()
 {
     if (self::$instance === null) {
         self::$instance = new NameFactory();
     }
     return self::$instance;
 }
Ejemplo n.º 2
0
 /**
  * Creates a default name for this index.
  *
  */
 protected function createName()
 {
     // ASSUMPTION: This Index not yet added to the list.
     $inputs[] = $this->table->getDatabase();
     $inputs[] = $this->table->getCommonName();
     $inputs[] = 'U';
     $inputs[] = count($this->table->getUnices()) + 1;
     // @TODO replace the factory by a real object
     $this->name = NameFactory::generateName(NameFactory::CONSTRAINT_GENERATOR, $inputs);
 }
Ejemplo n.º 3
0
 private function createName()
 {
     $table = $this->getTable();
     $inputs = array();
     $inputs[] = $table->getDatabase();
     $inputs[] = $table->getCommonName();
     if ($this->isUnique()) {
         $inputs[] = "U";
     } else {
         $inputs[] = "I";
     }
     // ASSUMPTION: This Index not yet added to the list.
     if ($this->isUnique()) {
         $inputs[] = count($table->getUnices()) + 1;
     } else {
         $inputs[] = count($table->getIndices()) + 1;
     }
     $this->indexName = NameFactory::generateName(NameFactory::CONSTRAINT_GENERATOR, $inputs);
 }
Ejemplo n.º 4
0
 public static function generatePhpName($name, $phpNamingMethod = PhpNameGenerator::CONV_METHOD_CLEAN, $namePrefix = null)
 {
     return NameFactory::generateName(NameFactory::PHP_GENERATOR, array($name, $phpNamingMethod, $namePrefix));
 }
Ejemplo n.º 5
0
 public function buildPhpName($name)
 {
     return NameFactory::generateName(NameFactory::PHP_GENERATOR, array($name, $this->phpNamingMethod));
 }
Ejemplo n.º 6
0
 /**
  * Get name to use in PHP sources
  * @return     string
  */
 public function getPhpName()
 {
     if ($this->phpName === null) {
         $inputs = array();
         $inputs[] = $this->name;
         $inputs[] = $this->phpNamingMethod;
         try {
             $this->phpName = NameFactory::generateName(NameFactory::PHP_GENERATOR, $inputs);
         } catch (EngineException $e) {
             print $e->getMessage() . "\n";
             print $e->getTraceAsString();
         }
     }
     return $this->phpName;
 }
Ejemplo n.º 7
0
 /**
  * @throws     Exception on fail
  */
 public function testNames()
 {
     for ($algoIndex = 0; $algoIndex < count(self::$ALGORITHMS); $algoIndex++) {
         $algo = self::$ALGORITHMS[$algoIndex];
         $algoInputs = self::$INPUTS[$algoIndex];
         for ($i = 0; $i < count($algoInputs); $i++) {
             $inputs = $this->makeInputs($algo, $algoInputs[$i]);
             $generated = NameFactory::generateName($algo, $inputs);
             $expected = self::$OUTPUTS[$algoIndex][$i];
             $this->assertEquals($expected, $generated, 0, "Algorithm " . $algo . " failed to generate an unique name");
         }
     }
 }
Ejemplo n.º 8
0
 /**
  * Get name to use in PHP sources
  * @return     string
  */
 public function getPhpName()
 {
     if ($this->phpName === null) {
         $inputs = array();
         $inputs[] = $this->name;
         $inputs[] = $this->phpNamingMethod;
         $inputs[] = $this->namePrefix;
         return NameFactory::generateName(NameFactory::PHP_GENERATOR, $inputs);
     }
     return $this->phpName;
 }
Ejemplo n.º 9
0
 /**
  * Pass in a WFModelEntity object with a name filled out.
  *
  * @param object WFModelEntity An WFModelEntity with a name.
  * @throws object WFModelEntity
  */
 function buildEntityModel($entity)
 {
     if (!$entity instanceof WFModelEntity) {
         throw new WFException("WFModelEntity required.");
     }
     $name = $entity->valueForKey('name');
     if (isset($this->builtEntities[$name])) {
         return $this->builtEntities[$name];
     }
     // build a WFModelEntity structure from the Propel metadata....
     $tableMap = $this->getEntityMetadata($name);
     // set up properties
     foreach ($tableMap->getColumns() as $column) {
         $property = new WFModelEntityProperty();
         $propertyName = $column->getPhpName();
         $propertyName[0] = strtolower($propertyName[0]);
         $property->setValueForKey($propertyName, 'name');
         $property->setValueForKey($column->getDefaultValue(), 'defaultValue');
         // BOOLEAN|TINYINT|SMALLINT|INTEGER|BIGINT|DOUBLE|FLOAT|REAL|DECIMAL|CHAR|{VARCHAR}|LONGVARCHAR|DATE|TIME|TIMESTAMP|BLOB|CLOB
         switch (strtoupper($column->getType())) {
             case 'TINYINT':
             case 'SMALLINT':
             case 'INTEGER':
             case 'BIGINT':
             case 'DOUBLE':
             case 'NUMERIC':
             case 'FLOAT':
             case 'REAL':
             case 'DECIMAL':
                 $type = WFModelEntityProperty::TYPE_NUMBER;
                 break;
             case 'TIMESTAMP':
             case 'DATETIME':
             case 'DATE':
                 $type = WFModelEntityProperty::TYPE_DATETIME;
                 break;
             case 'TEXT':
             case 'LONGVARCHAR':
                 $type = WFModelEntityProperty::TYPE_TEXT;
                 break;
             case 'BOOLEAN':
                 $type = WFModelEntityProperty::TYPE_BOOLEAN;
                 break;
             case 'CHAR':
             case 'VARCHAR':
             case 'STRING':
                 $type = WFModelEntityProperty::TYPE_STRING;
                 break;
             default:
                 print "WARNING: Unknown property type for column " . $property->valueForKey('name') . ": " . $column->getType() . "\n";
                 $type = WFModelEntityProperty::TYPE_STRING;
                 break;
         }
         if (!$entity->valueForKey('descriptiveColumnName') && $type === WFModelEntityProperty::TYPE_STRING) {
             $entity->setValueForKey($property->valueForKey('name'), 'descriptiveColumnName');
         }
         if (!$entity->valueForKey('primaryKeyProperty') && $column->isPrimaryKey()) {
             $entity->setValueForKey($property->valueForKey('name'), 'primaryKeyProperty');
         }
         $property->setValueForKey($type, 'type');
         $entity->addProperty($property);
     }
     if (!$entity->valueForKey('descriptiveColumnName')) {
         $entity->setValueForKey($entity->valueForKey('primaryKeyProperty'), 'descriptiveColumnName');
     }
     // set up relationships
     foreach ($tableMap->getColumns() as $column) {
         if (!$column->isForeignKey()) {
             continue;
         }
         // get related entity
         $relatedEntityName = NameFactory::generateName(NameFactory::PHP_GENERATOR, array($column->getRelatedTableName(), NameGenerator::CONV_METHOD_PHPNAME));
         $relatedEntityTableMap = $this->getEntityMetadata($relatedEntityName);
         $relatedEntity = WFModel::sharedModel()->getEntity($relatedEntityTableMap->getPhpName());
         if (!$relatedEntity) {
             $relatedEntity = WFModel::sharedModel()->buildEntity($relatedEntityTableMap->getPhpName());
         }
         // configure relationship
         $relName = $relatedEntity->valueForKey('name');
         if (!$entity->getRelationship($relName)) {
             // create relationship from this table to the other one
             $rel = new WFModelEntityRelationship();
             $rel->setToOne(true);
             // if we are the fk column, it must be to-one (unless it's many-to-many)
             $rel->setValueForKey($relName, 'name');
             // singular
             $rel->setValueForKey($column->isNotNull(), 'required');
             $entity->addRelationship($rel);
         }
         // create relationship in the other direction
         $invRelName = $tableMap->getPhpName();
         // make plural as needed -
         if (!$relatedEntity->getRelationship($invRelName)) {
             $invRel = new WFModelEntityRelationship();
             // configure relationship
             $inverseRelationshipIsToOne = false;
             // is this an "extension" table? TRUE if the relationship is on our PK; this makes the INVERSE relationship have an EXT relationship to this table
             if ($column->isPrimaryKey()) {
                 $inverseRelationshipIsToOne = true;
                 $invRel->setValueForKey(true, 'isExtension');
             }
             $invRel->setToOne($inverseRelationshipIsToOne);
             $invRel->setValueForKey($invRelName, 'name');
             $relatedEntity->addRelationship($invRel);
         }
     }
     $this->builtEntities[$entity->valueForKey('name')] = $entity;
 }