Exemplo n.º 1
0
 public function testMergeVendorInfo()
 {
     $current = new VendorInfo('mysql');
     $current->setParameters(['foo' => 'bar', 'baz' => 'bat']);
     $toMerge = new VendorInfo('mysql');
     $toMerge->setParameters(['foo' => 'wat', 'int' => 'mix']);
     $merged = $current->getMergedVendorInfo($toMerge);
     $this->assertInstanceOf('Propel\\Generator\\Model\\VendorInfo', $merged);
     $this->assertSame('wat', $merged->getParameter('foo'));
     $this->assertSame('bat', $merged->getParameter('baz'));
     $this->assertSame('mix', $merged->getParameter('int'));
 }
Exemplo n.º 2
0
 /**
  * Gets a new merged VendorInfo object.
  * @param      VendorInfo $info
  * @return     VendorInfo new object with merged parameters
  */
 public function getMergedVendorInfo(VendorInfo $merge)
 {
     $newParams = array_merge($this->getParameters(), $merge->getParameters());
     $newInfo = new VendorInfo($this->getType());
     $newInfo->setParameters($newParams);
     return $newInfo;
 }
 /**
  * Gets a new VendorInfo object for this platform with specified params.
  *
  * @param array $params
  */
 protected function getNewVendorInfoObject(array $params)
 {
     $type = $this->getPlatform()->getDatabaseType();
     $vi = new VendorInfo($type);
     $vi->setParameters($params);
     return $vi;
 }
Exemplo n.º 4
0
 public function testGetIndexDDLFulltext()
 {
     $table = new Table('foo');
     $table->setIdentifierQuoting(true);
     $column1 = new Column('bar1');
     $column1->getDomain()->copy($this->getPlatform()->getDomainForType('LONGVARCHAR'));
     $table->addColumn($column1);
     $index = new Index('bar_index');
     $index->addColumn($column1);
     $vendor = new VendorInfo('mysql');
     $vendor->setParameter('Index_type', 'FULLTEXT');
     $index->addVendorInfo($vendor);
     $table->addIndex($index);
     $expected = 'FULLTEXT INDEX `bar_index` (`bar1`)';
     $this->assertEquals($expected, $this->getPlatform()->getIndexDDL($index));
 }
Exemplo n.º 5
0
 /**
  * Adds a new VendorInfo instance to this current model object.
  *
  * @param  VendorInfo|array $vendor
  * @return VendorInfo
  */
 public function addVendorInfo($vendor)
 {
     if ($vendor instanceof VendorInfo) {
         $this->vendorInfos[$vendor->getType()] = $vendor;
         return $vendor;
     }
     $vi = new VendorInfo();
     $vi->loadMapping($vendor);
     return $this->addVendorInfo($vi);
 }
Exemplo n.º 6
0
 /**
  * Appends the generated <vendor> XML node to its parent node.
  *
  * @param VendorInfo $vendorInfo The VendorInfo model instance
  * @param \DOMNode   $parentNode The parent DOMNode object
  */
 private function appendVendorInformationNode(VendorInfo $vendorInfo, \DOMNode $parentNode)
 {
     $vendorNode = $parentNode->appendChild($this->document->createElement('vendor'));
     $vendorNode->setAttribute('type', $vendorInfo->getType());
     foreach ($vendorInfo->getParameters() as $key => $value) {
         $parameterNode = $this->document->createElement('parameter');
         $parameterNode->setAttribute('name', $key);
         $parameterNode->setAttribute('value', $value);
         $vendorNode->appendChild($parameterNode);
     }
 }
