Moved cli to sandbox folder. Fixes to importing schema and generating sql.
This commit is contained in:
parent
ea368a366d
commit
34af8e3aa1
@ -558,6 +558,7 @@ final class Doctrine
|
|||||||
public static function generateModelsFromYaml($yamlPath, $directory)
|
public static function generateModelsFromYaml($yamlPath, $directory)
|
||||||
{
|
{
|
||||||
$import = new Doctrine_Import_Schema();
|
$import = new Doctrine_Import_Schema();
|
||||||
|
$import->generateBaseClasses(true);
|
||||||
|
|
||||||
return $import->importSchema($yamlPath, 'yml', $directory);
|
return $import->importSchema($yamlPath, 'yml', $directory);
|
||||||
}
|
}
|
||||||
@ -754,8 +755,8 @@ final class Doctrine
|
|||||||
$path = $directory . DIRECTORY_SEPARATOR . $fileName;
|
$path = $directory . DIRECTORY_SEPARATOR . $fileName;
|
||||||
|
|
||||||
$code = '<?php' . PHP_EOL;
|
$code = '<?php' . PHP_EOL;
|
||||||
$code .= "// Automatically generated by Doctrine\n";
|
$code .= "// Automatically generated by the Doctrine ORM Framework\n";
|
||||||
$code .= "class " . $className . " extends Doctrine_Migration\n";
|
$code .= "class " . Doctrine::classify($className) . " extends Doctrine_Migration\n";
|
||||||
$code .= "{\n";
|
$code .= "{\n";
|
||||||
$code .= "\tpublic function up()\n\t{ }\n\n";
|
$code .= "\tpublic function up()\n\t{ }\n\n";
|
||||||
$code .= "\tpublic function down()\n\t{ }\n";
|
$code .= "\tpublic function down()\n\t{ }\n";
|
||||||
|
@ -55,9 +55,13 @@ abstract class Doctrine_Cli_Task
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getArgument($name)
|
public function getArgument($name, $default = null)
|
||||||
{
|
{
|
||||||
return $this->arguments[$name];
|
if (isset($this->arguments[$name])) {
|
||||||
|
return $this->arguments[$name];
|
||||||
|
} else if ($default) {
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getArguments()
|
public function getArguments()
|
||||||
|
@ -41,6 +41,14 @@ class Doctrine_Cli_Task_GenerateSql extends Doctrine_Cli_Task
|
|||||||
{
|
{
|
||||||
$sql = Doctrine::generateSqlFromModels($this->getArgument('models_path'));
|
$sql = Doctrine::generateSqlFromModels($this->getArgument('models_path'));
|
||||||
|
|
||||||
file_put_contents($this->getArgument('sql_path'), implode("\n", $sql));
|
if (is_dir($this->getArgument('sql_path'))) {
|
||||||
|
$path = $this->getArgument('sql_path') . DIRECTORY_SEPARATOR . 'schema.sql';
|
||||||
|
} else if (is_file($this->getArgument('sql_path'))) {
|
||||||
|
$path = $this->getArgument('sql_path');
|
||||||
|
} else {
|
||||||
|
throw new Doctrine_Cli_Exception('Invalid sql path.');
|
||||||
|
}
|
||||||
|
|
||||||
|
file_put_contents($path, implode("\n", $sql));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,100 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* $Id: Config.php 2753 2007-10-07 20:58:08Z Jonathan.Wage $
|
|
||||||
*
|
|
||||||
* 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_Config
|
|
||||||
*
|
|
||||||
* Class used to simplify the setup and configuration of a doctrine implementation.
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @subpackage Config
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @link www.phpdoctrine.com
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision: 2753 $
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
* @author Jonathan H. Wage <jwage@mac.com>
|
|
||||||
*/
|
|
||||||
class Doctrine_Config
|
|
||||||
{
|
|
||||||
protected $connections = array();
|
|
||||||
protected $cliConfig = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* addConnection
|
|
||||||
*
|
|
||||||
* @param string $adapter
|
|
||||||
* @param string $name
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function addConnection($adapter, $name = null)
|
|
||||||
{
|
|
||||||
$connections[] = Doctrine_Manager::getInstance()->openConnection($adapter, $name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* bindComponent
|
|
||||||
*
|
|
||||||
* @param string $modelName
|
|
||||||
* @param string $connectionName
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function bindComponent($modelName, $connectionName)
|
|
||||||
{
|
|
||||||
return Doctrine_Manager::getInstance()->bindComponent($modelName, $connectionName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* setAttribute
|
|
||||||
*
|
|
||||||
* @param string $key
|
|
||||||
* @param string $value
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function setAttribute($key, $value)
|
|
||||||
{
|
|
||||||
foreach ($this->connections as $connection) {
|
|
||||||
$connection->setAttribute($key, $value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* addCliConfig
|
|
||||||
*
|
|
||||||
* @param string $key
|
|
||||||
* @param string $value
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function addCliConfig($key, $value)
|
|
||||||
{
|
|
||||||
$this->cliConfig[$key] = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* getCliConfig
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function getCliConfig()
|
|
||||||
{
|
|
||||||
return $this->cliConfig;
|
|
||||||
}
|
|
||||||
}
|
|
@ -189,6 +189,7 @@ class Doctrine_Import extends Doctrine_Connection_Module
|
|||||||
|
|
||||||
foreach ($connections as $connection) {
|
foreach ($connections as $connection) {
|
||||||
$builder = new Doctrine_Import_Builder();
|
$builder = new Doctrine_Import_Builder();
|
||||||
|
$builder->generateBaseClasses(true);
|
||||||
$builder->setTargetPath($directory);
|
$builder->setTargetPath($directory);
|
||||||
|
|
||||||
$classes = array();
|
$classes = array();
|
||||||
|
@ -43,6 +43,12 @@ class Doctrine_Import_Schema
|
|||||||
public $indexes = array();
|
public $indexes = array();
|
||||||
public $generateBaseClasses = false;
|
public $generateBaseClasses = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* generateBaseClasses
|
||||||
|
*
|
||||||
|
* @param string $bool
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
public function generateBaseClasses($bool = null)
|
public function generateBaseClasses($bool = null)
|
||||||
{
|
{
|
||||||
if ($bool !== null) {
|
if ($bool !== null) {
|
||||||
@ -51,17 +57,39 @@ class Doctrine_Import_Schema
|
|||||||
|
|
||||||
return $this->generateBaseClasses;
|
return $this->generateBaseClasses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* buildSchema
|
||||||
|
*
|
||||||
|
* @param string $schema
|
||||||
|
* @param string $format
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
public function buildSchema($schema, $format)
|
public function buildSchema($schema, $format)
|
||||||
{
|
{
|
||||||
$array = array();
|
$array = array();
|
||||||
|
|
||||||
foreach ((array) $schema AS $s) {
|
foreach ((array) $schema AS $s) {
|
||||||
$array = array_merge($array, $this->parseSchema($s, $format));
|
if (is_file($s)) {
|
||||||
|
$array = array_merge($array, $this->parseSchema($s, $format));
|
||||||
|
} else if (is_dir($s)) {
|
||||||
|
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($s),
|
||||||
|
RecursiveIteratorIterator::LEAVES_ONLY);
|
||||||
|
|
||||||
|
foreach ($it as $file) {
|
||||||
|
$e = explode('.', $file->getFileName());
|
||||||
|
if (end($e) === $format) {
|
||||||
|
$array = array_merge($array, $this->parseSchema($file->getPathName(), $format));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->buildRelationships($array);
|
$this->buildRelationships($array);
|
||||||
|
|
||||||
return array('schema' => $array, 'relations' => $this->relations, 'indexes' => $this->indexes);
|
return array('schema' => $array, 'relations' => $this->relations, 'indexes' => $this->indexes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* importSchema
|
* importSchema
|
||||||
*
|
*
|
||||||
@ -96,6 +124,13 @@ class Doctrine_Import_Schema
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getOptions
|
||||||
|
*
|
||||||
|
* @param string $properties
|
||||||
|
* @param string $directory
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
public function getOptions($properties, $directory)
|
public function getOptions($properties, $directory)
|
||||||
{
|
{
|
||||||
$options = array();
|
$options = array();
|
||||||
@ -110,11 +145,23 @@ class Doctrine_Import_Schema
|
|||||||
return $options;
|
return $options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getColumns
|
||||||
|
*
|
||||||
|
* @param string $properties
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
public function getColumns($properties)
|
public function getColumns($properties)
|
||||||
{
|
{
|
||||||
return isset($properties['columns']) ? $properties['columns']:array();
|
return isset($properties['columns']) ? $properties['columns']:array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getRelations
|
||||||
|
*
|
||||||
|
* @param string $properties
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
public function getRelations($properties)
|
public function getRelations($properties)
|
||||||
{
|
{
|
||||||
return isset($this->relations[$properties['className']]) ? $this->relations[$properties['className']]:array();
|
return isset($this->relations[$properties['className']]) ? $this->relations[$properties['className']]:array();
|
||||||
@ -181,6 +228,12 @@ class Doctrine_Import_Schema
|
|||||||
return $build;
|
return $build;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* buildRelationships
|
||||||
|
*
|
||||||
|
* @param string $array
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
public function buildRelationships(&$array)
|
public function buildRelationships(&$array)
|
||||||
{
|
{
|
||||||
foreach ($array as $name => $properties) {
|
foreach ($array as $name => $properties) {
|
||||||
@ -225,6 +278,11 @@ class Doctrine_Import_Schema
|
|||||||
$this->fixRelationships();
|
$this->fixRelationships();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fixRelationships
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
public function fixRelationships()
|
public function fixRelationships()
|
||||||
{
|
{
|
||||||
// define both sides of the relationship
|
// define both sides of the relationship
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
<?php
|
|
||||||
require_once('config.php');
|
|
||||||
|
|
||||||
$cli = new Doctrine_Cli($config->getCliConfig());
|
|
||||||
$cli->run($_SERVER['argv']);
|
|
13
sandbox/cli.php
Normal file
13
sandbox/cli.php
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
require_once('config.php');
|
||||||
|
|
||||||
|
// Configure Doctrine Cli
|
||||||
|
// Normally these are arguments to the cli tasks but if they are set here the arguments will be auto-filled
|
||||||
|
$config = array('data_fixtures_path' => DATA_FIXTURES_PATH,
|
||||||
|
'models_path' => MODELS_PATH,
|
||||||
|
'migrations_path' => MIGRATIONS_PATH,
|
||||||
|
'sql_path' => SQL_PATH,
|
||||||
|
'yaml_schema_path' => YAML_SCHEMA_PATH);
|
||||||
|
|
||||||
|
$cli = new Doctrine_Cli($config);
|
||||||
|
$cli->run($_SERVER['argv']);
|
@ -1,7 +1,5 @@
|
|||||||
#!/usr/bin/env php
|
#!/usr/bin/php
|
||||||
<?php
|
|
||||||
chdir(dirname(__FILE__));
|
|
||||||
?>
|
|
||||||
Welcome to the interactive Doctrine Compiler 0.0.1 (Beta).
|
Welcome to the interactive Doctrine Compiler 0.0.1 (Beta).
|
||||||
|
|
||||||
WARNING: You're on your own - this script modifies your
|
WARNING: You're on your own - this script modifies your
|
||||||
@ -28,6 +26,21 @@ While the program is running:
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($argc > 1) {
|
||||||
|
$doctrinePath = $argv[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
$drivers = array(
|
||||||
|
'Db2',
|
||||||
|
'Firebird',
|
||||||
|
'Informix',
|
||||||
|
'Mssql',
|
||||||
|
'Mysql',
|
||||||
|
'Oracle',
|
||||||
|
'Pgsql',
|
||||||
|
'Sqlite'
|
||||||
|
);
|
||||||
|
|
||||||
function addIncludePath($path) {
|
function addIncludePath($path) {
|
||||||
set_include_path(
|
set_include_path(
|
||||||
$path . PATH_SEPARATOR . get_include_path()
|
$path . PATH_SEPARATOR . get_include_path()
|
||||||
@ -97,30 +110,20 @@ function ask(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Enable error reporting
|
// Enable error reporting
|
||||||
|
|
||||||
if (($answer = ask("Would you like to turn on error reporting?", 'n')) == 'y') {
|
if (($answer = ask("Would you like to turn on error reporting?", 'n')) == 'y') {
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
$showErrors = true;
|
|
||||||
} else {
|
} else {
|
||||||
error_reporting(0);
|
error_reporting(0);
|
||||||
$showErrors = false;
|
|
||||||
}
|
}
|
||||||
autoQuit($answer);
|
autoQuit($answer);
|
||||||
|
|
||||||
// Process library path command line argument
|
|
||||||
|
|
||||||
if ($argc > 1) {
|
|
||||||
$doctrinePath = $argv[1];
|
|
||||||
} else {
|
|
||||||
$doctrinePath = dirname(__FILE__);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get Doctrine's library path
|
// Get Doctrine's library path
|
||||||
|
|
||||||
$usablePath = false;
|
$usablePath = false;
|
||||||
while (!$usablePath) {
|
while (!$usablePath) {
|
||||||
|
if (!isset($doctrinePath)) {
|
||||||
|
$doctrinePath = dirname(__FILE__);
|
||||||
|
}
|
||||||
$path = ask("Please enter the path to Doctrine's lib directory:", $doctrinePath, array($doctrinePath), false);
|
$path = ask("Please enter the path to Doctrine's lib directory:", $doctrinePath, array($doctrinePath), false);
|
||||||
autoQuit($path);
|
autoQuit($path);
|
||||||
try {
|
try {
|
||||||
@ -136,58 +139,10 @@ while (!$usablePath) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process target filename command line argument
|
|
||||||
|
|
||||||
if ($argc > 2) {
|
|
||||||
$targetFile = $argv[2];
|
|
||||||
} else {
|
|
||||||
$targetFile = $path.DIRECTORY_SEPARATOR.'Doctrine.compiled.php';
|
|
||||||
}
|
|
||||||
|
|
||||||
clearstatcache();
|
|
||||||
$usableFilename = false;
|
|
||||||
while (!$usableFilename) {
|
|
||||||
$target = ask("Please enter the target filename for the 'compiled' Doctrine file that will be created:", $targetFile, array($targetFile), false);
|
|
||||||
autoQuit($target);
|
|
||||||
if (file_exists($target)) {
|
|
||||||
if (is_writable($target) && (!is_dir($target))) {
|
|
||||||
$usableFilename = true;
|
|
||||||
} else {
|
|
||||||
$msg = "The target filename '$target' cannot be used (it is not writable, or it is a directory).";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (is_writable(dirname($target))) {
|
|
||||||
$usableFilename = true;
|
|
||||||
} else {
|
|
||||||
$msg = "The directory in which the target file will be created is not writable.";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!$usableFilename) {
|
|
||||||
showMessage($msg);
|
|
||||||
if (($answer = ask("Would you like to specify a different target filename?")) != 'y') {
|
|
||||||
quit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Define the default drivers - unfortunately, this is hard-coded for now
|
|
||||||
|
|
||||||
$drivers = array(
|
|
||||||
'Db2',
|
|
||||||
'Firebird',
|
|
||||||
'Informix',
|
|
||||||
'Mssql',
|
|
||||||
'Mysql',
|
|
||||||
'Oracle',
|
|
||||||
'Pgsql',
|
|
||||||
'Sqlite'
|
|
||||||
);
|
|
||||||
|
|
||||||
$includeDrivers = array();
|
$includeDrivers = array();
|
||||||
$excludeDrivers = array();
|
$excludeDrivers = array();
|
||||||
|
|
||||||
// Determine driver support
|
// Determine driver support
|
||||||
|
|
||||||
foreach ($drivers as $driver) {
|
foreach ($drivers as $driver) {
|
||||||
if (($answer = ask("Would you like to enable support for $driver?")) == 'y') {
|
if (($answer = ask("Would you like to enable support for $driver?")) == 'y') {
|
||||||
$includeDrivers[] = $driver;
|
$includeDrivers[] = $driver;
|
||||||
@ -198,22 +153,19 @@ foreach ($drivers as $driver) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Verify driver support
|
// Verify driver support
|
||||||
|
|
||||||
if (!count($includeDrivers)) {
|
if (!count($includeDrivers)) {
|
||||||
showMessage("You have not selected any drivers. Usually this is not a good idea, unless you know what you're doing.");
|
showMessage("You have not selected any drivers. Normally this is not a good idea, unless you know what you're doing.");
|
||||||
if (($answer = ask("Are you sure you want to compile without any drivers?")) != 'y') {
|
if (($answer = ask("Are you sure you want to compile without any drivers?")) != 'y') {
|
||||||
quit();
|
quit();
|
||||||
}
|
}
|
||||||
autoQuit($answer);
|
autoQuit($answer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to prevent errors related to memory allocation
|
// 'Compile' Doctrine...
|
||||||
|
showMessage("Trying to set the PHP memory limit to 18MB...");
|
||||||
$requiredMemory = '20M';
|
ini_set('memory_limit', '18M');
|
||||||
showMessage("Trying to set the PHP memory limit to $requiredMemory...");
|
if (ini_get('memory_limit') != '18M') {
|
||||||
ini_set('memory_limit', $requiredMemory);
|
showMessage("WARNING: The program could not set the PHP memory limit to 18MB. The compilation might fail.");
|
||||||
if (ini_get('memory_limit') != $requiredMemory) {
|
|
||||||
showMessage("WARNING: The program could not set the PHP memory limit to $requiredMemory. The compilation might fail.");
|
|
||||||
if (($answer = ask("Do you still want to continue?")) != 'y') {
|
if (($answer = ask("Do you still want to continue?")) != 'y') {
|
||||||
quit;
|
quit;
|
||||||
}
|
}
|
||||||
@ -221,96 +173,80 @@ if (ini_get('memory_limit') != $requiredMemory) {
|
|||||||
showMessage("PHP memory limit adjusted successfully.");
|
showMessage("PHP memory limit adjusted successfully.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build / 'Compile' Doctrine...
|
|
||||||
|
|
||||||
|
$target = './Doctrine.compiled.php';
|
||||||
|
|
||||||
try {
|
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::LEAVES_ONLY);
|
||||||
|
|
||||||
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::LEAVES_ONLY);
|
foreach ($it as $file) {
|
||||||
|
$e = explode('.', $file->getFileName());
|
||||||
|
|
||||||
foreach ($it as $file) {
|
// we don't want to require versioning files
|
||||||
$e = explode('.', $file->getFileName());
|
if (end($e) === 'php' && strpos($file->getFileName(), '.inc') === false) {
|
||||||
|
require_once $file->getPathName();
|
||||||
// We don't want to require versioning files, or cli files
|
|
||||||
|
|
||||||
if (end($e) === 'php' && strpos($file->getFileName(), '.inc') === false && strpos($file->getFileName(), 'cli') !== 0) {
|
|
||||||
require_once $file->getPathName();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$classes = array_merge(get_declared_classes(), get_declared_interfaces());
|
|
||||||
|
|
||||||
$ret = array();
|
|
||||||
|
|
||||||
foreach ($classes as $class) {
|
|
||||||
$e = explode('_', $class);
|
|
||||||
|
|
||||||
if ($e[0] !== 'Doctrine') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip excluded drivers
|
|
||||||
|
|
||||||
$skipClass = false;
|
|
||||||
foreach ($excludeDrivers as $excludeDriver) {
|
|
||||||
if (in_array($excludeDriver, $e)) {
|
|
||||||
$skipClass = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($skipClass) {
|
|
||||||
echo "\nExcluding -> $class";
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$refl = new ReflectionClass($class);
|
|
||||||
$file = $refl->getFileName();
|
|
||||||
|
|
||||||
echo "\nIncluding -> $file";
|
|
||||||
|
|
||||||
$lines = file($file);
|
|
||||||
|
|
||||||
$start = $refl->getStartLine() - 1;
|
|
||||||
$end = $refl->getEndLine();
|
|
||||||
|
|
||||||
$ret = array_merge($ret, array_slice($lines, $start, ($end - $start)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// first write the 'compiled' data to a text file, so
|
|
||||||
// that we can use php_strip_whitespace (which only works on files)
|
|
||||||
|
|
||||||
$fp = @fopen($target, 'w');
|
|
||||||
|
|
||||||
if ($fp === false) {
|
|
||||||
throw new Exception("Couldn't write compiled data. Failed to open $target");
|
|
||||||
}
|
|
||||||
fwrite($fp, "<?php ". implode('', $ret));
|
|
||||||
fclose($fp);
|
|
||||||
|
|
||||||
$stripped = php_strip_whitespace($target);
|
|
||||||
$fp = @fopen($target, 'w');
|
|
||||||
if ($fp === false) {
|
|
||||||
throw new Exception("Couldn't write compiled data. Failed to open $file");
|
|
||||||
}
|
|
||||||
fwrite($fp, $stripped);
|
|
||||||
fclose($fp);
|
|
||||||
|
|
||||||
} catch (Exception $e) {
|
|
||||||
|
|
||||||
if (!$showErrors) {
|
|
||||||
if (($answer = ask("Sorry, an error occurred during the build. Would you like to see the error?")) == 'y') {
|
|
||||||
showMessage("\n$e");
|
|
||||||
} else {
|
|
||||||
quit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
showMessage("\nBuild Aborted.");
|
|
||||||
exit;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Say bye...
|
$classes = array_merge(get_declared_classes(), get_declared_interfaces());
|
||||||
|
|
||||||
|
$ret = array();
|
||||||
|
|
||||||
|
foreach ($classes as $class) {
|
||||||
|
$e = explode('_', $class);
|
||||||
|
|
||||||
|
if ($e[0] !== 'Doctrine') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip excluded drivers
|
||||||
|
$skipClass = false;
|
||||||
|
foreach ($excludeDrivers as $excludeDriver) {
|
||||||
|
if (in_array($excludeDriver, $e)) {
|
||||||
|
$skipClass = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($skipClass) {
|
||||||
|
echo "\nExcluding -> $class";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$refl = new ReflectionClass($class);
|
||||||
|
$file = $refl->getFileName();
|
||||||
|
|
||||||
|
echo "\nIncluding -> $file";
|
||||||
|
|
||||||
|
$lines = file($file);
|
||||||
|
|
||||||
|
$start = $refl->getStartLine() - 1;
|
||||||
|
$end = $refl->getEndLine();
|
||||||
|
|
||||||
|
$ret = array_merge($ret, array_slice($lines, $start, ($end - $start)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($target == null) {
|
||||||
|
$target = $path . DIRECTORY_SEPARATOR . 'Doctrine.compiled.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
// first write the 'compiled' data to a text file, so
|
||||||
|
// that we can use php_strip_whitespace (which only works on files)
|
||||||
|
$fp = @fopen($target, 'w');
|
||||||
|
|
||||||
|
if ($fp === false) {
|
||||||
|
throw new Exception("Couldn't write compiled data. Failed to open $target");
|
||||||
|
}
|
||||||
|
fwrite($fp, "<?php ". implode('', $ret));
|
||||||
|
fclose($fp);
|
||||||
|
|
||||||
|
$stripped = php_strip_whitespace($target);
|
||||||
|
$fp = @fopen($target, 'w');
|
||||||
|
if ($fp === false) {
|
||||||
|
throw new Exception("Couldn't write compiled data. Failed to open $file");
|
||||||
|
}
|
||||||
|
fwrite($fp, $stripped);
|
||||||
|
fclose($fp);
|
||||||
|
|
||||||
|
// Say bye...
|
||||||
showMessage("\nCompilation Finished.");
|
showMessage("\nCompilation Finished.");
|
||||||
showMessage("Thank you for using the interactive Doctrine Compiler. Have fun following the Doctrine :)\n");
|
showMessage("Thank you for using the interactive Doctrine Compiler. Have fun following the Doctrine :)\n");
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
* $Id: Config.php 2753 2007-10-07 20:58:08Z Jonathan.Wage $
|
* $Id: config.php 2753 2007-10-07 20:58:08Z Jonathan.Wage $
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
@ -23,8 +23,6 @@
|
|||||||
* Doctrine Configuration File
|
* Doctrine Configuration File
|
||||||
*
|
*
|
||||||
* This is a sample implementation of Doctrine
|
* This is a sample implementation of Doctrine
|
||||||
* You can use the Doctrine_Config interface below to setup the basics.
|
|
||||||
* Or if you prefer you can setup your Doctrine configuration manually.
|
|
||||||
*
|
*
|
||||||
* @package Doctrine
|
* @package Doctrine
|
||||||
* @subpackage Config
|
* @subpackage Config
|
||||||
@ -36,23 +34,17 @@
|
|||||||
* @author Jonathan H. Wage <jwage@mac.com>
|
* @author Jonathan H. Wage <jwage@mac.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Load Doctrine
|
define('SANDBOX_PATH', dirname(__FILE__));
|
||||||
require_once('Doctrine.php');
|
define('DOCTRINE_PATH', dirname(SANDBOX_PATH) . DIRECTORY_SEPARATOR . 'lib');
|
||||||
|
define('DATA_FIXTURES_PATH', SANDBOX_PATH . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'fixtures');
|
||||||
|
define('MODELS_PATH', SANDBOX_PATH . DIRECTORY_SEPARATOR . 'models');
|
||||||
|
define('MIGRATIONS_PATH', SANDBOX_PATH . DIRECTORY_SEPARATOR . 'models');
|
||||||
|
define('SQL_PATH', SANDBOX_PATH . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'sql');
|
||||||
|
define('YAML_SCHEMA_PATH', SANDBOX_PATH . DIRECTORY_SEPARATOR . 'schema');
|
||||||
|
define('DSN', 'sqlite:/' . SANDBOX_PATH . DIRECTORY_SEPARATOR . 'sandbox.db');
|
||||||
|
|
||||||
|
require_once(DOCTRINE_PATH . DIRECTORY_SEPARATOR . 'Doctrine.php');
|
||||||
|
|
||||||
spl_autoload_register(array('Doctrine', 'autoload'));
|
spl_autoload_register(array('Doctrine', 'autoload'));
|
||||||
|
|
||||||
// New Doctrine Config
|
Doctrine_Manager::connection(DSN, 'sandbox');
|
||||||
$config = new Doctrine_Config();
|
|
||||||
|
|
||||||
// Setup Connections
|
|
||||||
//$config->addConnection('mysql://user:pass@localhost/db_name', 'connection_1');
|
|
||||||
//$config->addConnection(new PDO('dsn', 'username', 'password'), 'connection_2);
|
|
||||||
|
|
||||||
// Bind components/models to connections
|
|
||||||
//$config->bindComponent('User', 'connection_1');
|
|
||||||
|
|
||||||
// Configure Doctrine Cli
|
|
||||||
// Normally these are arguments to the cli tasks but if they are set here the arguments will be auto-filled
|
|
||||||
//$config->addCliConfig('data_fixtures_path', '/path/to/your/data_fixtures');
|
|
||||||
//$config->addCliConfig('models_path', '/path/to/your/models');
|
|
||||||
//$config->addCliConfig('migrations_path', '/peth/to/your/migration/classes');
|
|
||||||
//$config->addCliConfig('sql_path', '/path/to/your/exported/sql');
|
|
Loading…
Reference in New Issue
Block a user