Initial entry of Doctrine_Resource and other fixes.
This commit is contained in:
parent
f4eeb641c0
commit
35ef784eaa
18 changed files with 1221 additions and 569 deletions
|
@ -37,36 +37,7 @@
|
|||
* @author Nicolas Bérard-Nault <nicobn@gmail.com>
|
||||
*/
|
||||
class Doctrine_Export_Schema
|
||||
{
|
||||
/**
|
||||
* build
|
||||
*
|
||||
* Build the schema string to be dumped to file
|
||||
*
|
||||
* @param string $array
|
||||
* @return void
|
||||
*/
|
||||
public function build($array)
|
||||
{
|
||||
throw new Doctrine_Export_Exception('This functionality is implemented by the driver');
|
||||
}
|
||||
|
||||
/**
|
||||
* dump
|
||||
*
|
||||
* Dump the array to the schema file
|
||||
*
|
||||
* @param string $array
|
||||
* @param string $schema
|
||||
* @return void
|
||||
*/
|
||||
public function dump($array, $schema)
|
||||
{
|
||||
$data = $this->build($array);
|
||||
|
||||
file_put_contents($schema, $data);
|
||||
}
|
||||
|
||||
{
|
||||
/**
|
||||
* buildSchema
|
||||
*
|
||||
|
@ -171,11 +142,8 @@ class Doctrine_Export_Schema
|
|||
*/
|
||||
public function exportSchema($schema, $format, $directory, $models = array())
|
||||
{
|
||||
$className = 'Doctrine_Export_Schema_'.ucwords($format);
|
||||
$array = $this->buildSchema($directory, $models);
|
||||
|
||||
$export = new $className();
|
||||
$array = $export->buildSchema($directory, $models);
|
||||
|
||||
return $export->dump($array, $schema);
|
||||
Doctrine_Parser::dump($array, $format, $schema);
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: Xml.php 1838 2007-06-26 00:58:21Z nicobn $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.phpdoctrine.com>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* class Doctrine_Export_Schema_Xml
|
||||
*
|
||||
* @package Doctrine
|
||||
* @category Object Relational Mapping
|
||||
* @link www.phpdoctrine.com
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @version $Revision: 1838 $
|
||||
* @author Nicolas Bérard-Nault <nicobn@gmail.com>
|
||||
*/
|
||||
class Doctrine_Export_Schema_Xml extends Doctrine_Export_Schema
|
||||
{
|
||||
/**
|
||||
* build
|
||||
*
|
||||
* Build the schema xml string to be dumped to file
|
||||
*
|
||||
* @param string $array
|
||||
* @return void
|
||||
*/
|
||||
public function build($array)
|
||||
{
|
||||
return Doctrine_Parser::dump($array, 'yml');
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: Yml.php 1838 2007-06-26 00:58:21Z nicobn $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.phpdoctrine.com>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* class Doctrine_Export_Schema_Yml
|
||||
*
|
||||
* @package Doctrine
|
||||
* @category Object Relational Mapping
|
||||
* @link www.phpdoctrine.com
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @version $Revision: 1838 $
|
||||
* @author Nicolas Bérard-Nault <nicobn@gmail.com>
|
||||
*/
|
||||
class Doctrine_Export_Schema_Yml extends Doctrine_Export_Schema
|
||||
{
|
||||
/**
|
||||
* build
|
||||
*
|
||||
* Build the schema yml string to be dumped to file
|
||||
*
|
||||
* @param string $array
|
||||
* @return void
|
||||
*/
|
||||
public function build($array)
|
||||
{
|
||||
return Doctrine_Parser::dump($array, 'yml');
|
||||
}
|
||||
}
|
|
@ -41,34 +41,7 @@ class Doctrine_Import_Schema
|
|||
{
|
||||
public $relations = array();
|
||||
|
||||
/**
|
||||
* Parse the schema and return it in an array
|
||||
*
|
||||
* @param string $schema
|
||||
* @access public
|
||||
*/
|
||||
public function parseSchema($schema)
|
||||
{
|
||||
throw new Doctrine_Import_Exception('This functionality is implemented by the driver');
|
||||
}
|
||||
|
||||
/**
|
||||
* parse
|
||||
*
|
||||
* Function to do the actual parsing of the file
|
||||
*
|
||||
* @param string $schema
|
||||
* @return void
|
||||
* @author Jonathan H. Wage
|
||||
*/
|
||||
public function parse($schema)
|
||||
{
|
||||
$class = get_class($this);
|
||||
$type = strtolower(str_replace('Doctrine_Import_Schema_', '', $class));
|
||||
|
||||
return Doctrine_Parser::load($schema, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* importSchema
|
||||
*
|
||||
|
@ -82,19 +55,15 @@ class Doctrine_Import_Schema
|
|||
*/
|
||||
public function importSchema($schema, $format, $directory, $models = array())
|
||||
{
|
||||
$className = 'Doctrine_Import_Schema_'.ucwords($format);
|
||||
|
||||
$import = new $className();
|
||||
|
||||
$builder = new Doctrine_Import_Builder();
|
||||
$builder->setTargetPath($directory);
|
||||
|
||||
$array = array();
|
||||
foreach ((array) $schema AS $s) {
|
||||
$array = array_merge($array, $import->parseSchema($s));
|
||||
$array = array_merge($array, $this->parseSchema($s, $format));
|
||||
}
|
||||
|
||||
$import->buildRelationships($array);
|
||||
$this->buildRelationships($array);
|
||||
|
||||
foreach ($array as $name => $properties) {
|
||||
if (!empty($models) && !in_array($properties['className'], $models)) {
|
||||
|
@ -107,11 +76,59 @@ class Doctrine_Import_Schema
|
|||
|
||||
$columns = $properties['columns'];
|
||||
|
||||
$relations = isset($import->relations[$options['className']]) ? $import->relations[$options['className']]:array();
|
||||
$relations = isset($this->relations[$options['className']]) ? $this->relations[$options['className']]:array();
|
||||
|
||||
$builder->buildRecord($options, $columns, $relations);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* parseSchema
|
||||
*
|
||||
* A method to parse a Yml Schema and translate it into a property array.
|
||||
* The function returns that property array.
|
||||
*
|
||||
* @param string $schema Path to the file containing the XML schema
|
||||
* @return array
|
||||
*/
|
||||
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;
|
||||
$tableName = isset($table['tableName']) ? (string) $table['tableName']:(string) $className;
|
||||
|
||||
foreach ($table['columns'] as $columnName => $field) {
|
||||
|
||||
$colDesc = array();
|
||||
$colDesc['name'] = isset($field['name']) ? (string) $field['name']:$columnName;
|
||||
$colDesc['type'] = isset($field['type']) ? (string) $field['type']:null;
|
||||
$colDesc['ptype'] = isset($field['ptype']) ? (string) $field['ptype']:(string) $colDesc['type'];
|
||||
$colDesc['length'] = isset($field['length']) ? (int) $field['length']:null;
|
||||
$colDesc['fixed'] = isset($field['fixed']) ? (int) $field['fixed']:null;
|
||||
$colDesc['unsigned'] = isset($field['unsigned']) ? (bool) $field['unsigned']:null;
|
||||
$colDesc['primary'] = isset($field['primary']) ? (bool) (isset($field['primary']) && $field['primary']):null;
|
||||
$colDesc['default'] = isset($field['default']) ? (string) $field['default']:null;
|
||||
$colDesc['notnull'] = isset($field['notnull']) ? (bool) (isset($field['notnull']) && $field['notnull']):null;
|
||||
$colDesc['autoinc'] = isset($field['autoinc']) ? (bool) (isset($field['autoinc']) && $field['autoinc']):null;
|
||||
|
||||
$columns[(string) $colDesc['name']] = $colDesc;
|
||||
}
|
||||
|
||||
$build[$className]['tableName'] = $tableName;
|
||||
$build[$className]['className'] = $className;
|
||||
|
||||
$build[$className]['columns'] = $columns;
|
||||
$build[$className]['relations'] = isset($table['relations']) ? $table['relations']:array();
|
||||
}
|
||||
|
||||
return $build;
|
||||
}
|
||||
|
||||
public function buildRelationships($array)
|
||||
{
|
||||
|
|
|
@ -1,86 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: Xml.php 1838 2007-06-26 00:58:21Z nicobn $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.phpdoctrine.com>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* class Doctrine_Import_Xml
|
||||
*
|
||||
* Different methods to import a XML schema. The logic behind using two different
|
||||
* methods is simple. Some people will like the idea of producing Doctrine_Record
|
||||
* objects directly, which is totally fine. But in fast and growing application,
|
||||
* table definitions tend to be a little bit more volatile. importArr() can be used
|
||||
* to output a table definition in a PHP file. This file can then be stored
|
||||
* independantly from the object itself.
|
||||
*
|
||||
* @package Doctrine
|
||||
* @category Object Relational Mapping
|
||||
* @link www.phpdoctrine.com
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @version $Revision: 1838 $
|
||||
* @author Nicolas Bérard-Nault <nicobn@gmail.com>
|
||||
* @author Jonathan H. Wage <jonwage@gmail.com>
|
||||
*/
|
||||
class Doctrine_Import_Schema_Xml extends Doctrine_Import_Schema
|
||||
{
|
||||
/**
|
||||
* parseSchema
|
||||
*
|
||||
* A method to parse a XML Schema and translate it into a property array.
|
||||
* The function returns that property array.
|
||||
*
|
||||
* @param string $schema Path to the file containing the XML schema
|
||||
* @return array
|
||||
*/
|
||||
public function parseSchema($schema)
|
||||
{
|
||||
$xmlObj = $this->parse($schema);
|
||||
|
||||
foreach ($xmlObj->tables as $table) {
|
||||
$columns = array();
|
||||
|
||||
// Go through all columns...
|
||||
foreach ($table->columns as $column) {
|
||||
$colDesc = array(
|
||||
'name' => (string) $column->name,
|
||||
'type' => (string) $column->type,
|
||||
'ptype' => (string) $column->type,
|
||||
'length' => (int) $column->length,
|
||||
'fixed' => (int) $column->fixed,
|
||||
'unsigned' => (bool) $column->unsigned,
|
||||
'primary' => (bool) (isset($column->primary) && $column->primary),
|
||||
'default' => (string) $column->default,
|
||||
'notnull' => (bool) (isset($column->notnull) && $column->notnull),
|
||||
'autoinc' => (bool) (isset($column->autoincrement) && $column->autoincrement),
|
||||
);
|
||||
|
||||
$columns[(string) $column->name] = $colDesc;
|
||||
}
|
||||
|
||||
$class = $table->class ? (string) $table->class:(string) $table->name;
|
||||
|
||||
$tables[(string) $table->name]['name'] = (string) $table->name;
|
||||
$tables[(string) $table->name]['class'] = (string) $class;
|
||||
|
||||
$tables[(string) $table->name]['columns'] = $columns;
|
||||
}
|
||||
|
||||
return $tables;
|
||||
}
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id: Yml.php 1838 2007-06-26 00:58:21Z nicobn $
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.phpdoctrine.com>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* class Doctrine_Import_Schema_Yml
|
||||
*
|
||||
* Different methods to import a YML schema. The logic behind using two different
|
||||
* methods is simple. Some people will like the idea of producing Doctrine_Record
|
||||
* objects directly, which is totally fine. But in fast and growing application,
|
||||
* table definitions tend to be a little bit more volatile. importArr() can be used
|
||||
* to output a table definition in a PHP file. This file can then be stored
|
||||
* independantly from the object itself.
|
||||
*
|
||||
* @package Doctrine
|
||||
* @category Object Relational Mapping
|
||||
* @link www.phpdoctrine.com
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @version $Revision: 1838 $
|
||||
* @author Nicolas Bérard-Nault <nicobn@gmail.com>
|
||||
* @author Jonathan H. Wage <jonwage@gmail.com>
|
||||
*/
|
||||
class Doctrine_Import_Schema_Yml extends Doctrine_Import_Schema
|
||||
{
|
||||
/**
|
||||
* parseSchema
|
||||
*
|
||||
* A method to parse a Yml Schema and translate it into a property array.
|
||||
* The function returns that property array.
|
||||
*
|
||||
* @param string $schema Path to the file containing the XML schema
|
||||
* @return array
|
||||
*/
|
||||
public function parseSchema($schema)
|
||||
{
|
||||
$array = $this->parse($schema);
|
||||
|
||||
foreach ($array as $className => $table) {
|
||||
$columns = array();
|
||||
|
||||
$className = isset($table['className']) ? (string) $table['className']:(string) $className;
|
||||
$tableName = isset($table['tableName']) ? (string) $table['tableName']:(string) $className;
|
||||
|
||||
foreach ($table['columns'] as $columnName => $field) {
|
||||
|
||||
$colDesc = array();
|
||||
$colDesc['name'] = isset($field['name']) ? (string) $field['name']:$columnName;
|
||||
$colDesc['type'] = isset($field['type']) ? (string) $field['type']:null;
|
||||
$colDesc['ptype'] = isset($field['ptype']) ? (string) $field['ptype']:(string) $colDesc['type'];
|
||||
$colDesc['length'] = isset($field['length']) ? (int) $field['length']:null;
|
||||
$colDesc['fixed'] = isset($field['fixed']) ? (int) $field['fixed']:null;
|
||||
$colDesc['unsigned'] = isset($field['unsigned']) ? (bool) $field['unsigned']:null;
|
||||
$colDesc['primary'] = isset($field['primary']) ? (bool) (isset($field['primary']) && $field['primary']):null;
|
||||
$colDesc['default'] = isset($field['default']) ? (string) $field['default']:null;
|
||||
$colDesc['notnull'] = isset($field['notnull']) ? (bool) (isset($field['notnull']) && $field['notnull']):null;
|
||||
$colDesc['autoinc'] = isset($field['autoinc']) ? (bool) (isset($field['autoinc']) && $field['autoinc']):null;
|
||||
|
||||
$columns[(string) $colDesc['name']] = $colDesc;
|
||||
}
|
||||
|
||||
$tables[$className]['tableName'] = $tableName;
|
||||
$tables[$className]['className'] = $className;
|
||||
|
||||
$tables[$className]['columns'] = $columns;
|
||||
$tables[$className]['relations'] = isset($table['relations']) ? $table['relations']:array();
|
||||
}
|
||||
|
||||
return $tables;
|
||||
}
|
||||
}
|
|
@ -67,18 +67,48 @@ class Doctrine_Parser_Xml extends Doctrine_Parser
|
|||
|
||||
public function loadData($path)
|
||||
{
|
||||
if ( !file_exists($path) OR !is_writeable($path) ) {
|
||||
throw new Doctrine_Parser_Exception('Xml file '. $path .' could not be read');
|
||||
}
|
||||
|
||||
if ( ! ($xmlString = file_get_contents($path))) {
|
||||
throw new Doctrine_Parser_Exception('Xml file '. $path . ' is empty');
|
||||
}
|
||||
|
||||
if (!file_exists($path) OR !is_readable($path) OR !($xmlString = file_get_contents($path))) {
|
||||
if (file_exists($path) && is_readable($path)) {
|
||||
$xmlString = file_get_contents($path);
|
||||
} else {
|
||||
$xmlString = $path;
|
||||
}
|
||||
|
||||
return simplexml_load_string($xmlString);
|
||||
$simpleXml = simplexml_load_string($xmlString);
|
||||
|
||||
return $this->prepareData($simpleXml);
|
||||
}
|
||||
|
||||
public function prepareData($simpleXml)
|
||||
{
|
||||
if ($simpleXml instanceof SimpleXMLElement) {
|
||||
$children = $simpleXml->children();
|
||||
$return = null;
|
||||
}
|
||||
|
||||
foreach ($children as $element => $value) {
|
||||
if ($value instanceof SimpleXMLElement) {
|
||||
$values = (array)$value->children();
|
||||
|
||||
if (count($values) > 0) {
|
||||
$return[$element] = $this->prepareData($value);
|
||||
} else {
|
||||
if (!isset($return[$element])) {
|
||||
$return[$element] = (string)$value;
|
||||
} else {
|
||||
if (!is_array($return[$element])) {
|
||||
$return[$element] = array($return[$element], (string)$value);
|
||||
} else {
|
||||
$return[$element][] = (string)$value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($return)) {
|
||||
return $return;
|
||||
} else {
|
||||
return $false;
|
||||
}
|
||||
}
|
||||
}
|
5
lib/Doctrine/Resource.php
Normal file
5
lib/Doctrine/Resource.php
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
class Doctrine_Resource
|
||||
{
|
||||
|
||||
}
|
367
lib/Doctrine/Resource/Client.php
Normal file
367
lib/Doctrine/Resource/Client.php
Normal file
|
@ -0,0 +1,367 @@
|
|||
<?php
|
||||
class Doctrine_Resource_Client extends Doctrine_Resource
|
||||
{
|
||||
public $parts = array();
|
||||
public $resourceUrl;
|
||||
public $format = 'xml';
|
||||
|
||||
public function __construct($resourceUrl)
|
||||
{
|
||||
$this->resourceUrl = $resourceUrl;
|
||||
}
|
||||
|
||||
public function execute($dql = null)
|
||||
{
|
||||
$request = array();
|
||||
|
||||
if ($dql === null) {
|
||||
$request['parts'] = $this->parts;
|
||||
} else {
|
||||
$request['dql'] = $dql;
|
||||
}
|
||||
|
||||
$request['format'] = $this->format;
|
||||
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $this->resourceUrl);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
|
||||
$data = curl_exec($ch);
|
||||
|
||||
return Doctrine_Parser::load($data, $this->format);
|
||||
}
|
||||
|
||||
public function setFormat($format)
|
||||
{
|
||||
$this->format = $format;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* addSelect
|
||||
* adds fields to the SELECT part of the query
|
||||
*
|
||||
* @param string $select Query SELECT part
|
||||
* @return Doctrine_Query
|
||||
*/
|
||||
public function addSelect($select)
|
||||
{
|
||||
return $this->parseQueryPart('select', $select, true);
|
||||
}
|
||||
/**
|
||||
* addFrom
|
||||
* adds fields to the FROM part of the query
|
||||
*
|
||||
* @param string $from Query FROM part
|
||||
* @return Doctrine_Query
|
||||
*/
|
||||
public function addFrom($from)
|
||||
{
|
||||
return $this->parseQueryPart('from', $from, true);
|
||||
}
|
||||
/**
|
||||
* addWhere
|
||||
* adds conditions to the WHERE part of the query
|
||||
*
|
||||
* @param string $where Query WHERE part
|
||||
* @param mixed $params an array of parameters or a simple scalar
|
||||
* @return Doctrine_Query
|
||||
*/
|
||||
public function addWhere($where, $params = array())
|
||||
{
|
||||
if (is_array($params)) {
|
||||
$this->_params['where'] = array_merge($this->_params['where'], $params);
|
||||
} else {
|
||||
$this->_params['where'][] = $params;
|
||||
}
|
||||
return $this->parseQueryPart('where', $where, true);
|
||||
}
|
||||
/**
|
||||
* whereIn
|
||||
* adds IN condition to the query WHERE part
|
||||
*
|
||||
* @param string $expr
|
||||
* @param mixed $params an array of parameters or a simple scalar
|
||||
* @return Doctrine_Query
|
||||
*/
|
||||
public function whereIn($expr, $params = array())
|
||||
{
|
||||
$params = (array) $params;
|
||||
$a = array();
|
||||
foreach ($params as $k => $value) {
|
||||
if ($value instanceof Doctrine_Expression) {
|
||||
$value = $value->getSql();
|
||||
unset($params[$k]);
|
||||
} else {
|
||||
$value = '?';
|
||||
}
|
||||
$a[] = $value;
|
||||
}
|
||||
|
||||
$this->_params['where'] = array_merge($this->_params['where'], $params);
|
||||
|
||||
$where = $expr . ' IN (' . implode(', ', $a) . ')';
|
||||
|
||||
return $this->parseQueryPart('where', $where, true);
|
||||
}
|
||||
/**
|
||||
* addGroupBy
|
||||
* adds fields to the GROUP BY part of the query
|
||||
*
|
||||
* @param string $groupby Query GROUP BY part
|
||||
* @return Doctrine_Query
|
||||
*/
|
||||
public function addGroupBy($groupby)
|
||||
{
|
||||
return $this->parseQueryPart('groupby', $groupby, true);
|
||||
}
|
||||
/**
|
||||
* addHaving
|
||||
* adds conditions to the HAVING part of the query
|
||||
*
|
||||
* @param string $having Query HAVING part
|
||||
* @param mixed $params an array of parameters or a simple scalar
|
||||
* @return Doctrine_Query
|
||||
*/
|
||||
public function addHaving($having, $params = array())
|
||||
{
|
||||
if (is_array($params)) {
|
||||
$this->_params['having'] = array_merge($this->_params['having'], $params);
|
||||
} else {
|
||||
$this->_params['having'][] = $params;
|
||||
}
|
||||
return $this->parseQueryPart('having', $having, true);
|
||||
}
|
||||
/**
|
||||
* addOrderBy
|
||||
* adds fields to the ORDER BY part of the query
|
||||
*
|
||||
* @param string $orderby Query ORDER BY part
|
||||
* @return Doctrine_Query
|
||||
*/
|
||||
public function addOrderBy($orderby)
|
||||
{
|
||||
return $this->parseQueryPart('orderby', $orderby, true);
|
||||
}
|
||||
/**
|
||||
* select
|
||||
* sets the SELECT part of the query
|
||||
*
|
||||
* @param string $select Query SELECT part
|
||||
* @return Doctrine_Query
|
||||
*/
|
||||
public function select($select)
|
||||
{
|
||||
return $this->parseQueryPart('select', $select);
|
||||
}
|
||||
/**
|
||||
* distinct
|
||||
* Makes the query SELECT DISTINCT.
|
||||
*
|
||||
* @param bool $flag Whether or not the SELECT is DISTINCT (default true).
|
||||
* @return Doctrine_Query
|
||||
*/
|
||||
public function distinct($flag = true)
|
||||
{
|
||||
$this->parts['distinct'] = (bool) $flag;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* forUpdate
|
||||
* Makes the query SELECT FOR UPDATE.
|
||||
*
|
||||
* @param bool $flag Whether or not the SELECT is FOR UPDATE (default true).
|
||||
* @return Doctrine_Query
|
||||
*/
|
||||
public function forUpdate($flag = true)
|
||||
{
|
||||
$this->parts[self::FOR_UPDATE] = (bool) $flag;
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* delete
|
||||
* sets the query type to DELETE
|
||||
*
|
||||
* @return Doctrine_Query
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$this->type = self::DELETE;
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* update
|
||||
* sets the UPDATE part of the query
|
||||
*
|
||||
* @param string $update Query UPDATE part
|
||||
* @return Doctrine_Query
|
||||
*/
|
||||
public function update($update)
|
||||
{
|
||||
$this->type = self::UPDATE;
|
||||
|
||||
return $this->parseQueryPart('from', $update);
|
||||
}
|
||||
/**
|
||||
* set
|
||||
* sets the SET part of the query
|
||||
*
|
||||
* @param string $update Query UPDATE part
|
||||
* @return Doctrine_Query
|
||||
*/
|
||||
public function set($key, $value, $params = null)
|
||||
{
|
||||
if (is_array($key)) {
|
||||
foreach ($key as $k => $v) {
|
||||
$this->set($k, '?', array($v));
|
||||
}
|
||||
} else {
|
||||
if ($params !== null) {
|
||||
if (is_array($params)) {
|
||||
$this->_params['set'] = array_merge($this->_params['set'], $params);
|
||||
} else {
|
||||
$this->_params['set'][] = $params;
|
||||
}
|
||||
}
|
||||
return $this->parseQueryPart('set', $key . ' = ' . $value, true);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* from
|
||||
* sets the FROM part of the query
|
||||
*
|
||||
* @param string $from Query FROM part
|
||||
* @return Doctrine_Query
|
||||
*/
|
||||
public function from($from)
|
||||
{
|
||||
return $this->parseQueryPart('from', $from);
|
||||
}
|
||||
/**
|
||||
* innerJoin
|
||||
* appends an INNER JOIN to the FROM part of the query
|
||||
*
|
||||
* @param string $join Query INNER JOIN
|
||||
* @return Doctrine_Query
|
||||
*/
|
||||
public function innerJoin($join)
|
||||
{
|
||||
return $this->parseQueryPart('from', 'INNER JOIN ' . $join, true);
|
||||
}
|
||||
/**
|
||||
* leftJoin
|
||||
* appends a LEFT JOIN to the FROM part of the query
|
||||
*
|
||||
* @param string $join Query LEFT JOIN
|
||||
* @return Doctrine_Query
|
||||
*/
|
||||
public function leftJoin($join)
|
||||
{
|
||||
return $this->parseQueryPart('from', 'LEFT JOIN ' . $join, true);
|
||||
}
|
||||
/**
|
||||
* groupBy
|
||||
* sets the GROUP BY part of the query
|
||||
*
|
||||
* @param string $groupby Query GROUP BY part
|
||||
* @return Doctrine_Query
|
||||
*/
|
||||
public function groupBy($groupby)
|
||||
{
|
||||
return $this->parseQueryPart('groupby', $groupby);
|
||||
}
|
||||
/**
|
||||
* where
|
||||
* sets the WHERE part of the query
|
||||
*
|
||||
* @param string $join Query WHERE part
|
||||
* @param mixed $params an array of parameters or a simple scalar
|
||||
* @return Doctrine_Query
|
||||
*/
|
||||
public function where($where, $params = array())
|
||||
{
|
||||
$this->_params['where'] = array();
|
||||
if (is_array($params)) {
|
||||
$this->_params['where'] = $params;
|
||||
} else {
|
||||
$this->_params['where'][] = $params;
|
||||
}
|
||||
|
||||
return $this->parseQueryPart('where', $where);
|
||||
}
|
||||
/**
|
||||
* having
|
||||
* sets the HAVING part of the query
|
||||
*
|
||||
* @param string $having Query HAVING part
|
||||
* @param mixed $params an array of parameters or a simple scalar
|
||||
* @return Doctrine_Query
|
||||
*/
|
||||
public function having($having, $params = array())
|
||||
{
|
||||
$this->_params['having'] = array();
|
||||
if (is_array($params)) {
|
||||
$this->_params['having'] = $params;
|
||||
} else {
|
||||
$this->_params['having'][] = $params;
|
||||
}
|
||||
|
||||
return $this->parseQueryPart('having', $having);
|
||||
}
|
||||
/**
|
||||
* orderBy
|
||||
* sets the ORDER BY part of the query
|
||||
*
|
||||
* @param string $orderby Query ORDER BY part
|
||||
* @return Doctrine_Query
|
||||
*/
|
||||
public function orderBy($orderby)
|
||||
{
|
||||
return $this->parseQueryPart('orderby', $orderby);
|
||||
}
|
||||
/**
|
||||
* limit
|
||||
* sets the Query query limit
|
||||
*
|
||||
* @param integer $limit limit to be used for limiting the query results
|
||||
* @return Doctrine_Query
|
||||
*/
|
||||
public function limit($limit)
|
||||
{
|
||||
return $this->parseQueryPart('limit', $limit);
|
||||
}
|
||||
/**
|
||||
* offset
|
||||
* sets the Query query offset
|
||||
*
|
||||
* @param integer $offset offset to be used for paginating the query
|
||||
* @return Doctrine_Query
|
||||
*/
|
||||
public function offset($offset)
|
||||
{
|
||||
return $this->parseQueryPart('offset', $offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* parseQueryPart
|
||||
* parses given DQL query part
|
||||
*
|
||||
* @param string $queryPartName the name of the query part
|
||||
* @param string $queryPart query part to be parsed
|
||||
* @return Doctrine_Query this object
|
||||
*/
|
||||
public function parseQueryPart($queryPartName, $queryPart)
|
||||
{
|
||||
$this->parts[$queryPartName][] = $queryPart;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
40
lib/Doctrine/Resource/Server.php
Normal file
40
lib/Doctrine/Resource/Server.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
class Doctrine_Resource_Server extends Doctrine_Resource
|
||||
{
|
||||
public function execute($request)
|
||||
{
|
||||
if (isset($request['dql'])) {
|
||||
$query = new Doctrine_Query();
|
||||
$result = $query->query($request['dql']);
|
||||
} else {
|
||||
$result = $this->buildDql($request['parts']);
|
||||
}
|
||||
|
||||
$data = array();
|
||||
foreach ($result as $recordKey => $record) {
|
||||
$array = $record->toArray();
|
||||
|
||||
$recordKey = get_class($record). '_' .($recordKey + 1);
|
||||
|
||||
foreach ($array as $valueKey => $value) {
|
||||
$data[get_class($record)][$recordKey][$valueKey] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$format = isset($request['format']) ? $request['format']:'xml';
|
||||
|
||||
return Doctrine_Parser::dump($data, $format);
|
||||
}
|
||||
|
||||
public function buildDql($parts)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
$request = $_REQUEST;
|
||||
|
||||
echo $this->execute($request);
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.phpdoctrine.com>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Doctrine_Export_Schema_Xml_TestCase
|
||||
*
|
||||
* @package Doctrine
|
||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @category Object Relational Mapping
|
||||
* @link www.phpdoctrine.com
|
||||
* @since 1.0
|
||||
* @version $Revision$
|
||||
*/
|
||||
class Doctrine_Export_Schema_Xml_TestCase extends Doctrine_UnitTestCase
|
||||
{
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.phpdoctrine.com>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Doctrine_Export_Schema_Yml_TestCase
|
||||
*
|
||||
* @package Doctrine
|
||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @category Object Relational Mapping
|
||||
* @link www.phpdoctrine.com
|
||||
* @since 1.0
|
||||
* @version $Revision$
|
||||
*/
|
||||
class Doctrine_Export_Schema_Yml_TestCase extends Doctrine_UnitTestCase
|
||||
{
|
||||
}
|
67
tests/Export/SchemaTestCase.php
Normal file
67
tests/Export/SchemaTestCase.php
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.phpdoctrine.com>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Doctrine_Export_Schema_TestCase
|
||||
*
|
||||
* @package Doctrine
|
||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @category Object Relational Mapping
|
||||
* @link www.phpdoctrine.com
|
||||
* @since 1.0
|
||||
* @version $Revision$
|
||||
*/
|
||||
class Doctrine_Export_Schema_TestCase extends Doctrine_UnitTestCase
|
||||
{
|
||||
public $tables = array('Entity',
|
||||
'EntityReference',
|
||||
'EntityAddress',
|
||||
'Email',
|
||||
'Phonenumber',
|
||||
'Groupuser',
|
||||
'Group',
|
||||
'User',
|
||||
'Album',
|
||||
'Song',
|
||||
'Element',
|
||||
'Error',
|
||||
'Description',
|
||||
'Address',
|
||||
'Account',
|
||||
'Task',
|
||||
'Resource',
|
||||
'Assignment',
|
||||
'ResourceType',
|
||||
'ResourceReference');
|
||||
|
||||
public function testYmlExport()
|
||||
{
|
||||
$export = new Doctrine_Export_Schema();
|
||||
$export->exportSchema('schema.yml', 'yml', dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'models', $this->tables);
|
||||
}
|
||||
|
||||
public function testXmlExport()
|
||||
{
|
||||
$export = new Doctrine_Export_Schema();
|
||||
$export->exportSchema('schema.xml', 'xml', dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'models', $this->tables);
|
||||
}
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.phpdoctrine.com>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Doctrine_Import_Schema_Xml_TestCase
|
||||
*
|
||||
* @package Doctrine
|
||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @category Object Relational Mapping
|
||||
* @link www.phpdoctrine.com
|
||||
* @since 1.0
|
||||
* @version $Revision$
|
||||
*/
|
||||
class Doctrine_Import_Schema_Xml_TestCase extends Doctrine_UnitTestCase
|
||||
{
|
||||
public function testXmlImport()
|
||||
{
|
||||
$import = new Doctrine_Import_Schema_Xml();
|
||||
$import->importSchema('schema.xml', 'classes');
|
||||
|
||||
if ( ! file_exists('classes/User.class.php')) {
|
||||
$this->fail();
|
||||
} else {
|
||||
unlink('classes/User.class.php');
|
||||
}
|
||||
|
||||
if ( ! file_exists('classes/Group.class.php')) {
|
||||
$this->fail();
|
||||
} else {
|
||||
unlink('classes/Group.class.php');
|
||||
}
|
||||
}
|
||||
}
|
|
@ -20,7 +20,7 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* Doctrine_Import_Schema_Yml_TestCase
|
||||
* Doctrine_Import_Schema_TestCase
|
||||
*
|
||||
* @package Doctrine
|
||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
||||
|
@ -30,7 +30,7 @@
|
|||
* @since 1.0
|
||||
* @version $Revision$
|
||||
*/
|
||||
class Doctrine_Import_Schema_Yml_TestCase extends Doctrine_UnitTestCase
|
||||
class Doctrine_Import_Schema_TestCase extends Doctrine_UnitTestCase
|
||||
{
|
||||
public function testYmlImport()
|
||||
{
|
||||
|
@ -49,4 +49,22 @@ class Doctrine_Import_Schema_Yml_TestCase extends Doctrine_UnitTestCase
|
|||
unlink('classes/Group.class.php');
|
||||
}
|
||||
}
|
||||
|
||||
public function testXmlImport()
|
||||
{
|
||||
$import = new Doctrine_Import_Schema();
|
||||
$import->importSchema('schema.xml', 'xml', 'classes');
|
||||
|
||||
if ( ! file_exists('classes/User.class.php')) {
|
||||
$this->fail();
|
||||
} else {
|
||||
unlink('classes/User.class.php');
|
||||
}
|
||||
|
||||
if ( ! file_exists('classes/Group.class.php')) {
|
||||
$this->fail();
|
||||
} else {
|
||||
unlink('classes/Group.class.php');
|
||||
}
|
||||
}
|
||||
}
|
|
@ -79,9 +79,6 @@ foreach($models as $key => $file) {
|
|||
}
|
||||
}
|
||||
}
|
||||
//require_once dirname(__FILE__) . '/../models/location.php';
|
||||
//require_once dirname(__FILE__) . '/../models/Blog.php';
|
||||
//require_once dirname(__FILE__) . '/classes.php';
|
||||
|
||||
require_once dirname(__FILE__) . '/Test.php';
|
||||
require_once dirname(__FILE__) . '/UnitTestCase.php';
|
||||
|
@ -90,7 +87,6 @@ error_reporting(E_ALL | E_STRICT);
|
|||
|
||||
$test = new GroupTest('Doctrine Framework Unit Tests');
|
||||
|
||||
|
||||
//TICKET test cases
|
||||
$tickets = new GroupTest('Tickets tests');
|
||||
$tickets->addTestCase(new Doctrine_Ticket_Njero_TestCase());
|
||||
|
@ -306,11 +302,6 @@ $test->addTestCase(new Doctrine_RawSql_TestCase());
|
|||
|
||||
$test->addTestCase(new Doctrine_NewCore_TestCase());
|
||||
|
||||
//$test->addTestCase(new Doctrine_Import_Schema_Xml_TestCase());
|
||||
//$test->addTestCase(new Doctrine_Export_Schema_Xml_TestCase());
|
||||
$test->addTestCase(new Doctrine_Import_Schema_Yml_TestCase());
|
||||
$test->addTestCase(new Doctrine_Export_Schema_Yml_TestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_Template_TestCase());
|
||||
|
||||
//$test->addTestCase(new Doctrine_Import_Builder_TestCase());
|
||||
|
@ -339,6 +330,10 @@ $test->addTestCase(new Doctrine_Query_ApplyInheritance_TestCase());
|
|||
|
||||
$test->addTestCase(new Doctrine_Migration_TestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_Import_Schema_TestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_Export_Schema_TestCase());
|
||||
|
||||
class CliReporter extends HtmlReporter{
|
||||
public function paintHeader(){
|
||||
echo "Doctrine UnitTests\n";
|
||||
|
|
File diff suppressed because one or more lines are too long
670
tests/schema.yml
670
tests/schema.yml
|
@ -1,58 +1,630 @@
|
|||
---
|
||||
User:
|
||||
tableName: user
|
||||
className: User
|
||||
columns:
|
||||
id:
|
||||
Account:
|
||||
tableName: account
|
||||
className: Account
|
||||
columns:
|
||||
id:
|
||||
type: integer
|
||||
length: 20
|
||||
autoincrement: true
|
||||
username:
|
||||
primary: true
|
||||
name: id
|
||||
entity_id:
|
||||
type: integer
|
||||
length: 2147483647
|
||||
name: entity_id
|
||||
amount:
|
||||
type: integer
|
||||
length: 2147483647
|
||||
name: amount
|
||||
Address:
|
||||
tableName: address
|
||||
className: Address
|
||||
columns:
|
||||
id:
|
||||
type: integer
|
||||
length: 20
|
||||
autoincrement: true
|
||||
primary: true
|
||||
name: id
|
||||
address:
|
||||
type: string
|
||||
length: 200
|
||||
name: address
|
||||
relations:
|
||||
User:
|
||||
refClass: EntityAddress
|
||||
local: address_id
|
||||
foreign: user_id
|
||||
type: many
|
||||
EntityAddress:
|
||||
local: id
|
||||
foreign: address_id
|
||||
type: many
|
||||
Album:
|
||||
tableName: album
|
||||
className: Album
|
||||
columns:
|
||||
id:
|
||||
type: integer
|
||||
length: 20
|
||||
autoincrement: true
|
||||
primary: true
|
||||
name: id
|
||||
user_id:
|
||||
type: integer
|
||||
length: 2147483647
|
||||
name: user_id
|
||||
name:
|
||||
type: string
|
||||
length: 20
|
||||
name: name
|
||||
relations:
|
||||
Song:
|
||||
local: id
|
||||
foreign: album_id
|
||||
type: many
|
||||
User:
|
||||
local: user_id
|
||||
foreign: id
|
||||
type: one
|
||||
Assignment:
|
||||
tableName: assignment
|
||||
className: Assignment
|
||||
columns:
|
||||
id:
|
||||
type: integer
|
||||
length: 20
|
||||
autoincrement: true
|
||||
primary: true
|
||||
name: id
|
||||
task_id:
|
||||
type: integer
|
||||
length: 2147483647
|
||||
name: task_id
|
||||
resource_id:
|
||||
type: integer
|
||||
length: 2147483647
|
||||
name: resource_id
|
||||
Description:
|
||||
tableName: description
|
||||
className: Description
|
||||
columns:
|
||||
id:
|
||||
type: integer
|
||||
length: 20
|
||||
autoincrement: true
|
||||
primary: true
|
||||
name: id
|
||||
description:
|
||||
type: string
|
||||
length: 3000
|
||||
name: description
|
||||
file_md5:
|
||||
type: string
|
||||
length: 32
|
||||
name: file_md5
|
||||
Element:
|
||||
tableName: element
|
||||
className: Element
|
||||
columns:
|
||||
id:
|
||||
type: integer
|
||||
length: 20
|
||||
autoincrement: true
|
||||
primary: true
|
||||
name: id
|
||||
name:
|
||||
type: string
|
||||
length: 100
|
||||
name: name
|
||||
parent_id:
|
||||
type: integer
|
||||
length: 2147483647
|
||||
name: parent_id
|
||||
relations:
|
||||
Child:
|
||||
class: Element
|
||||
local: id
|
||||
foreign: parent_id
|
||||
type: many
|
||||
Parent:
|
||||
class: Element
|
||||
local: parent_id
|
||||
foreign: id
|
||||
type: one
|
||||
Email:
|
||||
tableName: email
|
||||
className: Email
|
||||
columns:
|
||||
id:
|
||||
type: integer
|
||||
length: 20
|
||||
autoincrement: true
|
||||
primary: true
|
||||
name: id
|
||||
address:
|
||||
email: true
|
||||
unique: true
|
||||
type: string
|
||||
length: 150
|
||||
name: address
|
||||
Entity:
|
||||
tableName: entity
|
||||
className: Entity
|
||||
columns:
|
||||
id:
|
||||
autoincrement: true
|
||||
primary: true
|
||||
type: integer
|
||||
length: 20
|
||||
name: id
|
||||
name:
|
||||
type: string
|
||||
length: 50
|
||||
name: name
|
||||
loginname:
|
||||
unique: true
|
||||
type: string
|
||||
length: 20
|
||||
name: loginname
|
||||
password:
|
||||
type: string
|
||||
length: 16
|
||||
name: password
|
||||
type:
|
||||
type: integer
|
||||
length: 1
|
||||
name: type
|
||||
created:
|
||||
type: integer
|
||||
length: 11
|
||||
relations:
|
||||
Groups:
|
||||
class: Group
|
||||
refClass: UserGroup
|
||||
name: created
|
||||
updated:
|
||||
type: integer
|
||||
length: 11
|
||||
name: updated
|
||||
email_id:
|
||||
type: integer
|
||||
length: 2147483647
|
||||
name: email_id
|
||||
relations:
|
||||
Email:
|
||||
local: email_id
|
||||
foreign: id
|
||||
type: one
|
||||
Phonenumber:
|
||||
local: id
|
||||
foreign: entity_id
|
||||
type: many
|
||||
Account:
|
||||
local: id
|
||||
foreign: entity_id
|
||||
type: one
|
||||
Entity:
|
||||
refClass: EntityReference
|
||||
local: entity1
|
||||
foreign: entity2
|
||||
type: many
|
||||
EntityReference:
|
||||
local: id
|
||||
foreign: entity1
|
||||
type: many
|
||||
EntityAddress:
|
||||
tableName: entity_address
|
||||
className: EntityAddress
|
||||
columns:
|
||||
user_id:
|
||||
primary: true
|
||||
type: integer
|
||||
length: 2147483647
|
||||
name: user_id
|
||||
address_id:
|
||||
primary: true
|
||||
type: integer
|
||||
length: 2147483647
|
||||
name: address_id
|
||||
relations:
|
||||
Address:
|
||||
local: address_id
|
||||
foreign: id
|
||||
type: one
|
||||
EntityReference:
|
||||
tableName: entity_reference
|
||||
className: EntityReference
|
||||
columns:
|
||||
entity1:
|
||||
primary: true
|
||||
type: integer
|
||||
length: 2147483647
|
||||
name: entity1
|
||||
entity2:
|
||||
primary: true
|
||||
type: integer
|
||||
length: 2147483647
|
||||
name: entity2
|
||||
relations:
|
||||
Entity:
|
||||
local: entity1
|
||||
foreign: id
|
||||
type: one
|
||||
Error:
|
||||
tableName: error
|
||||
className: Error
|
||||
columns:
|
||||
message:
|
||||
type: string
|
||||
length: 200
|
||||
name: message
|
||||
code:
|
||||
type: integer
|
||||
length: 11
|
||||
name: code
|
||||
file_md5:
|
||||
primary: true
|
||||
type: string
|
||||
length: 32
|
||||
name: file_md5
|
||||
relations:
|
||||
Description:
|
||||
local: file_md5
|
||||
foreign: file_md5
|
||||
type: one
|
||||
Group:
|
||||
tableName: entity
|
||||
className: Group
|
||||
columns:
|
||||
id:
|
||||
autoincrement: true
|
||||
primary: true
|
||||
type: integer
|
||||
length: 20
|
||||
name: id
|
||||
name:
|
||||
type: string
|
||||
length: 50
|
||||
name: name
|
||||
loginname:
|
||||
unique: true
|
||||
type: string
|
||||
length: 20
|
||||
name: loginname
|
||||
password:
|
||||
type: string
|
||||
length: 16
|
||||
name: password
|
||||
type:
|
||||
type: integer
|
||||
length: 1
|
||||
name: type
|
||||
created:
|
||||
type: integer
|
||||
length: 11
|
||||
name: created
|
||||
updated:
|
||||
type: integer
|
||||
length: 11
|
||||
name: updated
|
||||
email_id:
|
||||
type: integer
|
||||
length: 2147483647
|
||||
name: email_id
|
||||
relations:
|
||||
Email:
|
||||
local: email_id
|
||||
foreign: id
|
||||
type: one
|
||||
Phonenumber:
|
||||
local: id
|
||||
foreign: entity_id
|
||||
type: many
|
||||
Account:
|
||||
local: id
|
||||
foreign: entity_id
|
||||
type: one
|
||||
Entity:
|
||||
refClass: EntityReference
|
||||
local: entity1
|
||||
foreign: entity2
|
||||
type: many
|
||||
User:
|
||||
refClass: Groupuser
|
||||
local: group_id
|
||||
foreign: user_id
|
||||
type: many
|
||||
EntityReference:
|
||||
local: id
|
||||
foreign: entity1
|
||||
type: many
|
||||
Groupuser:
|
||||
local: id
|
||||
foreign: group_id
|
||||
type: many
|
||||
Groupuser:
|
||||
tableName: groupuser
|
||||
className: Groupuser
|
||||
columns:
|
||||
id:
|
||||
type: integer
|
||||
length: 20
|
||||
autoincrement: true
|
||||
primary: true
|
||||
name: id
|
||||
added:
|
||||
type: integer
|
||||
length: 2147483647
|
||||
name: added
|
||||
group_id:
|
||||
type: integer
|
||||
length: 2147483647
|
||||
name: group_id
|
||||
user_id:
|
||||
type: integer
|
||||
length: 2147483647
|
||||
name: user_id
|
||||
relations:
|
||||
Group:
|
||||
local: group_id
|
||||
foreign: id
|
||||
type: one
|
||||
User:
|
||||
local: user_id
|
||||
foreign: id
|
||||
type: one
|
||||
Phonenumber:
|
||||
tableName: phonenumber
|
||||
className: Phonenumber
|
||||
columns:
|
||||
id:
|
||||
type: integer
|
||||
length: 20
|
||||
autoincrement: true
|
||||
primary: true
|
||||
name: id
|
||||
phonenumber:
|
||||
type: string
|
||||
length: 20
|
||||
name: phonenumber
|
||||
entity_id:
|
||||
type: integer
|
||||
length: 2147483647
|
||||
name: entity_id
|
||||
relations:
|
||||
Entity:
|
||||
local: entity_id
|
||||
foreign: id
|
||||
type: one
|
||||
Group:
|
||||
local: entity_id
|
||||
foreign: id
|
||||
type: one
|
||||
User:
|
||||
local: entity_id
|
||||
foreign: id
|
||||
type: one
|
||||
ResourceReference:
|
||||
tableName: resource_reference
|
||||
className: ResourceReference
|
||||
columns:
|
||||
id:
|
||||
type: integer
|
||||
length: 20
|
||||
autoincrement: true
|
||||
primary: true
|
||||
name: id
|
||||
type_id:
|
||||
type: integer
|
||||
length: 2147483647
|
||||
name: type_id
|
||||
resource_id:
|
||||
type: integer
|
||||
length: 2147483647
|
||||
name: resource_id
|
||||
Resource:
|
||||
tableName: resource
|
||||
className: Resource
|
||||
columns:
|
||||
id:
|
||||
type: integer
|
||||
length: 20
|
||||
autoincrement: true
|
||||
primary: true
|
||||
name: id
|
||||
name:
|
||||
type: string
|
||||
length: 100
|
||||
name: name
|
||||
relations:
|
||||
TaskAlias:
|
||||
refClass: Assignment
|
||||
class: Task
|
||||
local: resource_id
|
||||
foreign: task_id
|
||||
type: many
|
||||
Type:
|
||||
refClass: ResourceReference
|
||||
class: ResourceType
|
||||
local: resource_id
|
||||
foreign: type_id
|
||||
type: many
|
||||
Assignment:
|
||||
local: id
|
||||
foreign: resource_id
|
||||
type: many
|
||||
ResourceReference:
|
||||
local: id
|
||||
foreign: resource_id
|
||||
type: many
|
||||
ResourceType:
|
||||
tableName: resource_type
|
||||
className: ResourceType
|
||||
columns:
|
||||
id:
|
||||
type: integer
|
||||
length: 20
|
||||
autoincrement: true
|
||||
primary: true
|
||||
name: id
|
||||
type:
|
||||
type: string
|
||||
length: 100
|
||||
name: type
|
||||
relations:
|
||||
ResourceAlias:
|
||||
refClass: ResourceReference
|
||||
class: Resource
|
||||
local: resourcetype_id
|
||||
foreign: resource_id
|
||||
type: many
|
||||
ResourceReference:
|
||||
local: id
|
||||
foreign: resourcetype_id
|
||||
type: many
|
||||
Song:
|
||||
tableName: song
|
||||
className: Song
|
||||
columns:
|
||||
id:
|
||||
type: integer
|
||||
length: 20
|
||||
autoincrement: true
|
||||
primary: true
|
||||
name: id
|
||||
album_id:
|
||||
type: integer
|
||||
length: 2147483647
|
||||
name: album_id
|
||||
genre:
|
||||
type: string
|
||||
length: 20
|
||||
name: genre
|
||||
title:
|
||||
type: string
|
||||
length: 30
|
||||
name: title
|
||||
relations:
|
||||
Album:
|
||||
local: album_id
|
||||
foreign: id
|
||||
type: one
|
||||
Task:
|
||||
tableName: task
|
||||
className: Task
|
||||
columns:
|
||||
id:
|
||||
type: integer
|
||||
length: 20
|
||||
autoincrement: true
|
||||
primary: true
|
||||
name: id
|
||||
name:
|
||||
type: string
|
||||
length: 100
|
||||
name: name
|
||||
parent_id:
|
||||
type: integer
|
||||
length: 2147483647
|
||||
name: parent_id
|
||||
relations:
|
||||
ResourceAlias:
|
||||
refClass: Assignment
|
||||
class: Resource
|
||||
local: task_id
|
||||
foreign: resource_id
|
||||
type: many
|
||||
Subtask:
|
||||
class: Task
|
||||
local: id
|
||||
foreign: parent_id
|
||||
type: many
|
||||
Assignment:
|
||||
local: id
|
||||
foreign: task_id
|
||||
type: many
|
||||
User:
|
||||
tableName: entity
|
||||
className: User
|
||||
columns:
|
||||
id:
|
||||
autoincrement: true
|
||||
primary: true
|
||||
type: integer
|
||||
length: 20
|
||||
name: id
|
||||
name:
|
||||
type: string
|
||||
length: 50
|
||||
name: name
|
||||
loginname:
|
||||
unique: true
|
||||
type: string
|
||||
length: 20
|
||||
name: loginname
|
||||
password:
|
||||
type: string
|
||||
length: 16
|
||||
name: password
|
||||
type:
|
||||
type: integer
|
||||
length: 1
|
||||
name: type
|
||||
created:
|
||||
type: integer
|
||||
length: 11
|
||||
name: created
|
||||
updated:
|
||||
type: integer
|
||||
length: 11
|
||||
name: updated
|
||||
email_id:
|
||||
type: integer
|
||||
length: 2147483647
|
||||
name: email_id
|
||||
relations:
|
||||
Email:
|
||||
local: email_id
|
||||
foreign: id
|
||||
type: one
|
||||
Phonenumber:
|
||||
local: id
|
||||
foreign: entity_id
|
||||
type: many
|
||||
Account:
|
||||
local: id
|
||||
foreign: entity_id
|
||||
type: one
|
||||
Entity:
|
||||
refClass: EntityReference
|
||||
local: entity1
|
||||
foreign: entity2
|
||||
type: many
|
||||
Address:
|
||||
refClass: EntityAddress
|
||||
local: user_id
|
||||
foreign: address_id
|
||||
type: many
|
||||
Album:
|
||||
local: id
|
||||
foreign: user_id
|
||||
type: many
|
||||
Book:
|
||||
local: id
|
||||
foreign: user_id
|
||||
type: many
|
||||
Group:
|
||||
refClass: Groupuser
|
||||
local: user_id
|
||||
foreign: group_id
|
||||
type: many
|
||||
|
||||
UserGroup:
|
||||
tableName: user_group
|
||||
className: UserGroup
|
||||
columns:
|
||||
user_id:
|
||||
type: int
|
||||
length: 11
|
||||
primary: true
|
||||
group_id:
|
||||
type: int
|
||||
length: 11
|
||||
primary: true
|
||||
relations:
|
||||
User:
|
||||
foreign: id
|
||||
local: user_id
|
||||
type: one
|
||||
Group:
|
||||
foreign: id
|
||||
local: group_id
|
||||
type: one
|
||||
|
||||
Group:
|
||||
tableName: group
|
||||
className: Group
|
||||
columns:
|
||||
id:
|
||||
type: integer
|
||||
autoincrement: true
|
||||
name:
|
||||
type: string
|
||||
length: 255
|
||||
relations:
|
||||
Users:
|
||||
class: User
|
||||
refClass: UserGroup
|
||||
local: group_id
|
||||
EntityReference:
|
||||
local: id
|
||||
foreign: entity1
|
||||
type: many
|
||||
EntityAddress:
|
||||
local: id
|
||||
foreign: user_id
|
||||
type: many
|
||||
type: many
|
||||
Groupuser:
|
||||
local: id
|
||||
foreign: user_id
|
||||
type: many
|
||||
|
|
Loading…
Add table
Reference in a new issue