Commit db10d4a0 authored by Jonathan.Wage's avatar Jonathan.Wage

Formatting/standards changes.

parent 4428b517
......@@ -686,12 +686,13 @@ final class Doctrine
*
* @param string $yamlPath Path to your yaml schema files
* @param string $directory Directory to generate your models in
* @param array $options Array of options to pass to the schema importer
* @return void
*/
public static function generateModelsFromYaml($yamlPath, $directory)
public static function generateModelsFromYaml($yamlPath, $directory, $options = array())
{
$import = new Doctrine_Import_Schema();
$import->generateBaseClasses(true);
$import->setOption('generateBaseClasses', true);
return $import->importSchema($yamlPath, 'yml', $directory);
}
......
......@@ -32,12 +32,12 @@
*/
class Doctrine_Cli
{
protected $tasks = array(),
$taskInstance = null,
$formatter = null,
$scriptName = null,
$message = null,
$config = array();
protected $_tasks = array(),
$_taskInstance = null,
$_formatter = null,
$_scriptName = null,
$_message = null,
$_config = array();
/**
* __construct
......@@ -47,8 +47,8 @@ class Doctrine_Cli
*/
public function __construct($config = array())
{
$this->config = $config;
$this->formatter = new Doctrine_Cli_AnsiColorFormatter();
$this->_config = $config;
$this->_formatter = new Doctrine_Cli_AnsiColorFormatter();
$this->loadTasks();
}
......@@ -61,7 +61,7 @@ class Doctrine_Cli
*/
public function notify($notification = null, $style = 'HEADER')
{
echo $this->formatter->format($this->taskInstance->getTaskName(), 'INFO') . ' - ' . $this->formatter->format($notification, $style) . "\n";
echo $this->_formatter->format($this->_taskInstance->getTaskName(), 'INFO') . ' - ' . $this->_formatter->format($notification, $style) . "\n";
}
/**
......@@ -72,7 +72,7 @@ class Doctrine_Cli
*/
public function notifyException($exception)
{
echo $this->formatter->format($exception->getMessage(), 'ERROR') . "\n";
echo $this->_formatter->format($exception->getMessage(), 'ERROR') . "\n";
}
/**
......@@ -90,7 +90,15 @@ class Doctrine_Cli
$this->notifyException($exception);
}
}
/**
* _getTaskClassFromArgs
*
* Get the task class from an array of cli arguments
*
* @param string $args
* @return void
*/
protected function _getTaskClassFromArgs($args)
{
$taskName = str_replace('-', '_', $args[1]);
......@@ -98,10 +106,16 @@ class Doctrine_Cli
return $taskClass;
}
/**
* _run
*
* @param string $args
* @return void
*/
protected function _run($args)
{
$this->scriptName = $args[0];
$this->_scriptName = $args[0];
$arg1 = isset($args[1]) ? $args[1]:null;
......@@ -124,17 +138,17 @@ class Doctrine_Cli
unset($args[0]);
unset($args[1]);
$this->taskInstance = new $taskClass($this);
$this->_taskInstance = new $taskClass($this);
$args = $this->prepareArgs($args);
$this->taskInstance->setArguments($args);
$this->_taskInstance->setArguments($args);
try {
if ($this->taskInstance->validate()) {
$this->taskInstance->execute();
if ($this->_taskInstance->validate()) {
$this->_taskInstance->execute();
} else {
echo $this->formatter->format('Requires arguments missing!!', 'ERROR') . "\n\n";
echo $this->_formatter->format('Requires arguments missing!!', 'ERROR') . "\n\n";
echo $this->printTasks($arg1, true);
}
} catch (Exception $e) {
......@@ -150,7 +164,7 @@ class Doctrine_Cli
*/
protected function prepareArgs($args)
{
$taskInstance = $this->taskInstance;
$taskInstance = $this->_taskInstance;
$args = array_values($args);
......@@ -168,8 +182,8 @@ class Doctrine_Cli
}
// If we have a config array then lets try and fill some of the arguments with the config values
if (is_array($this->config) && !empty($this->config)) {
foreach ($this->config as $key => $value) {
if (is_array($this->_config) && !empty($this->_config)) {
foreach ($this->_config as $key => $value) {
if (array_key_exists($key, $prepared)) {
$prepared[$key] = $value;
}
......@@ -202,7 +216,7 @@ class Doctrine_Cli
$tasks = $this->getLoadedTasks();
echo $this->formatter->format("Doctrine Command Line Interface", 'HEADER') . "\n\n";
echo $this->_formatter->format("Doctrine Command Line Interface", 'HEADER') . "\n\n";
foreach ($tasks as $taskName)
{
......@@ -214,9 +228,9 @@ class Doctrine_Cli
$taskInstance = new $className();
$taskInstance->taskName = str_replace('_', '-', Doctrine::tableize($taskName));
$syntax = $this->scriptName . ' ' . $taskInstance->getTaskName();
$syntax = $this->_scriptName . ' ' . $taskInstance->getTaskName();
echo $this->formatter->format($syntax, 'INFO');
echo $this->_formatter->format($syntax, 'INFO');
if ($full) {
echo " - " . $taskInstance->getDescription() . "\n";
......@@ -227,10 +241,10 @@ class Doctrine_Cli
if ( ! empty($requiredArguments)) {
foreach ($requiredArguments as $name => $description) {
$args .= $this->formatter->format($name, "ERROR");
$args .= $this->_formatter->format($name, "ERROR");
if (isset($this->config[$name])) {
$args .= " - " . $this->formatter->format($this->config[$name], 'COMMENT');
if (isset($this->_config[$name])) {
$args .= " - " . $this->_formatter->format($this->_config[$name], 'COMMENT');
} else {
$args .= " - " . $description;
}
......@@ -248,7 +262,7 @@ class Doctrine_Cli
}
if ($args) {
echo "\n" . $this->formatter->format('Arguments:', 'HEADER') . "\n" . $args;
echo "\n" . $this->_formatter->format('Arguments:', 'HEADER') . "\n" . $args;
}
}
......@@ -295,9 +309,9 @@ class Doctrine_Cli
}
}
$this->tasks = array_merge($this->tasks, $tasks);
$this->_tasks = array_merge($this->_tasks, $tasks);
return $this->tasks;
return $this->_tasks;
}
public function getLoadedTasks()
......@@ -318,6 +332,6 @@ class Doctrine_Cli
}
}
return array_merge($this->tasks, $tasks);
return array_merge($this->_tasks, $tasks);
}
}
......@@ -37,126 +37,119 @@
*/
class Doctrine_Cli_AnsiColorFormatter extends Doctrine_Cli_Formatter
{
protected
$styles = array(
'HEADER' => array('fg' => 'black', 'bold' => true),
'ERROR' => array('bg' => 'red', 'fg' => 'white', 'bold' => true),
'INFO' => array('fg' => 'green', 'bold' => true),
'COMMENT' => array('fg' => 'yellow'),
),
$options = array('bold' => 1, 'underscore' => 4, 'blink' => 5, 'reverse' => 7, 'conceal' => 8),
$foreground = array('black' => 30, 'red' => 31, 'green' => 32, 'yellow' => 33, 'blue' => 34, 'magenta' => 35, 'cyan' => 36, 'white' => 37),
$background = array('black' => 40, 'red' => 41, 'green' => 42, 'yellow' => 43, 'blue' => 44, 'magenta' => 45, 'cyan' => 46, 'white' => 47);
protected
$_styles = array(
'HEADER' => array('fg' => 'black', 'bold' => true),
'ERROR' => array('bg' => 'red', 'fg' => 'white', 'bold' => true),
'INFO' => array('fg' => 'green', 'bold' => true),
'COMMENT' => array('fg' => 'yellow'),
),
$_options = array('bold' => 1, 'underscore' => 4, 'blink' => 5, 'reverse' => 7, 'conceal' => 8),
$_foreground = array('black' => 30, 'red' => 31, 'green' => 32, 'yellow' => 33, 'blue' => 34, 'magenta' => 35, 'cyan' => 36, 'white' => 37),
$_background = array('black' => 40, 'red' => 41, 'green' => 42, 'yellow' => 43, 'blue' => 44, 'magenta' => 45, 'cyan' => 46, 'white' => 47);
/**
* Sets a new style.
*
* @param string The style name
* @param array An array of options
*/
public function setStyle($name, $options = array())
{
$this->styles[$name] = $options;
}
/**
* Formats a text according to the given style or parameters.
*
* @param string The test to style
* @param mixed An array of options or a style name
*
* @return string The styled text
*/
public function format($text = '', $parameters = array(), $stream = STDOUT)
{
if ( ! $this->supportsColors($stream))
/**
* Sets a new style.
*
* @param string The style name
* @param array An array of options
*/
public function setStyle($name, $options = array())
{
return $text;
$this->_styles[$name] = $options;
}
if ( ! is_array($parameters) && 'NONE' == $parameters)
/**
* Formats a text according to the given style or parameters.
*
* @param string The test to style
* @param mixed An array of options or a style name
*
* @return string The styled text
*/
public function format($text = '', $parameters = array(), $stream = STDOUT)
{
return $text;
}
if ( ! $this->supportsColors($stream)) {
return $text;
}
if ( ! is_array($parameters) && isset($this->styles[$parameters]))
{
$parameters = $this->styles[$parameters];
}
if ( ! is_array($parameters) && 'NONE' == $parameters) {
return $text;
}
$codes = array();
if (isset($parameters['fg']))
{
$codes[] = $this->foreground[$parameters['fg']];
}
if (isset($parameters['bg']))
{
$codes[] = $this->background[$parameters['bg']];
if ( ! is_array($parameters) && isset($this->_styles[$parameters])) {
$parameters = $this->_styles[$parameters];
}
$codes = array();
if (isset($parameters['fg'])) {
$codes[] = $this->_foreground[$parameters['fg']];
}
if (isset($parameters['bg'])) {
$codes[] = $this->_background[$parameters['bg']];
}
foreach ($this->_options as $option => $value) {
if (isset($parameters[$option]) && $parameters[$option]) {
$codes[] = $value;
}
}
return "\033[".implode(';', $codes).'m'.$text."\033[0m";
}
foreach ($this->options as $option => $value)
/**
* Formats a message within a section.
*
* @param string The section name
* @param string The text message
* @param integer The maximum size allowed for a line (65 by default)
*/
public function formatSection($section, $text, $size = null)
{
if (isset($parameters[$option]) && $parameters[$option])
{
$codes[] = $value;
}
$width = 9 + strlen($this->format('', 'INFO'));
return sprintf(">> %-${width}s %s", $this->format($section, 'INFO'), $this->excerpt($text, $size));
}
return "\033[".implode(';', $codes).'m'.$text."\033[0m";
}
/**
* Truncates a line.
*
* @param string The text
* @param integer The maximum size of the returned string (65 by default)
*
* @return string The truncated string
*/
public function excerpt($text, $size = null)
{
if ( ! $size) {
$size = $this->size;
}
/**
* Formats a message within a section.
*
* @param string The section name
* @param string The text message
* @param integer The maximum size allowed for a line (65 by default)
*/
public function formatSection($section, $text, $size = null)
{
$width = 9 + strlen($this->format('', 'INFO'));
if (strlen($text) < $size) {
return $text;
}
return sprintf(">> %-${width}s %s", $this->format($section, 'INFO'), $this->excerpt($text, $size));
}
$subsize = floor(($size - 3) / 2);
/**
* Truncates a line.
*
* @param string The text
* @param integer The maximum size of the returned string (65 by default)
*
* @return string The truncated string
*/
public function excerpt($text, $size = null)
{
if ( ! $size)
{
$size = $this->size;
return substr($text, 0, $subsize).$this->format('...', 'INFO').substr($text, -$subsize);
}
if (strlen($text) < $size)
/**
* Returns true if the stream supports colorization.
*
* Colorization is disabled if not supported by the stream:
*
* - windows
* - non tty consoles
*
* @param mixed A stream
*
* @return Boolean true if the stream supports colorization, false otherwise
*/
public function supportsColors($stream)
{
return $text;
return DIRECTORY_SEPARATOR != '\\' && function_exists('posix_isatty') && @posix_isatty($stream);
}
$subsize = floor(($size - 3) / 2);
return substr($text, 0, $subsize).$this->format('...', 'INFO').substr($text, -$subsize);
}
/**
* Returns true if the stream supports colorization.
*
* Colorization is disabled if not supported by the stream:
*
* - windows
* - non tty consoles
*
* @param mixed A stream
*
* @return Boolean true if the stream supports colorization, false otherwise
*/
public function supportsColors($stream)
{
return DIRECTORY_SEPARATOR != '\\' && function_exists('posix_isatty') && @posix_isatty($stream);
}
}
\ No newline at end of file
......@@ -37,72 +37,75 @@
*/
class Doctrine_Cli_Formatter
{
protected
$size = 65;
protected $_size = 65;
function __construct($maxLineSize = 65)
{
$this->size = $maxLineSize;
}
/**
* Formats a text according to the given parameters.
*
* @param string The test to style
* @param mixed An array of parameters
* @param stream A stream (default to STDOUT)
*
* @return string The formatted text
*/
public function format($text = '', $parameters = array(), $stream = STDOUT)
{
return $text;
}
/**
* Formats a message within a section.
*
* @param string The section name
* @param string The text message
* @param integer The maximum size allowed for a line (65 by default)
*/
public function formatSection($section, $text, $size = null)
{
return sprintf(">> %-$9s %s", $section, $this->excerpt($text, $size));
}
/**
* __construct
*
* @param string $maxLineSize
* @return void
*/
function __construct($maxLineSize = 65)
{
$this->_size = $maxLineSize;
}
/**
* Truncates a line.
*
* @param string The text
* @param integer The maximum size of the returned string (65 by default)
*
* @return string The truncated string
*/
public function excerpt($text, $size = null)
{
if ( ! $size)
/**
* Formats a text according to the given parameters.
*
* @param string The test to style
* @param mixed An array of parameters
* @param stream A stream (default to STDOUT)
*
* @return string The formatted text
*/
public function format($text = '', $parameters = array(), $stream = STDOUT)
{
$size = $this->size;
return $text;
}
if (strlen($text) < $size)
/**
* Formats a message within a section.
*
* @param string The section name
* @param string The text message
* @param integer The maximum size allowed for a line (65 by default)
*/
public function formatSection($section, $text, $size = null)
{
return $text;
return sprintf(">> %-$9s %s", $section, $this->excerpt($text, $size));
}
$subsize = floor(($size - 3) / 2);
/**
* Truncates a line.
*
* @param string The text
* @param integer The maximum size of the returned string (65 by default)
*
* @return string The truncated string
*/
public function excerpt($text, $size = null)
{
if ( ! $size) {
$size = $this->_size;
}
if (strlen($text) < $size) {
return $text;
}
$subsize = floor(($size - 3) / 2);
return substr($text, 0, $subsize).'...'.substr($text, -$subsize);
}
return substr($text, 0, $subsize).'...'.substr($text, -$subsize);
}
/**
* Sets the maximum line size.
*
* @param integer The maximum line size for a message
*/
public function setMaxLineSize($size)
{
$this->size = $size;
}
/**
* Sets the maximum line size.
*
* @param integer The maximum line size for a message
*/
public function setMaxLineSize($size)
{
$this->_size = $size;
}
}
\ No newline at end of file
......@@ -42,7 +42,7 @@ class Doctrine_Data
*
* @var string
*/
public $formats = array('csv', 'yml', 'xml');
protected $_formats = array('csv', 'yml', 'xml');
/**
* format
......@@ -51,7 +51,7 @@ class Doctrine_Data
*
* @var string
*/
public $format = 'yml';
protected $_format = 'yml';
/**
* directory
......@@ -60,7 +60,7 @@ class Doctrine_Data
*
* @var string
*/
public $directory = null;
protected $_directory = null;
/**
* models
......@@ -69,16 +69,16 @@ class Doctrine_Data
*
* @var string
*/
public $models = array();
protected $_models = array();
/**
* exportIndividualFiles
* _exportIndividualFiles
*
* whether or not to export data to individual files instead of 1
*
* @var string
*/
public $exportIndividualFiles = false;
protected $_exportIndividualFiles = false;
/**
* setFormat
......@@ -90,7 +90,7 @@ class Doctrine_Data
*/
public function setFormat($format)
{
$this->format = $format;
$this->_format = $format;
}
/**
......@@ -102,7 +102,7 @@ class Doctrine_Data
*/
public function getFormat()
{
return $this->format;
return $this->_format;
}
/**
......@@ -114,7 +114,7 @@ class Doctrine_Data
*/
public function getFormats()
{
return $this->formats;
return $this->_formats;
}
/**
......@@ -126,7 +126,7 @@ class Doctrine_Data
*/
public function setDirectory($directory)
{
$this->directory = $directory;
$this->_directory = $directory;
}
/**
......@@ -138,7 +138,7 @@ class Doctrine_Data
*/
public function getDirectory()
{
return $this->directory;
return $this->_directory;
}
/**
......@@ -151,7 +151,7 @@ class Doctrine_Data
*/
public function setModels($models)
{
$this->models = $models;
$this->_models = $models;
}
/**
......@@ -163,23 +163,23 @@ class Doctrine_Data
*/
public function getModels()
{
return $this->models;
return $this->_models;
}
/**
* exportIndividualFiles
* _exportIndividualFiles
*
* Set/Get whether or not to export individual files
*
* @return bool $exportIndividualFiles
* @return bool $_exportIndividualFiles
*/
public function exportIndividualFiles($bool = null)
{
if ($bool !== null) {
$this->exportIndividualFiles = $bool;
$this->_exportIndividualFiles = $bool;
}
return $this->exportIndividualFiles;
return $this->_exportIndividualFiles;
}
/**
......@@ -190,15 +190,15 @@ class Doctrine_Data
* @param string $directory
* @param string $format
* @param string $models
* @param string $exportIndividualFiles
* @param string $_exportIndividualFiles
* @return void
*/
public function exportData($directory, $format = 'yml', $models = array(), $exportIndividualFiles = false)
public function exportData($directory, $format = 'yml', $models = array(), $_exportIndividualFiles = false)
{
$export = new Doctrine_Data_Export($directory);
$export->setFormat($format);
$export->setModels($models);
$export->exportIndividualFiles($exportIndividualFiles);
$export->exportIndividualFiles($_exportIndividualFiles);
return $export->doExport();
}
......
......@@ -52,7 +52,7 @@ class Doctrine_Data_Import extends Doctrine_Data
*/
public function doImport()
{
$directory = $this->directory;
$directory = $this->getDirectory();
$array = array();
......
......@@ -43,23 +43,23 @@ class Doctrine_Import_Builder
*
* the path where imported files are being generated
*
* @var string $path
* @var string $_path
*/
private $path = '';
protected $_path = '';
/**
* packagesPrefix
*
* @var string
*/
private $packagesPrefix = 'Package';
protected $_packagesPrefix = 'Package';
/**
* packagesPath
*
* @var string
*/
private $packagesPath = '';
protected $_packagesPath = '';
/**
* suffix
......@@ -68,7 +68,7 @@ class Doctrine_Import_Builder
*
* @var string $suffix
*/
private $suffix = '.class.php';
protected $_suffix = '.class.php';
/**
* generateBaseClasses
......@@ -77,14 +77,14 @@ class Doctrine_Import_Builder
*
* @var string $suffix
*/
private $generateBaseClasses = true;
protected $_generateBaseClasses = true;
/**
* generateTableClasses
*
* @var string
*/
private $generateTableClasses = true;
protected $_generateTableClasses = true;
/**
* baseClassesDirectory
......@@ -93,23 +93,23 @@ class Doctrine_Import_Builder
*
* @var string $suffix
*/
private $baseClassesDirectory = 'generated';
protected $_baseClassesDirectory = 'generated';
/**
* baseClassName
*
* @var string
*/
private $baseClassName = 'Doctrine_Record';
protected $_baseClassName = 'Doctrine_Record';
/**
* tpl
*
* Class template used for writing classes
*
* @var $tpl
* @var $_tpl
*/
private static $tpl;
protected static $_tpl;
/**
* __construct
......@@ -131,11 +131,11 @@ class Doctrine_Import_Builder
{
Doctrine::makeDirectories($path);
if (!$this->packagesPath) {
$this->packagesPath = $path . DIRECTORY_SEPARATOR . 'packages';
if (!$this->_packagesPath) {
$this->_packagesPath = $path . DIRECTORY_SEPARATOR . 'packages';
}
$this->path = $path;
$this->_path = $path;
}
/**
......@@ -146,7 +146,7 @@ class Doctrine_Import_Builder
*/
public function setPackagesPrefix($packagesPrefix)
{
$this->packagesPrefix = $packagesPrefix;
$this->_packagesPrefix = $packagesPrefix;
}
/**
......@@ -157,7 +157,7 @@ class Doctrine_Import_Builder
*/
public function setPackagesPath($packagesPath)
{
$this->packagesPath = $packagesPath;
$this->_packagesPath = $packagesPath;
}
/**
......@@ -171,10 +171,10 @@ class Doctrine_Import_Builder
public function generateBaseClasses($bool = null)
{
if ($bool !== null) {
$this->generateBaseClasses = $bool;
$this->_generateBaseClasses = $bool;
}
return $this->generateBaseClasses;
return $this->_generateBaseClasses;
}
/**
......@@ -188,10 +188,10 @@ class Doctrine_Import_Builder
public function generateTableClasses($bool = null)
{
if ($bool !== null) {
$this->generateTableClasses = $bool;
$this->_generateTableClasses = $bool;
}
return $this->generateTableClasses;
return $this->_generateTableClasses;
}
/**
......@@ -201,7 +201,7 @@ class Doctrine_Import_Builder
*/
public function setBaseClassesDirectory($baseClassesDirectory)
{
$this->baseClassesDirectory;
$this->_baseClassesDirectory;
}
/**
......@@ -211,7 +211,7 @@ class Doctrine_Import_Builder
*/
public function setBaseClassName($className)
{
$this->baseClassName = $className;
$this->_baseClassName = $className;
}
/**
......@@ -222,7 +222,7 @@ class Doctrine_Import_Builder
*/
public function setSuffix($suffix)
{
$this->suffix = $suffix;
$this->_suffix = $suffix;
}
/**
......@@ -232,7 +232,7 @@ class Doctrine_Import_Builder
*/
public function getTargetPath()
{
return $this->path;
return $this->_path;
}
/**
......@@ -244,11 +244,11 @@ class Doctrine_Import_Builder
*/
public function loadTemplate()
{
if (isset(self::$tpl)) {
if (isset(self::$_tpl)) {
return;
}
self::$tpl =<<<END
self::$_tpl =<<<END
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
......@@ -651,7 +651,7 @@ END;
$abstract = isset($options['abstract']) && $options['abstract'] === true ? 'abstract ':null;
$className = $options['className'];
$extends = isset($options['inheritance']['extends']) ? $options['inheritance']['extends']:$this->baseClassName;
$extends = isset($options['inheritance']['extends']) ? $options['inheritance']['extends']:$this->_baseClassName;
if ( ! (isset($options['no_definition']) && $options['no_definition'] === true)) {
$definition = $this->buildTableDefinition($options, $columns, $relations, $indexes, $attributes, $templates, $actAs);
......@@ -663,7 +663,7 @@ END;
$accessors = (isset($options['generate_accessors']) && $options['generate_accessors'] === true) ? $this->buildAccessors($options, $columns):null;
$content = sprintf(self::$tpl, $abstract,
$content = sprintf(self::$_tpl, $abstract,
$className,
$extends,
$definition,
......@@ -708,7 +708,7 @@ END;
// If we have a package then we need to make this extend the package definition and not the base definition
// The package definition will then extends the base definition
$topLevel['inheritance']['extends'] = (isset($topLevel['package']) && $topLevel['package']) ? $this->packagesPrefix . $topLevel['className']:'Base' . $topLevel['className'];
$topLevel['inheritance']['extends'] = (isset($topLevel['package']) && $topLevel['package']) ? $this->_packagesPrefix . $topLevel['className']:'Base' . $topLevel['className'];
$topLevel['no_definition'] = true;
$topLevel['generate_once'] = true;
$topLevel['is_main_class'] = true;
......@@ -754,7 +754,7 @@ END;
$className = $className . 'Table';
$content = '<?php' . PHP_EOL;
$content .= sprintf(self::$tpl, false,
$content .= sprintf(self::$_tpl, false,
$className,
isset($options['extends']) ? $options['extends']:'Doctrine_Table',
null,
......@@ -764,7 +764,7 @@ END;
Doctrine::makeDirectories($path);
$writePath = $path . DIRECTORY_SEPARATOR . $className . $this->suffix;
$writePath = $path . DIRECTORY_SEPARATOR . $className . $this->_suffix;
if (!file_exists($writePath)) {
file_put_contents($writePath, $content);
......@@ -787,20 +787,20 @@ END;
{
$definition = $this->buildDefinition($options, $columns, $relations, $indexes, $attributes, $templates, $actAs);
$fileName = $options['className'] . $this->suffix;
$fileName = $options['className'] . $this->_suffix;
$packagesPath = $this->packagesPath ? $this->packagesPath:$this->path;
$packagesPath = $this->_packagesPath ? $this->_packagesPath:$this->_path;
// If this is a main class that either extends from Base or Package class
if (isset($options['is_main_class']) && $options['is_main_class']) {
// If is package then we need to put it in a package subfolder
if (isset($options['is_package']) && $options['is_package']) {
$writePath = $this->path . DIRECTORY_SEPARATOR . $options['package_name'];
$writePath = $this->_path . DIRECTORY_SEPARATOR . $options['package_name'];
$this->writeTableDefinition($options['className'], $writePath, array('extends' => $options['inheritance']['extends'] . 'Table'));
// Otherwise lets just put it in the root of the path
} else {
$writePath = $this->path;
$writePath = $this->_path;
$this->writeTableDefinition($options['className'], $writePath);
}
......@@ -819,10 +819,10 @@ END;
if (isset($options['is_base_class']) && $options['is_base_class']) {
// If it is a part of a package then we need to put it in a package subfolder
if (isset($options['is_package']) && $options['is_package']) {
$writePath = $this->path . DIRECTORY_SEPARATOR . $options['package_name'] . DIRECTORY_SEPARATOR . $this->baseClassesDirectory;
$writePath = $this->_path . DIRECTORY_SEPARATOR . $options['package_name'] . DIRECTORY_SEPARATOR . $this->_baseClassesDirectory;
// Otherwise lets just put it in the root generated folder
} else {
$writePath = $this->path . DIRECTORY_SEPARATOR . $this->baseClassesDirectory;
$writePath = $this->_path . DIRECTORY_SEPARATOR . $this->_baseClassesDirectory;
}
}
......@@ -831,9 +831,9 @@ END;
$writePath .= DIRECTORY_SEPARATOR . $fileName;
} else {
Doctrine::makeDirectories($this->path);
Doctrine::makeDirectories($this->_path);
$writePath = $this->path . DIRECTORY_SEPARATOR . $fileName;
$writePath = $this->_path . DIRECTORY_SEPARATOR . $fileName;
}
$code = "<?php" . PHP_EOL;
......
......@@ -39,14 +39,14 @@
*/
class Doctrine_Import_Schema
{
protected $relations = array();
protected $options = array('packagesPrefix' => 'Package',
'packagesPath' => '',
'generateBaseClasses' => true,
'generateTableClasses' => true,
'baseClassesDirectory' => 'generated',
'baseClassName' => 'Doctrine_Record',
'suffix' => '.class.php');
protected $_relations = array();
protected $_options = array('packagesPrefix' => 'Package',
'packagesPath' => '',
'generateBaseClasses' => true,
'generateTableClasses' => true,
'baseClassesDirectory' => 'generated',
'baseClassName' => 'Doctrine_Record',
'suffix' => '.class.php');
/**
* getOption
......@@ -56,8 +56,8 @@ class Doctrine_Import_Schema
*/
public function getOption($name)
{
if (isset($this->options[$name])) {
return $this->options[$name];
if (isset($this->_options[$name])) {
return $this->_options[$name];
}
}
......@@ -70,10 +70,21 @@ class Doctrine_Import_Schema
*/
public function setOption($name, $value)
{
if (isset($this->options[$name])) {
$this->options[$name] = $value;
if (isset($this->_options[$name])) {
$this->_options[$name] = $value;
}
}
/**
* setOptions
*
* @param string $options
* @return void
*/
public function setOptions($options)
{
$this->_options = $options;
}
/**
* buildSchema
......@@ -106,7 +117,7 @@ class Doctrine_Import_Schema
$this->buildRelationships($array);
return array('schema' => $array, 'relations' => $this->relations);
return array('schema' => $array, 'relations' => $this->_relations);
}
/**
......@@ -199,7 +210,7 @@ class Doctrine_Import_Schema
*/
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();
}
/**
......@@ -385,7 +396,7 @@ class Doctrine_Import_Schema
$relation['foreignType'] = $relation['foreignType'] === 'one' ? Doctrine_Relation::ONE:Doctrine_Relation::MANY;
}
$this->relations[$className][$alias] = $relation;
$this->_relations[$className][$alias] = $relation;
}
}
......@@ -402,7 +413,7 @@ class Doctrine_Import_Schema
*/
protected function fixRelationships()
{
foreach($this->relations as $className => $relations) {
foreach($this->_relations as $className => $relations) {
foreach ($relations AS $alias => $relation) {
$newRelation = array();
$newRelation['foreign'] = $relation['local'];
......@@ -421,8 +432,8 @@ class Doctrine_Import_Schema
}
}
if (!isset($this->relations[$relation['class']][$newRelation['alias']])) {
$this->relations[$relation['class']][$newRelation['alias']] = $newRelation;
if (!isset($this->_relations[$relation['class']][$newRelation['alias']])) {
$this->_relations[$relation['class']][$newRelation['alias']] = $newRelation;
}
}
}
......
......@@ -34,24 +34,23 @@
*/
class Doctrine_Migration
{
protected $changes = array('created_tables' => array(),
'renamed_tables' => array(),
'created_constraints' => array(),
'dropped_fks' => array(),
'created_fks' => array(),
'dropped_constraints' => array(),
'removed_indexes' => array(),
'dropped_tables' => array(),
'added_columns' => array(),
'renamed_columns' => array(),
'changed_columns' => array(),
'removed_columns' => array(),
'added_indexes' => array(),
),
$migrationTableName = 'migration_version',
$migrationClassesDirectory = array(),
$migrationClasses = array(),
$loadedMigrations = array();
protected $_changes = array('created_tables' => array(),
'renamed_tables' => array(),
'created_constraints' => array(),
'dropped_fks' => array(),
'created_fks' => array(),
'dropped_constraints' => array(),
'removed_indexes' => array(),
'dropped_tables' => array(),
'added_columns' => array(),
'renamed_columns' => array(),
'changed_columns' => array(),
'removed_columns' => array(),
'added_indexes' => array()),
$_migrationTableName = 'migration_version',
$_migrationClassesDirectory = array(),
$_migrationClasses = array(),
$_loadedMigrations = array();
/**
* construct
......@@ -65,7 +64,7 @@ class Doctrine_Migration
public function __construct($directory = null)
{
if ($directory != null) {
$this->migrationClassesDirectory = $directory;
$this->_migrationClassesDirectory = $directory;
$this->loadMigrationClasses();
......@@ -85,7 +84,7 @@ class Doctrine_Migration
$conn = Doctrine_Manager::connection();
try {
$conn->export->createTable($this->migrationTableName, array('version' => array('type' => 'integer', 'size' => 11)));
$conn->export->createTable($this->_migrationTableName, array('version' => array('type' => 'integer', 'size' => 11)));
return true;
} catch(Exception $e) {
......@@ -102,28 +101,28 @@ class Doctrine_Migration
*/
protected function loadMigrationClasses()
{
if ($this->migrationClasses) {
return $this->migrationClasses;
if ($this->_migrationClasses) {
return $this->_migrationClasses;
}
$classes = get_declared_classes();
if ($this->migrationClassesDirectory !== null) {
foreach ((array) $this->migrationClassesDirectory as $dir) {
if ($this->_migrationClassesDirectory !== null) {
foreach ((array) $this->_migrationClassesDirectory 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) {
if ( ! in_array($file->getFileName(), $this->loadedMigrations)) {
if ( ! in_array($file->getFileName(), $this->_loadedMigrations)) {
require_once($file->getPathName());
$requiredClass = array_diff(get_declared_classes(), $classes);
$requiredClass = end($requiredClass);
if ($requiredClass) {
$this->loadedMigrations[$requiredClass] = $file->getFileName();
$this->_loadedMigrations[$requiredClass] = $file->getFileName();
}
}
}
......@@ -133,7 +132,7 @@ class Doctrine_Migration
$parent = new ReflectionClass('Doctrine_Migration');
foreach ($this->loadedMigrations as $name => $fileName) {
foreach ($this->_loadedMigrations as $name => $fileName) {
$class = new ReflectionClass($name);
while ($class->isSubclassOf($parent)) {
......@@ -151,10 +150,10 @@ class Doctrine_Migration
$e = explode('_', $fileName);
$classMigrationNum = (int) $e[0];
$this->migrationClasses[$classMigrationNum] = array('className' => $name, 'fileName' => $fileName);
$this->_migrationClasses[$classMigrationNum] = array('className' => $name, 'fileName' => $fileName);
}
return $this->migrationClasses;
return $this->_migrationClasses;
}
/**
......@@ -164,7 +163,7 @@ class Doctrine_Migration
*/
public function getMigrationClasses()
{
return $this->migrationClasses;
return $this->_migrationClasses;
}
/**
......@@ -180,9 +179,9 @@ class Doctrine_Migration
$conn = Doctrine_Manager::connection();
if ($this->hasMigrated()) {
$conn->exec("UPDATE " . $this->migrationTableName . " SET version = $number");
$conn->exec("UPDATE " . $this->_migrationTableName . " SET version = $number");
} else {
$conn->exec("INSERT INTO " . $this->migrationTableName . " (version) VALUES ($number)");
$conn->exec("INSERT INTO " . $this->_migrationTableName . " (version) VALUES ($number)");
}
}
......@@ -197,7 +196,7 @@ class Doctrine_Migration
{
$conn = Doctrine_Manager::connection();
$result = $conn->fetchColumn("SELECT version FROM " . $this->migrationTableName);
$result = $conn->fetchColumn("SELECT version FROM " . $this->_migrationTableName);
return isset($result[0]) ? $result[0]:0;
}
......@@ -213,7 +212,7 @@ class Doctrine_Migration
{
$conn = Doctrine_Manager::connection();
$result = $conn->fetchColumn("SELECT version FROM " . $this->migrationTableName);
$result = $conn->fetchColumn("SELECT version FROM " . $this->_migrationTableName);
return isset($result[0]) ? true:false;
}
......@@ -230,7 +229,7 @@ class Doctrine_Migration
$this->loadMigrationClasses();
$versions = array();
foreach (array_keys($this->migrationClasses) as $classMigrationNum) {
foreach (array_keys($this->_migrationClasses) as $classMigrationNum) {
$versions[$classMigrationNum] = $classMigrationNum;
}
......@@ -259,7 +258,7 @@ class Doctrine_Migration
*/
protected function getMigrationClass($num)
{
foreach ($this->migrationClasses as $classMigrationNum => $info) {
foreach ($this->_migrationClasses as $classMigrationNum => $info) {
$className = $info['className'];
if ($classMigrationNum == $num) {
......@@ -299,7 +298,7 @@ class Doctrine_Migration
if (method_exists($this, $direction)) {
$this->$direction();
foreach ($this->changes as $type => $changes) {
foreach ($this->_changes as $type => $changes) {
$process = new Doctrine_Migration_Process();
$funcName = 'process' . Doctrine::classify($type);
......@@ -359,7 +358,7 @@ class Doctrine_Migration
*/
protected function addChange($type, array $change = array())
{
$this->changes[$type][] = $change;
$this->_changes[$type][] = $change;
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment