/** * getValidators * * Retrieve the array of available validators * * @return array */ public function getValidators() { if (empty($this->_validators)) { $this->_validators = Doctrine_Lib::getValidators(); } return $this->_validators; }
/** * parseSchema * * A method to parse a Schema and translate it into a property array. * The function returns that property array. * * @param string $schema Path to the file containing the schema * @return array $build Built array of schema information */ public function parseSchema($schema, $type) { $array = Doctrine_Parser::load($schema, $type); $build = array(); foreach ($array as $className => $table) { $columns = array(); $className = isset($table['className']) ? (string) $table['className'] : (string) $className; if (isset($table['tableName']) && $table['tableName']) { $tableName = $table['tableName']; } else { if (isset($table['inheritance']['extends']) && isset($table['inheritance']['extends']['keyType']) && isset($table['inheritance']['extends']['keyValue'])) { $tableName = null; } else { $tableName = Doctrine::tableize($className); } } $columns = isset($table['columns']) ? $table['columns'] : array(); $columns = isset($table['fields']) ? $table['fields'] : $columns; if (!empty($columns)) { foreach ($columns as $columnName => $field) { $colDesc = array(); $colDesc['name'] = $columnName; $e = explode('(', $field['type']); if (isset($e[0]) && isset($e[1])) { $colDesc['type'] = $e[0]; $colDesc['length'] = substr($e[1], 0, strlen($e[1]) - 1); } else { $colDesc['type'] = isset($field['type']) ? (string) $field['type'] : null; $colDesc['length'] = isset($field['length']) ? (int) $field['length'] : null; $colDesc['length'] = isset($field['size']) ? (int) $field['size'] : $colDesc['length']; } $colDesc['ptype'] = isset($field['ptype']) ? (string) $field['ptype'] : (string) $colDesc['type']; $colDesc['fixed'] = isset($field['fixed']) ? (int) $field['fixed'] : null; $colDesc['primary'] = isset($field['primary']) ? (bool) (isset($field['primary']) && $field['primary']) : null; $colDesc['default'] = isset($field['default']) ? $field['default'] : null; $colDesc['autoincrement'] = isset($field['autoincrement']) ? (bool) (isset($field['autoincrement']) && $field['autoincrement']) : null; $colDesc['autoincrement'] = isset($field['autoinc']) ? (bool) (isset($field['autoinc']) && $field['autoinc']) : $colDesc['autoincrement']; $colDesc['sequence'] = isset($field['sequence']) ? (string) $field['sequence'] : null; $colDesc['values'] = isset($field['values']) ? (array) $field['values'] : null; $validators = Doctrine_Lib::getValidators(); foreach ($validators as $validator) { if (isset($field[$validator])) { $colDesc[$validator] = $field[$validator]; } } $columns[(string) $colDesc['name']] = $colDesc; } } $build[$className]['connection'] = isset($table['connection']) ? $table['connection'] : null; $build[$className]['className'] = $className; $build[$className]['tableName'] = $tableName; $build[$className]['columns'] = $columns; $build[$className]['relations'] = isset($table['relations']) ? $table['relations'] : array(); $build[$className]['indexes'] = isset($table['indexes']) ? $table['indexes'] : array(); $build[$className]['attributes'] = isset($table['attributes']) ? $table['attributes'] : array(); $build[$className]['templates'] = isset($table['templates']) ? $table['templates'] : array(); $build[$className]['actAs'] = isset($table['actAs']) ? $table['actAs'] : array(); $build[$className]['options'] = isset($table['options']) ? $table['options'] : array(); $build[$className]['package'] = isset($table['package']) ? $table['package'] : null; if (isset($table['inheritance'])) { $build[$className]['inheritance'] = $table['inheritance']; } } return $build; }