Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
779003ed
Commit
779003ed
authored
Oct 19, 2007
by
Jonathan.Wage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed Facade and moved all static methods to Doctrine class.
parent
dfdcf002
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
380 additions
and
464 deletions
+380
-464
Doctrine.php
lib/Doctrine.php
+370
-27
Facade.php
lib/Doctrine/Facade.php
+0
-427
Compile.php
lib/Doctrine/Task/Compile.php
+1
-1
CreateDb.php
lib/Doctrine/Task/CreateDb.php
+1
-1
CreateTables.php
lib/Doctrine/Task/CreateTables.php
+1
-1
DropDb.php
lib/Doctrine/Task/DropDb.php
+1
-1
DumpData.php
lib/Doctrine/Task/DumpData.php
+2
-2
GenerateMigration.php
lib/Doctrine/Task/GenerateMigration.php
+1
-1
GenerateModelsFromDb.php
lib/Doctrine/Task/GenerateModelsFromDb.php
+1
-1
GenerateModelsFromYaml.php
lib/Doctrine/Task/GenerateModelsFromYaml.php
+1
-1
GenerateSql.php
lib/Doctrine/Task/GenerateSql.php
+1
-1
No files found.
lib/Doctrine.php
View file @
779003ed
...
...
@@ -254,51 +254,51 @@ final class Doctrine
/**
* Portability: turn off all portability features.
* @see
Doctrine
::ATTR_PORTABILITY
* @see
self
::ATTR_PORTABILITY
*/
const
PORTABILITY_NONE
=
0
;
/**
* Portability: convert names of tables and fields to case defined in the
* "field_case" option when using the query*(), fetch*() methods.
* @see
Doctrine
::ATTR_PORTABILITY
* @see
self
::ATTR_PORTABILITY
*/
const
PORTABILITY_FIX_CASE
=
1
;
/**
* Portability: right trim the data output by query*() and fetch*().
* @see
Doctrine
::ATTR_PORTABILITY
* @see
self
::ATTR_PORTABILITY
*/
const
PORTABILITY_RTRIM
=
2
;
/**
* Portability: force reporting the number of rows deleted.
* @see
Doctrine
::ATTR_PORTABILITY
* @see
self
::ATTR_PORTABILITY
*/
const
PORTABILITY_DELETE_COUNT
=
4
;
/**
* Portability: convert empty values to null strings in data output by
* query*() and fetch*().
* @see
Doctrine
::ATTR_PORTABILITY
* @see
self
::ATTR_PORTABILITY
*/
const
PORTABILITY_EMPTY_TO_NULL
=
8
;
/**
* Portability: removes database/table qualifiers from associative indexes
* @see
Doctrine
::ATTR_PORTABILITY
* @see
self
::ATTR_PORTABILITY
*/
const
PORTABILITY_FIX_ASSOC_FIELD_NAMES
=
16
;
/**
* Portability: makes Doctrine_Expression throw exception for unportable RDBMS expressions
* @see
Doctrine
::ATTR_PORTABILITY
* @see
self
::ATTR_PORTABILITY
*/
const
PORTABILITY_EXPR
=
32
;
/**
* Portability: turn on all portability features.
* @see
Doctrine
::ATTR_PORTABILITY
* @see
self
::ATTR_PORTABILITY
*/
const
PORTABILITY_ALL
=
63
;
...
...
@@ -444,7 +444,59 @@ final class Doctrine
*/
public
static
function
loadAll
()
{
return
Doctrine_Facade
::
loadAllRuntimeClasses
();
return
self
::
loadAllRuntimeClasses
();
}
/**
* importSchema
* method for importing existing schema to Doctrine_Record classes
*
* @param string $directory Directory to write your models to
* @param array $databases Array of databases to generate models for
* @return boolean
*/
public
static
function
importSchema
(
$directory
,
array
$databases
=
array
())
{
return
self
::
generateModelsFromDb
(
$directory
,
$databases
);
}
/**
* exportSchema
* method for exporting Doctrine_Record classes to a schema
*
* @param string $directory Directory containing your models
* @return void
*/
public
static
function
exportSchema
(
$directory
=
null
)
{
return
self
::
createTablesFromModels
(
$directory
);
}
/**
* exportSql
* method for exporting Doctrine_Record classes to a schema
*
* @param string $directory
*/
public
static
function
exportSql
(
$directory
=
null
)
{
return
self
::
generateSqlFromModels
(
$directory
);
}
/**
* loadAllRuntimeClasses
*
* loads all runtime classes
*
* @return void
*/
public
static
function
loadAllRuntimeClasses
()
{
$classes
=
Doctrine_Compiler
::
getRuntimeClasses
();
foreach
(
$classes
as
$class
)
{
self
::
autoload
(
$class
);
}
}
/**
...
...
@@ -457,7 +509,25 @@ final class Doctrine
*/
public
static
function
loadModels
(
$directory
)
{
return
Doctrine_Facade
::
loadModels
(
$directory
);
$declared
=
get_declared_classes
();
if
(
$directory
!==
null
)
{
foreach
((
array
)
$directory
as
$dir
)
{
$it
=
new
RecursiveIteratorIterator
(
new
RecursiveDirectoryIterator
(
$dir
),
RecursiveIteratorIterator
::
LEAVES_ONLY
);
foreach
(
$it
as
$file
)
{
$e
=
explode
(
'.'
,
$file
->
getFileName
());
if
(
end
(
$e
)
===
'php'
&&
strpos
(
$file
->
getFileName
(),
'.inc'
)
===
false
)
{
require_once
$file
->
getPathName
();
}
}
}
$declared
=
array_diff
(
get_declared_classes
(),
$declared
);
}
return
self
::
getLoadedModels
(
$declared
);
}
/**
...
...
@@ -470,7 +540,33 @@ final class Doctrine
*/
public
static
function
getLoadedModels
(
$classes
=
null
)
{
return
Doctrine_Facade
::
getLoadedModels
(
$classes
);
if
(
$classes
===
null
)
{
$classes
=
get_declared_classes
();
}
$parent
=
new
ReflectionClass
(
'Doctrine_Record'
);
$loadedModels
=
array
();
// we iterate trhough the diff of previously declared classes
// and currently declared classes
foreach
(
$classes
as
$name
)
{
$class
=
new
ReflectionClass
(
$name
);
// Skip the following classes
// - abstract classes
// - not a subclass of Doctrine_Record
// - don't have a setTableDefinition method
if
(
$class
->
isAbstract
()
||
!
$class
->
isSubClassOf
(
$parent
)
||
!
$class
->
hasMethod
(
'setTableDefinition'
))
{
continue
;
}
$loadedModels
[]
=
$name
;
}
return
$loadedModels
;
}
/**
...
...
@@ -483,43 +579,290 @@ final class Doctrine
*/
public
static
function
getConnectionByTableName
(
$tableName
)
{
return
Doctrine_Facade
::
getConnectionByTableName
(
$tableName
);
$loadedModels
=
self
::
getLoadedModels
();
foreach
(
$loadedModels
as
$name
)
{
$model
=
new
$name
();
$table
=
$model
->
getTable
();
if
(
$table
->
getTableName
()
==
$tableName
)
{
return
$table
->
getConnection
();
}
}
return
Doctrine_Manager
::
connection
();
}
/**
* importSchema
* generateModelsFromDb
*
* method for importing existing schema to Doctrine_Record classes
*
* @param string $directory Directory to write your models to
* @param array $databases Array of databases to generate models for
* @return boolean
*/
public
static
function
importSchema
(
$directory
,
array
$databases
=
array
())
public
static
function
generateModelsFromDb
(
$directory
,
array
$databases
=
array
())
{
return
Doctrine_
Facade
::
generateModelsFromDb
(
$directory
,
$databases
);
return
Doctrine_
Manager
::
connection
()
->
import
->
importSchema
(
$directory
,
$databases
);
}
/**
* exportSchema
* method for exporting Doctrine_Record classes to a schema
* generateYamlFromDb
*
* Generates models from database to temporary location then uses those models to generate a yaml schema file.
* This should probably be fixed. We should write something to generate a yaml schema file directly from the database.
*
* @param string $yamlPath Path to write oyur yaml schema file to
* @return void
*/
public
static
function
generateYamlFromDb
(
$yamlPath
)
{
$directory
=
'/tmp/tmp_doctrine_models'
;
Doctrine
::
generateModelsFromDb
(
$directory
);
$export
=
new
Doctrine_Export_Schema
();
$result
=
$export
->
exportSchema
(
$yamlPath
,
'yml'
,
$directory
);
exec
(
'rm -rf '
.
$directory
);
return
$result
;
}
/**
* generateModelsFromYaml
*
* Generate a yaml schema file from an existing directory of models
*
* @param string $yamlPath Path to your yaml schema files
* @param string $directory Directory to generate your models in
* @return void
*/
public
static
function
generateModelsFromYaml
(
$yamlPath
,
$directory
)
{
$import
=
new
Doctrine_Import_Schema
();
$import
->
generateBaseClasses
(
true
);
return
$import
->
importSchema
(
$yamlPath
,
'yml'
,
$directory
);
}
/**
* createTablesFromModels
*
* Creates database tables for the models in the specified directory
*
* @param string $directory Directory containing your models
* @return void
*/
public
static
function
exportSchema
(
$directory
=
null
)
public
static
function
createTablesFromModels
(
$directory
=
null
)
{
return
Doctrine_
Facade
::
createTablesFromModels
(
$directory
);
return
Doctrine_
Manager
::
connection
()
->
export
->
exportSchema
(
$directory
);
}
/**
* exportSql
* method for exporting Doctrine_Record classes to a schema
* generateSqlFromModels
*
* @param string $directory
* @return void
*/
public
static
function
exportSql
(
$directory
=
null
)
public
static
function
generateSqlFromModels
(
$directory
=
null
)
{
$sql
=
Doctrine_Manager
::
connection
()
->
export
->
exportSql
(
$directory
);
$build
=
''
;
foreach
(
$sql
as
$query
)
{
$build
.=
$query
.
";
\n
"
;
}
return
$build
;
}
/**
* generateYamlFromModels
*
* Generate yaml schema file for the models in the specified directory
*
* @param string $yamlPath Path to your yaml schema files
* @param string $directory Directory to generate your models in
* @return void
*/
public
static
function
generateYamlFromModels
(
$yamlPath
,
$directory
)
{
$export
=
new
Doctrine_Export_Schema
();
return
$export
->
exportSchema
(
$yamlPath
,
'yml'
,
$directory
);
}
/**
* createDatabases
*
* Creates databases for connections
*
* @param string $specifiedConnections Array of connections you wish to create the database for
* @return void
*/
public
static
function
createDatabases
(
$specifiedConnections
)
{
if
(
!
is_array
(
$specifiedConnections
))
{
$specifiedConnections
=
(
array
)
$specifiedConnections
;
}
$connections
=
Doctrine_Manager
::
getInstance
()
->
getConnections
();
foreach
(
$connections
as
$name
=>
$connection
)
{
if
(
!
empty
(
$specifiedConnections
)
&&
!
in_array
(
$name
,
$specifiedConnections
))
{
continue
;
}
$connection
->
export
->
createDatabase
(
$name
);
}
}
/**
* dropDatabases
*
* Drops databases for connections
*
* @param string $specifiedConnections Array of connections you wish to drop the database for
* @return void
*/
public
static
function
dropDatabases
(
$specifiedConnections
=
array
())
{
if
(
!
is_array
(
$specifiedConnections
))
{
$specifiedConnections
=
(
array
)
$specifiedConnections
;
}
$connections
=
Doctrine_Manager
::
getInstance
()
->
getConnections
();
foreach
(
$connections
as
$name
=>
$connection
)
{
if
(
!
empty
(
$specifiedConnections
)
&&
!
in_array
(
$name
,
$specifiedConnections
))
{
continue
;
}
$connection
->
export
->
dropDatabase
(
$name
);
}
}
/**
* dumpData
*
* Dump data to a yaml fixtures file
*
* @param string $yamlPath Path to write the yaml data fixtures to
* @param string $individualFiles Whether or not to dump data to individual fixtures files
* @return void
*/
public
static
function
dumpData
(
$yamlPath
,
$individualFiles
=
false
)
{
$data
=
new
Doctrine_Data
();
return
$data
->
exportData
(
$yamlPath
,
'yml'
,
array
(),
$individualFiles
);
}
/**
* loadData
*
* Load data from a yaml fixtures file.
* The output of dumpData can be fed to loadData
*
* @param string $yamlPath Path to your yaml data fixtures
* @param string $append Whether or not to append the data
* @return void
*/
public
static
function
loadData
(
$yamlPath
,
$append
=
false
)
{
$delete
=
isset
(
$append
)
?
(
$append
?
false
:
true
)
:
true
;
if
(
$delete
)
{
$models
=
Doctrine
::
getLoadedModels
();
foreach
(
$models
as
$model
)
{
$model
=
new
$model
();
$model
->
getTable
()
->
createQuery
()
->
delete
(
$model
)
->
execute
();
}
}
$data
=
new
Doctrine_Data
();
return
$data
->
importData
(
$yamlPath
,
'yml'
);
}
/**
* loadDummyData
*
* Populdate your models with dummy data
*
* @param string $append Whether or not to append the data
* @param string $num Number of records to populate
* @return void
*/
public
static
function
loadDummyData
(
$append
,
$num
=
5
)
{
$delete
=
isset
(
$append
)
?
(
$append
?
false
:
true
)
:
true
;
if
(
$delete
)
{
$models
=
Doctrine
::
getLoadedModels
();
foreach
(
$models
as
$model
)
{
return
Doctrine_Facade
::
generateSqlFromModels
(
$directory
);
$model
=
new
$model
();
$model
->
getTable
()
->
createQuery
()
->
delete
(
$model
)
->
execute
();
}
}
$data
=
new
Doctrine_Data
();
return
$data
->
importDummyData
(
$num
);
}
/**
* migrate
*
* Migrate database to specified $to version. Migrates from current to latest if you do not specify.
*
* @param string $directory Directory which contains your migration classes
* @param string $to Version you wish to migrate to.
* @return void
*/
public
static
function
migrate
(
$directory
,
$to
=
null
)
{
$migration
=
new
Doctrine_Migration
(
$directory
);
return
$migration
->
migrate
(
$to
);
}
/**
* generateMigrationClass
*
* Generate new migration class skeleton
*
* @param string $className Name of the Migration class to generate
* @param string $directory Directory which contains your migration classes
* @package default
*/
public
static
function
generateMigrationClass
(
$className
,
$directory
)
{
$migration
=
new
Doctrine_Migration
(
$directory
);
$next
=
(
string
)
$migration
->
getNextVersion
();
$fileName
=
str_repeat
(
'0'
,
(
3
-
strlen
(
$next
)))
.
$next
.
'_'
.
self
::
tableize
(
$className
)
.
'.class.php'
;
$path
=
$directory
.
DIRECTORY_SEPARATOR
.
$fileName
;
$code
=
'<?php'
.
PHP_EOL
;
$code
.=
"// Automatically generated by the Doctrine ORM Framework
\n
"
;
$code
.=
"class "
.
self
::
classify
(
$className
)
.
" extends Doctrine_Migration
\n
"
;
$code
.=
"{\n"
;
$code
.=
"
\t
public function up()
\n\t
{ }
\n\n
"
;
$code
.=
"
\t
public function down()
\n\t
{ }
\n
"
;
$code
.=
"}"
;
file_put_contents
(
$path
,
$code
);
}
/**
...
...
@@ -535,7 +878,7 @@ final class Doctrine
*/
public
static
function
compile
(
$target
=
null
,
$includedDrivers
=
array
())
{
return
Doctrine_
Facade
::
compile
(
$target
,
$includedDrivers
);
return
Doctrine_
Compiler
::
compile
(
$target
,
$includedDrivers
);
}
/**
...
...
@@ -582,7 +925,7 @@ final class Doctrine
case
'array'
:
$ret
[]
=
'Array('
;
foreach
(
$var
as
$k
=>
$v
)
{
$ret
[]
=
$k
.
' : '
.
Doctrine
::
dump
(
$v
,
false
);
$ret
[]
=
$k
.
' : '
.
self
::
dump
(
$v
,
false
);
}
$ret
[]
=
")"
;
break
;
...
...
lib/Doctrine/Facade.php
deleted
100644 → 0
View file @
dfdcf002
<?php
/*
* $Id: Facade.php 2761 2007-10-07 23:42:29Z zYne $
*
* 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_Facade
*
* @package Doctrine
* @subpackage Facade
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision: 2761 $
* @author Jonathan H. Wage <jwage@mac.com>
*/
class
Doctrine_Facade
{
/**
* loadAllRuntimeClasses
*
* loads all runtime classes
*
* @return void
*/
public
static
function
loadAllRuntimeClasses
()
{
$classes
=
Doctrine_Compiler
::
getRuntimeClasses
();
foreach
(
$classes
as
$class
)
{
Doctrine
::
autoload
(
$class
);
}
}
/**
* loadModels
*
* Recursively load all models from a directory or array of directories
*
* @param string $directory Path to directory of models or array of directory paths
* @return void
*/
public
static
function
loadModels
(
$directory
)
{
$declared
=
get_declared_classes
();
if
(
$directory
!==
null
)
{
foreach
((
array
)
$directory
as
$dir
)
{
$it
=
new
RecursiveIteratorIterator
(
new
RecursiveDirectoryIterator
(
$dir
),
RecursiveIteratorIterator
::
LEAVES_ONLY
);
foreach
(
$it
as
$file
)
{
$e
=
explode
(
'.'
,
$file
->
getFileName
());
if
(
end
(
$e
)
===
'php'
&&
strpos
(
$file
->
getFileName
(),
'.inc'
)
===
false
)
{
require_once
$file
->
getPathName
();
}
}
}
$declared
=
array_diff
(
get_declared_classes
(),
$declared
);
}
return
self
::
getLoadedModels
(
$declared
);
}
/**
* getLoadedModels
*
* Get all the loaded models, you can provide an array of classes or it will use get_declared_classes()
*
* @param $classes Array of classes to filter through, otherwise uses get_declared_classes()
* @return void
*/
public
static
function
getLoadedModels
(
$classes
=
null
)
{
if
(
$classes
===
null
)
{
$classes
=
get_declared_classes
();
}
$parent
=
new
ReflectionClass
(
'Doctrine_Record'
);
$loadedModels
=
array
();
// we iterate trhough the diff of previously declared classes
// and currently declared classes
foreach
(
$classes
as
$name
)
{
$class
=
new
ReflectionClass
(
$name
);
// Skip the following classes
// - abstract classes
// - not a subclass of Doctrine_Record
// - don't have a setTableDefinition method
if
(
$class
->
isAbstract
()
||
!
$class
->
isSubClassOf
(
$parent
)
||
!
$class
->
hasMethod
(
'setTableDefinition'
))
{
continue
;
}
$loadedModels
[]
=
$name
;
}
return
$loadedModels
;
}
/**
* getConnectionByTableName
*
* Get the connection object for a table by the actual table name
*
* @param string $tableName
* @return void
*/
public
static
function
getConnectionByTableName
(
$tableName
)
{
$loadedModels
=
self
::
getLoadedModels
();
foreach
(
$loadedModels
as
$name
)
{
$model
=
new
$name
();
$table
=
$model
->
getTable
();
if
(
$table
->
getTableName
()
==
$tableName
)
{
return
$table
->
getConnection
();
}
}
return
Doctrine_Manager
::
connection
();
}
/**
* generateModelsFromDb
*
* method for importing existing schema to Doctrine_Record classes
*
* @param string $directory Directory to write your models to
* @param array $databases Array of databases to generate models for
* @return boolean
*/
public
static
function
generateModelsFromDb
(
$directory
,
array
$databases
=
array
())
{
return
Doctrine_Manager
::
connection
()
->
import
->
importSchema
(
$directory
,
$databases
);
}
/**
* generateYamlFromDb
*
* Generates models from database to temporary location then uses those models to generate a yaml schema file.
* This should probably be fixed. We should write something to generate a yaml schema file directly from the database.
*
* @param string $yamlPath Path to write oyur yaml schema file to
* @return void
*/
public
static
function
generateYamlFromDb
(
$yamlPath
)
{
$directory
=
'/tmp/tmp_doctrine_models'
;
Doctrine_Facade
::
generateModelsFromDb
(
$directory
);
$export
=
new
Doctrine_Export_Schema
();
$result
=
$export
->
exportSchema
(
$yamlPath
,
'yml'
,
$directory
);
exec
(
'rm -rf '
.
$directory
);
return
$result
;
}
/**
* generateModelsFromYaml
*
* Generate a yaml schema file from an existing directory of models
*
* @param string $yamlPath Path to your yaml schema files
* @param string $directory Directory to generate your models in
* @return void
*/
public
static
function
generateModelsFromYaml
(
$yamlPath
,
$directory
)
{
$import
=
new
Doctrine_Import_Schema
();
$import
->
generateBaseClasses
(
true
);
return
$import
->
importSchema
(
$yamlPath
,
'yml'
,
$directory
);
}
/**
* createTablesFromModels
*
* Creates database tables for the models in the specified directory
*
* @param string $directory Directory containing your models
* @return void
*/
public
static
function
createTablesFromModels
(
$directory
=
null
)
{
return
Doctrine_Manager
::
connection
()
->
export
->
exportSchema
(
$directory
);
}
/**
* generateSqlFromModels
*
* @param string $directory
* @return void
*/
public
static
function
generateSqlFromModels
(
$directory
=
null
)
{
$sql
=
Doctrine_Manager
::
connection
()
->
export
->
exportSql
(
$directory
);
$build
=
''
;
foreach
(
$sql
as
$query
)
{
$build
.=
$query
.
";
\n
"
;
}
return
$build
;
}
/**
* generateYamlFromModels
*
* Generate yaml schema file for the models in the specified directory
*
* @param string $yamlPath Path to your yaml schema files
* @param string $directory Directory to generate your models in
* @return void
*/
public
static
function
generateYamlFromModels
(
$yamlPath
,
$directory
)
{
$export
=
new
Doctrine_Export_Schema
();
return
$export
->
exportSchema
(
$yamlPath
,
'yml'
,
$directory
);
}
/**
* createDatabases
*
* Creates databases for connections
*
* @param string $specifiedConnections Array of connections you wish to create the database for
* @return void
*/
public
static
function
createDatabases
(
$specifiedConnections
)
{
if
(
!
is_array
(
$specifiedConnections
))
{
$specifiedConnections
=
(
array
)
$specifiedConnections
;
}
$connections
=
Doctrine_Manager
::
getInstance
()
->
getConnections
();
foreach
(
$connections
as
$name
=>
$connection
)
{
if
(
!
empty
(
$specifiedConnections
)
&&
!
in_array
(
$name
,
$specifiedConnections
))
{
continue
;
}
$connection
->
export
->
createDatabase
(
$name
);
}
}
/**
* dropDatabases
*
* Drops databases for connections
*
* @param string $specifiedConnections Array of connections you wish to drop the database for
* @return void
*/
public
static
function
dropDatabases
(
$specifiedConnections
=
array
())
{
if
(
!
is_array
(
$specifiedConnections
))
{
$specifiedConnections
=
(
array
)
$specifiedConnections
;
}
$connections
=
Doctrine_Manager
::
getInstance
()
->
getConnections
();
foreach
(
$connections
as
$name
=>
$connection
)
{
if
(
!
empty
(
$specifiedConnections
)
&&
!
in_array
(
$name
,
$specifiedConnections
))
{
continue
;
}
$connection
->
export
->
dropDatabase
(
$name
);
}
}
/**
* dumpData
*
* Dump data to a yaml fixtures file
*
* @param string $yamlPath Path to write the yaml data fixtures to
* @param string $individualFiles Whether or not to dump data to individual fixtures files
* @return void
*/
public
static
function
dumpData
(
$yamlPath
,
$individualFiles
=
false
)
{
$data
=
new
Doctrine_Data
();
return
$data
->
exportData
(
$yamlPath
,
'yml'
,
array
(),
$individualFiles
);
}
/**
* loadData
*
* Load data from a yaml fixtures file.
* The output of dumpData can be fed to loadData
*
* @param string $yamlPath Path to your yaml data fixtures
* @param string $append Whether or not to append the data
* @return void
*/
public
static
function
loadData
(
$yamlPath
,
$append
=
false
)
{
$delete
=
isset
(
$append
)
?
(
$append
?
false
:
true
)
:
true
;
if
(
$delete
)
{
$models
=
Doctrine_Facade
::
getLoadedModels
();
foreach
(
$models
as
$model
)
{
$model
=
new
$model
();
$model
->
getTable
()
->
createQuery
()
->
delete
(
$model
)
->
execute
();
}
}
$data
=
new
Doctrine_Data
();
return
$data
->
importData
(
$yamlPath
,
'yml'
);
}
/**
* loadDummyData
*
* Populdate your models with dummy data
*
* @param string $append Whether or not to append the data
* @param string $num Number of records to populate
* @return void
*/
public
static
function
loadDummyData
(
$append
,
$num
=
5
)
{
$delete
=
isset
(
$append
)
?
(
$append
?
false
:
true
)
:
true
;
if
(
$delete
)
{
$models
=
Doctrine_Facade
::
getLoadedModels
();
foreach
(
$models
as
$model
)
{
$model
=
new
$model
();
$model
->
getTable
()
->
createQuery
()
->
delete
(
$model
)
->
execute
();
}
}
$data
=
new
Doctrine_Data
();
return
$data
->
importDummyData
(
$num
);
}
/**
* migrate
*
* Migrate database to specified $to version. Migrates from current to latest if you do not specify.
*
* @param string $directory Directory which contains your migration classes
* @param string $to Version you wish to migrate to.
* @return void
*/
public
static
function
migrate
(
$directory
,
$to
=
null
)
{
$migration
=
new
Doctrine_Migration
(
$directory
);
return
$migration
->
migrate
(
$to
);
}
/**
* generateMigrationClass
*
* Generate new migration class skeleton
*
* @param string $className Name of the Migration class to generate
* @param string $directory Directory which contains your migration classes
* @package default
*/
public
static
function
generateMigrationClass
(
$className
,
$directory
)
{
$migration
=
new
Doctrine_Migration
(
$directory
);
$next
=
(
string
)
$migration
->
getNextVersion
();
$fileName
=
str_repeat
(
'0'
,
(
3
-
strlen
(
$next
)))
.
$next
.
'_'
.
Doctrine
::
tableize
(
$className
)
.
'.class.php'
;
$path
=
$directory
.
DIRECTORY_SEPARATOR
.
$fileName
;
$code
=
'<?php'
.
PHP_EOL
;
$code
.=
"// Automatically generated by the Doctrine ORM Framework
\n
"
;
$code
.=
"class "
.
Doctrine
::
classify
(
$className
)
.
" extends Doctrine_Migration
\n
"
;
$code
.=
"{\n"
;
$code
.=
"
\t
public function up()
\n\t
{ }
\n\n
"
;
$code
.=
"
\t
public function down()
\n\t
{ }
\n
"
;
$code
.=
"}"
;
file_put_contents
(
$path
,
$code
);
}
/**
* compile
*
* @param string $target
* @return void
*/
public
static
function
compile
(
$target
=
null
,
$includedDrivers
=
array
())
{
return
Doctrine_Compiler
::
compile
(
$target
,
$includedDrivers
);
}
}
\ No newline at end of file
lib/Doctrine/Task/Compile.php
View file @
779003ed
...
...
@@ -39,6 +39,6 @@ class Doctrine_Task_Compile extends Doctrine_Task
public
function
execute
()
{
Doctrine
_Facade
::
compile
(
$this
->
getArgument
(
'compiled_path'
),
$this
->
getArgument
(
'drivers'
,
array
()));
Doctrine
::
compile
(
$this
->
getArgument
(
'compiled_path'
),
$this
->
getArgument
(
'drivers'
,
array
()));
}
}
\ No newline at end of file
lib/Doctrine/Task/CreateDb.php
View file @
779003ed
...
...
@@ -37,6 +37,6 @@ class Doctrine_Task_CreateDb extends Doctrine_Task
public
function
execute
()
{
Doctrine
_Facade
::
createDatabases
(
$this
->
getArgument
(
'connection'
));
Doctrine
::
createDatabases
(
$this
->
getArgument
(
'connection'
));
}
}
\ No newline at end of file
lib/Doctrine/Task/CreateTables.php
View file @
779003ed
...
...
@@ -38,6 +38,6 @@ class Doctrine_Task_CreateTables extends Doctrine_Task
public
function
execute
()
{
Doctrine
_Facade
::
createTablesFromModels
(
$this
->
getArgument
(
'models_path'
));
Doctrine
::
createTablesFromModels
(
$this
->
getArgument
(
'models_path'
));
}
}
\ No newline at end of file
lib/Doctrine/Task/DropDb.php
View file @
779003ed
...
...
@@ -38,6 +38,6 @@ class Doctrine_Task_DropDb extends Doctrine_Task
public
function
execute
()
{
Doctrine
_Facade
::
dropDatabases
(
$this
->
getArgument
(
'connection'
));
Doctrine
::
dropDatabases
(
$this
->
getArgument
(
'connection'
));
}
}
\ No newline at end of file
lib/Doctrine/Task/DumpData.php
View file @
779003ed
...
...
@@ -39,7 +39,7 @@ class Doctrine_Task_DumpData extends Doctrine_Task
public
function
execute
()
{
Doctrine
_Facade
::
loadModels
(
$this
->
getArgument
(
'models_path'
));
Doctrine
::
loadModels
(
$this
->
getArgument
(
'models_path'
));
$individualFiles
=
$this
->
getArgument
(
'individual_files'
)
?
true
:
false
;
...
...
@@ -53,6 +53,6 @@ class Doctrine_Task_DumpData extends Doctrine_Task
}
}
Doctrine
_Facade
::
dumpData
(
$path
,
$individualFiles
);
Doctrine
::
dumpData
(
$path
,
$individualFiles
);
}
}
\ No newline at end of file
lib/Doctrine/Task/GenerateMigration.php
View file @
779003ed
...
...
@@ -39,6 +39,6 @@ class Doctrine_Task_GenerateMigration extends Doctrine_Task
public
function
execute
()
{
Doctrine
_Facade
::
generateMigrationClass
(
$this
->
getArgument
(
'class_name'
),
$this
->
getArgument
(
'migrations_path'
));
Doctrine
::
generateMigrationClass
(
$this
->
getArgument
(
'class_name'
),
$this
->
getArgument
(
'migrations_path'
));
}
}
\ No newline at end of file
lib/Doctrine/Task/GenerateModelsFromDb.php
View file @
779003ed
...
...
@@ -38,6 +38,6 @@ class Doctrine_Task_GenerateModelsFromDb extends Doctrine_Task
public
function
execute
()
{
Doctrine
_Facade
::
generateModelsFromDb
(
$this
->
getArgument
(
'models_path'
),
(
array
)
$this
->
getArgument
(
'connection'
));
Doctrine
::
generateModelsFromDb
(
$this
->
getArgument
(
'models_path'
),
(
array
)
$this
->
getArgument
(
'connection'
));
}
}
\ No newline at end of file
lib/Doctrine/Task/GenerateModelsFromYaml.php
View file @
779003ed
...
...
@@ -39,6 +39,6 @@ class Doctrine_Task_GenerateModelsFromYaml extends Doctrine_Task
public
function
execute
()
{
Doctrine
_Facade
::
generateModelsFromYaml
(
$this
->
getArgument
(
'yaml_schema_path'
),
$this
->
getArgument
(
'models_path'
));
Doctrine
::
generateModelsFromYaml
(
$this
->
getArgument
(
'yaml_schema_path'
),
$this
->
getArgument
(
'models_path'
));
}
}
\ No newline at end of file
lib/Doctrine/Task/GenerateSql.php
View file @
779003ed
...
...
@@ -47,7 +47,7 @@ class Doctrine_Task_GenerateSql extends Doctrine_Task
throw
new
Doctrine_Task_Exception
(
'Invalid sql path.'
);
}
$sql
=
Doctrine
_Facade
::
generateSqlFromModels
(
$this
->
getArgument
(
'models_path'
));
$sql
=
Doctrine
::
generateSqlFromModels
(
$this
->
getArgument
(
'models_path'
));
file_put_contents
(
$path
,
$sql
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment