Exemple #1
0
 /**
  * loadData
  *
  * Load and parse data from a yml file
  * 
  * @param  string  $path  Path to load yaml data from
  * @return array   $array Array of parsed yaml data
  */
 public function loadData($path)
 {
     $contents = $this->doLoad($path);
     $spyc = new Doctrine_Parser_Spyc();
     $array = $spyc->load($contents);
     return $array;
 }
Exemple #2
0
                if ($foreignKeyChilds->item($k)->nodeType == XML_ELEMENT_NODE && $foreignKeyChilds->item($k)->nodeName == "reference") {
                    $referenceNode = $foreignKeyChilds->item($k);
                    break;
                }
            }
            if (!$referenceNode) {
                continue;
            }
            $onDelete = $tableChild->getAttribute('onDelete') == 'setnull' ? 'null' : $tableChild->getAttribute('onDelete');
            $alias = sfInflector::camelize(substr($referenceNode->getAttribute('local'), 0, -3));
            // local = "id", so $alias = "". We need set $alias to $foreignClass
            if ($alias == "") {
                $alias = $foreignClass;
            }
            $doctrineSchema[$class]['relations'][$alias] = array('class' => $foreignClass, 'foreign' => $referenceNode->getAttribute('foreign'), 'foreignAlias' => $class . 's', 'alias' => $alias, 'local' => $referenceNode->getAttribute('local'), 'onDelete' => $onDelete);
        } elseif ($nodeName == "unique") {
            $indexName = $tableChild->getAttribute('name');
            $foreignKeyChilds = $tableChild->childNodes;
            $fields = array();
            for ($k = 0; $k < $foreignKeyChilds->length; $k++) {
                if ($foreignKeyChilds->item($k)->nodeType == XML_ELEMENT_NODE && $foreignKeyChilds->item($k)->nodeName == "unique-column") {
                    $fields[] = $foreignKeyChilds->item($k)->getAttribute('name');
                }
            }
            $doctrineSchema[$class]['indexes'][$indexName] = array('fields' => $fields, 'type' => 'unique');
        }
    }
}
// Dump data. Dont use sfYaml::dump (syck_dump has problem)
$yamlDumper = new Doctrine_Parser_Spyc();
file_put_contents($doctrineSchemaFile, $yamlDumper->dump($doctrineSchema, 2, 0));