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

Formatting/standards changes.

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