Exemplo n.º 7
0
 public function startElement($parser, $name, $attributes)
 {
     $parentTag = $this->peekCurrentSchemaTag();
     if (false === $parentTag) {
         switch ($name) {
             case 'database':
                 if ($this->isExternalSchema()) {
                     $this->currentPackage = isset($attributes['package']) ? $attributes['package'] : null;
                     if (null === $this->currentPackage) {
                         $this->currentPackage = $this->defaultPackage;
                     }
                 } else {
                     $this->currDB = $this->schema->addDatabase($attributes);
                 }
                 break;
             default:
                 $this->_throwInvalidTagException($parser, $name);
         }
     } elseif ('database' === $parentTag) {
         switch ($name) {
             case 'external-schema':
                 $xmlFile = isset($attributes['filename']) ? $attributes['filename'] : null;
                 // 'referenceOnly' attribute is valid in the main schema XML file only,
                 // and it's ignored in the nested external-schemas
                 if (!$this->isExternalSchema()) {
                     $isForRefOnly = isset($attributes['referenceOnly']) ? $attributes['referenceOnly'] : null;
                     $this->isForReferenceOnly = null !== $isForRefOnly ? 'true' === strtolower($isForRefOnly) : true;
                     // defaults to TRUE
                 }
                 if ('/' !== $xmlFile[0]) {
                     $xmlFile = realpath(dirname($this->currentXmlFile) . DIRECTORY_SEPARATOR . $xmlFile);
                     if (!file_exists($xmlFile)) {
                         throw new SchemaException(sprintf('Unknown include external "%s"', $xmlFile));
                     }
                 }
                 $this->parseFile($xmlFile);
                 break;
             case 'domain':
                 $this->currDB->addDomain($attributes);
                 break;
             case 'table':
                 if (!isset($attributes['schema']) && $this->currDB->getSchema() && $this->currDB->getPlatform()->supportsSchemas() && false === strpos($attributes['name'], $this->currDB->getPlatform()->getSchemaDelimiter())) {
                     $attributes['schema'] = $this->currDB->getSchema();
                 }
                 $this->currTable = $this->currDB->addTable($attributes);
                 if ($this->isExternalSchema()) {
                     $this->currTable->setForReferenceOnly($this->isForReferenceOnly);
                     $this->currTable->setPackage($this->currentPackage);
                 }
                 break;
             case 'vendor':
                 $this->currVendorObject = $this->currDB->addVendorInfo($attributes);
                 break;
             case 'behavior':
                 $this->currBehavior = $this->currDB->addBehavior($attributes);
                 break;
             default:
                 $this->_throwInvalidTagException($parser, $name);
         }
     } elseif ('table' === $parentTag) {
         switch ($name) {
             case 'column':
                 $this->currColumn = $this->currTable->addColumn($attributes);
                 break;
             case 'foreign-key':
                 $this->currFK = $this->currTable->addForeignKey($attributes);
                 break;
             case 'index':
                 $this->currIndex = new Index();
                 $this->currIndex->setTable($this->currTable);
                 $this->currIndex->loadMapping($attributes);
                 break;
             case 'unique':
                 $this->currUnique = new Unique();
                 $this->currUnique->setTable($this->currTable);
                 $this->currUnique->loadMapping($attributes);
                 break;
             case 'vendor':
                 $this->currVendorObject = $this->currTable->addVendorInfo($attributes);
                 break;
             case 'id-method-parameter':
                 $this->currTable->addIdMethodParameter($attributes);
                 break;
             case 'behavior':
                 $this->currBehavior = $this->currTable->addBehavior($attributes);
                 break;
             default:
                 $this->_throwInvalidTagException($parser, $name);
         }
     } elseif ('column' === $parentTag) {
         switch ($name) {
             case 'inheritance':
                 $this->currColumn->addInheritance($attributes);
                 break;
             case 'vendor':
                 $this->currVendorObject = $this->currColumn->addVendorInfo($attributes);
                 break;
             default:
                 $this->_throwInvalidTagException($parser, $name);
         }
     } elseif ('foreign-key' === $parentTag) {
         switch ($name) {
             case 'reference':
                 $this->currFK->addReference($attributes);
                 break;
             case 'vendor':
                 $this->currVendorObject = $this->currUnique->addVendorInfo($attributes);
                 break;
             default:
                 $this->_throwInvalidTagException($parser, $name);
         }
     } elseif ('index' === $parentTag) {
         switch ($name) {
             case 'index-column':
                 $this->currIndex->addColumn($attributes);
                 break;
             case 'vendor':
                 $this->currVendorObject = $this->currIndex->addVendorInfo($attributes);
                 break;
             default:
                 $this->_throwInvalidTagException($parser, $name);
         }
     } elseif ('unique' === $parentTag) {
         switch ($name) {
             case 'unique-column':
                 $this->currUnique->addColumn($attributes);
                 break;
             case 'vendor':
                 $this->currVendorObject = $this->currUnique->addVendorInfo($attributes);
                 break;
             default:
                 $this->_throwInvalidTagException($parser, $name);
         }
     } elseif ($parentTag == 'behavior') {
         switch ($name) {
             case 'parameter':
                 $this->currBehavior->addParameter($attributes);
                 break;
             default:
                 $this->_throwInvalidTagException($parser, $name);
         }
     } elseif ('vendor' === $parentTag) {
         switch ($name) {
             case 'parameter':
                 $this->currVendorObject->setParameter($attributes['name'], $attributes['value']);
                 break;
             default:
                 $this->_throwInvalidTagException($parser, $name);
         }
     } else {
         // it must be an invalid tag
         $this->_throwInvalidTagException($parser, $name);
     }
     $this->pushCurrentSchemaTag($name);
 }
Exemplo n.º 8
0
 /**
  * Sets an associated VendorInfo object.
  *
  * @param      mixed $data VendorInfo object or XML attrib data (array)
  * @return     VendorInfo
  */
 public function addVendorInfo($data)
 {
     if ($data instanceof VendorInfo) {
         $vi = $data;
         $this->vendorInfos[$vi->getType()] = $vi;
         return $vi;
     } else {
         $vi = new VendorInfo();
         $vi->loadFromXML($data);
         return $this->addVendorInfo($vi);
         // call self w/ different param
     }
 }