mirror of
https://github.com/atlanticbiomedical/portal-legacy.git
synced 2025-07-02 01:47:28 -04:00
initial commit
This commit is contained in:
458
lib/symfony/vendor/pake/pakeApp.class.php
vendored
Executable file
458
lib/symfony/vendor/pake/pakeApp.class.php
vendored
Executable file
@ -0,0 +1,458 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package pake
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @copyright 2004-2005 Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @license see the LICENSE file included in the distribution
|
||||
* @version SVN: $Id: pakeApp.class.php 4623 2007-07-16 12:34:38Z fabien $
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* main pake class.
|
||||
*
|
||||
* This class is a singleton.
|
||||
*
|
||||
* @package pake
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @copyright 2004-2005 Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @license see the LICENSE file included in the distribution
|
||||
* @version SVN: $Id: pakeApp.class.php 4623 2007-07-16 12:34:38Z fabien $
|
||||
*/
|
||||
class pakeApp
|
||||
{
|
||||
const VERSION = '1.1.DEV';
|
||||
|
||||
private static $MAX_LINE_SIZE = 65;
|
||||
private static $PROPERTIES = array();
|
||||
private static $PAKEFILES = array('pakefile', 'Pakefile', 'pakefile.php', 'Pakefile.php');
|
||||
private static $PLUGINDIRS = array();
|
||||
private static $OPTIONS = array(
|
||||
array('--dry-run', '-n', pakeGetopt::NO_ARGUMENT, "Do a dry run without executing actions."),
|
||||
array('--help', '-H', pakeGetopt::NO_ARGUMENT, "Display this help message."),
|
||||
array('--libdir', '-I', pakeGetopt::REQUIRED_ARGUMENT, "Include LIBDIR in the search path for required modules."),
|
||||
array('--nosearch', '-N', pakeGetopt::NO_ARGUMENT, "Do not search parent directories for the pakefile."),
|
||||
array('--prereqs', '-P', pakeGetopt::NO_ARGUMENT, "Display the tasks and dependencies, then exit."),
|
||||
array('--quiet', '-q', pakeGetopt::NO_ARGUMENT, "Do not log messages to standard output."),
|
||||
array('--pakefile', '-f', pakeGetopt::REQUIRED_ARGUMENT, "Use FILE as the pakefile."),
|
||||
array('--require', '-r', pakeGetopt::REQUIRED_ARGUMENT, "Require MODULE before executing pakefile."),
|
||||
array('--tasks', '-T', pakeGetopt::NO_ARGUMENT, "Display the tasks and dependencies, then exit."),
|
||||
array('--trace', '-t', pakeGetopt::NO_ARGUMENT, "Turn on invoke/execute tracing, enable full backtrace."),
|
||||
array('--usage', '-h', pakeGetopt::NO_ARGUMENT, "Display usage."),
|
||||
array('--verbose', '-v', pakeGetopt::NO_ARGUMENT, "Log message to standard output (default)."),
|
||||
array('--version', '-V', pakeGetopt::NO_ARGUMENT, "Display the program version."),
|
||||
);
|
||||
|
||||
private $opt = null;
|
||||
private $nosearch = false;
|
||||
private $trace = false;
|
||||
private $verbose = true;
|
||||
private $dryrun = false;
|
||||
private $nowrite = false;
|
||||
private $show_tasks = false;
|
||||
private $show_prereqs = false;
|
||||
private $pakefile = '';
|
||||
private static $instance = null;
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
self::$PLUGINDIRS[] = dirname(__FILE__).'/tasks';
|
||||
}
|
||||
|
||||
public static function get_plugin_dirs()
|
||||
{
|
||||
return self::$PLUGINDIRS;
|
||||
}
|
||||
|
||||
public function get_properties()
|
||||
{
|
||||
return self::$PROPERTIES;
|
||||
}
|
||||
|
||||
public function set_properties($properties)
|
||||
{
|
||||
self::$PROPERTIES = $properties;
|
||||
}
|
||||
|
||||
public static function get_instance()
|
||||
{
|
||||
if (!self::$instance) self::$instance = new pakeApp();
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public function get_verbose()
|
||||
{
|
||||
return $this->verbose;
|
||||
}
|
||||
|
||||
public function get_trace()
|
||||
{
|
||||
return $this->trace;
|
||||
}
|
||||
|
||||
public function get_dryrun()
|
||||
{
|
||||
return $this->dryrun;
|
||||
}
|
||||
|
||||
public function run($pakefile = null, $options = null, $load_pakefile = true)
|
||||
{
|
||||
if ($pakefile)
|
||||
{
|
||||
pakeApp::$PAKEFILES = array($pakefile);
|
||||
}
|
||||
|
||||
$this->handle_options($options);
|
||||
if ($load_pakefile)
|
||||
{
|
||||
$this->load_pakefile();
|
||||
}
|
||||
|
||||
if ($this->show_tasks)
|
||||
{
|
||||
$this->display_tasks_and_comments();
|
||||
}
|
||||
else if ($this->show_prereqs)
|
||||
{
|
||||
$this->display_prerequisites();
|
||||
}
|
||||
else
|
||||
{
|
||||
$args = $this->opt->get_arguments();
|
||||
$task = array_shift($args);
|
||||
|
||||
$options = array();
|
||||
for ($i = 0, $max = count($args); $i < $max; $i++)
|
||||
{
|
||||
if (0 === strpos($args[$i], '--'))
|
||||
{
|
||||
if (false !== $pos = strpos($args[$i], '='))
|
||||
{
|
||||
$key = substr($args[$i], 2, $pos - 2);
|
||||
$value = substr($args[$i], $pos + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
$key = substr($args[$i], 2);
|
||||
$value = true;
|
||||
}
|
||||
if ('[]' == substr($key, -2))
|
||||
{
|
||||
if (!isset($options[$key]))
|
||||
{
|
||||
$options[$key] = array();
|
||||
}
|
||||
$options[$key][] = $value;
|
||||
}
|
||||
else
|
||||
{
|
||||
$options[$key] = $value;
|
||||
}
|
||||
unset($args[$i]);
|
||||
}
|
||||
}
|
||||
$args = array_values($args);
|
||||
|
||||
$abbrev_options = $this->abbrev(array_keys(pakeTask::get_tasks()));
|
||||
$task = pakeTask::get_full_task_name($task);
|
||||
if (!$task)
|
||||
{
|
||||
$task = 'default';
|
||||
}
|
||||
|
||||
if (!array_key_exists($task, $abbrev_options))
|
||||
{
|
||||
throw new pakeException(sprintf('Task "%s" is not defined.', $task));
|
||||
}
|
||||
else if (count($abbrev_options[$task]) > 1)
|
||||
{
|
||||
throw new pakeException(sprintf('Task "%s" is ambiguous (%s).', $task, implode(', ', $abbrev_options[$task])));
|
||||
}
|
||||
else
|
||||
{
|
||||
return pakeTask::get($abbrev_options[$task][0])->invoke($args, $options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Read and handle the command line options.
|
||||
public function handle_options($options = null)
|
||||
{
|
||||
$this->opt = new pakeGetopt(pakeApp::$OPTIONS);
|
||||
$this->opt->parse($options);
|
||||
foreach ($this->opt->get_options() as $opt => $value)
|
||||
{
|
||||
$this->do_option($opt, $value);
|
||||
}
|
||||
}
|
||||
|
||||
// True if one of the files in RAKEFILES is in the current directory.
|
||||
// If a match is found, it is copied into @pakefile.
|
||||
public function have_pakefile()
|
||||
{
|
||||
foreach (pakeApp::$PAKEFILES as $file)
|
||||
{
|
||||
if (file_exists($file))
|
||||
{
|
||||
$this->pakefile = $file;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function load_pakefile()
|
||||
{
|
||||
$here = getcwd();
|
||||
while (!$this->have_pakefile())
|
||||
{
|
||||
chdir('..');
|
||||
if (getcwd() == $here || $this->nosearch)
|
||||
{
|
||||
throw new pakeException(sprintf('No pakefile found (looking for: %s)', join(', ', pakeApp::$PAKEFILES))."\n");
|
||||
}
|
||||
|
||||
$here = getcwd();
|
||||
}
|
||||
|
||||
require_once($this->pakefile);
|
||||
}
|
||||
|
||||
// Do the option defined by +opt+ and +value+.
|
||||
public function do_option($opt, $value)
|
||||
{
|
||||
switch ($opt)
|
||||
{
|
||||
case 'dry-run':
|
||||
$this->verbose = true;
|
||||
$this->nowrite = true;
|
||||
$this->dryrun = true;
|
||||
$this->trace = true;
|
||||
break;
|
||||
case 'help':
|
||||
$this->help();
|
||||
exit();
|
||||
case 'libdir':
|
||||
set_include_path($value.PATH_SEPARATOR.get_include_path());
|
||||
break;
|
||||
case 'nosearch':
|
||||
$this->nosearch = true;
|
||||
break;
|
||||
case 'prereqs':
|
||||
$this->show_prereqs = true;
|
||||
break;
|
||||
case 'quiet':
|
||||
$this->verbose = false;
|
||||
break;
|
||||
case 'pakefile':
|
||||
pakeApp::$PAKEFILES = array($value);
|
||||
break;
|
||||
case 'require':
|
||||
require $value;
|
||||
break;
|
||||
case 'tasks':
|
||||
$this->show_tasks = true;
|
||||
break;
|
||||
case 'trace':
|
||||
$this->trace = true;
|
||||
$this->verbose = true;
|
||||
break;
|
||||
case 'usage':
|
||||
$this->usage();
|
||||
exit();
|
||||
case 'verbose':
|
||||
$this->verbose = true;
|
||||
break;
|
||||
case 'version':
|
||||
echo sprintf('pake version %s', pakeColor::colorize(pakeApp::VERSION, 'INFO'))."\n";
|
||||
exit();
|
||||
default:
|
||||
throw new pakeException(sprintf("Unknown option: %s", $opt));
|
||||
}
|
||||
}
|
||||
|
||||
// Display the program usage line.
|
||||
public function usage()
|
||||
{
|
||||
echo "pake [-f pakefile] {options} targets...\n".pakeColor::colorize("Try pake -H for more information", 'INFO')."\n";
|
||||
}
|
||||
|
||||
// Display the rake command line help.
|
||||
public function help()
|
||||
{
|
||||
$this->usage();
|
||||
echo "\n";
|
||||
echo "available options:";
|
||||
echo "\n";
|
||||
|
||||
foreach (pakeApp::$OPTIONS as $option)
|
||||
{
|
||||
list($long, $short, $mode, $comment) = $option;
|
||||
if ($mode == pakeGetopt::REQUIRED_ARGUMENT)
|
||||
{
|
||||
if (preg_match('/\b([A-Z]{2,})\b/', $comment, $match))
|
||||
$long .= '='.$match[1];
|
||||
}
|
||||
printf(" %-20s (%s)\n", pakeColor::colorize($long, 'INFO'), pakeColor::colorize($short, 'INFO'));
|
||||
printf(" %s\n", $comment);
|
||||
}
|
||||
}
|
||||
|
||||
// Display the tasks and dependencies.
|
||||
public function display_tasks_and_comments()
|
||||
{
|
||||
$width = 0;
|
||||
$tasks = pakeTask::get_tasks();
|
||||
foreach ($tasks as $name => $task)
|
||||
{
|
||||
$w = strlen(pakeTask::get_mini_task_name($name));
|
||||
if ($w > $width) $width = $w;
|
||||
}
|
||||
$width += strlen(pakeColor::colorize(' ', 'INFO'));
|
||||
|
||||
echo "available pake tasks:\n";
|
||||
|
||||
// display tasks
|
||||
$has_alias = false;
|
||||
ksort($tasks);
|
||||
foreach ($tasks as $name => $task)
|
||||
{
|
||||
if ($task->get_alias())
|
||||
{
|
||||
$has_alias = true;
|
||||
}
|
||||
|
||||
if (!$task->get_alias() && $task->get_comment())
|
||||
{
|
||||
$mini_name = pakeTask::get_mini_task_name($name);
|
||||
printf(' %-'.$width.'s > %s'."\n", pakeColor::colorize($mini_name, 'INFO'), $task->get_comment().($mini_name != $name ? ' ['.$name.']' : ''));
|
||||
}
|
||||
}
|
||||
|
||||
if ($has_alias)
|
||||
{
|
||||
print("\ntask aliases:\n");
|
||||
|
||||
// display aliases
|
||||
foreach ($tasks as $name => $task)
|
||||
{
|
||||
if ($task->get_alias())
|
||||
{
|
||||
$mini_name = pakeTask::get_mini_task_name($name);
|
||||
printf(' %-'.$width.'s = pake %s'."\n", pakeColor::colorize(pakeTask::get_mini_task_name($name), 'INFO'), $task->get_alias().($mini_name != $name ? ' ['.$name.']' : ''));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Display the tasks and prerequisites
|
||||
public function display_prerequisites()
|
||||
{
|
||||
foreach (pakeTask::get_tasks() as $name => $task)
|
||||
{
|
||||
echo "pake ".pakeTask::get_mini_task_name($name)."\n";
|
||||
foreach ($task->get_prerequisites() as $prerequisite)
|
||||
{
|
||||
echo " $prerequisite\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function get_files_from_argument($arg, $target_dir = '', $relative = false)
|
||||
{
|
||||
$files = array();
|
||||
if (is_array($arg))
|
||||
{
|
||||
$files = $arg;
|
||||
}
|
||||
else if (is_string($arg))
|
||||
{
|
||||
$files[] = $arg;
|
||||
}
|
||||
else if ($arg instanceof pakeFinder)
|
||||
{
|
||||
$files = $arg->in($target_dir);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new pakeException('Wrong argument type (must be a list, a string or a pakeFinder object).');
|
||||
}
|
||||
|
||||
if ($relative && $target_dir)
|
||||
{
|
||||
$files = preg_replace('/^'.preg_quote(realpath($target_dir), '/').'/', '', $files);
|
||||
|
||||
// remove leading /
|
||||
$files = array_map(create_function('$f', 'return 0 === strpos($f, DIRECTORY_SEPARATOR) ? substr($f, 1) : $f;'), $files);
|
||||
}
|
||||
|
||||
return $files;
|
||||
}
|
||||
|
||||
public static function excerpt($text, $size = null)
|
||||
{
|
||||
if (!$size)
|
||||
{
|
||||
$size = self::$MAX_LINE_SIZE;
|
||||
}
|
||||
|
||||
if (strlen($text) < $size)
|
||||
{
|
||||
return $text;
|
||||
}
|
||||
|
||||
$subsize = floor(($size - 3) / 2);
|
||||
|
||||
return substr($text, 0, $subsize).pakeColor::colorize('...', 'INFO').substr($text, -$subsize);
|
||||
}
|
||||
|
||||
/* see perl Text::Abbrev module */
|
||||
private function abbrev($options)
|
||||
{
|
||||
$abbrevs = array();
|
||||
$table = array();
|
||||
|
||||
foreach ($options as $option)
|
||||
{
|
||||
$option = pakeTask::get_mini_task_name($option);
|
||||
|
||||
for ($len = (strlen($option)) - 1; $len > 0; --$len)
|
||||
{
|
||||
$abbrev = substr($option, 0, $len);
|
||||
if (!array_key_exists($abbrev, $table))
|
||||
$table[$abbrev] = 1;
|
||||
else
|
||||
++$table[$abbrev];
|
||||
|
||||
$seen = $table[$abbrev];
|
||||
if ($seen == 1)
|
||||
{
|
||||
// we're the first word so far to have this abbreviation.
|
||||
$abbrevs[$abbrev] = array($option);
|
||||
}
|
||||
else if ($seen == 2)
|
||||
{
|
||||
// we're the second word to have this abbreviation, so we can't use it.
|
||||
//unset($abbrevs[$abbrev]);
|
||||
$abbrevs[$abbrev][] = $option;
|
||||
}
|
||||
else
|
||||
{
|
||||
// we're the third word to have this abbreviation, so skip to the next word.
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Non-abbreviations always get entered, even if they aren't unique
|
||||
foreach ($options as $option)
|
||||
{
|
||||
$abbrevs[$option] = array($option);
|
||||
}
|
||||
|
||||
return $abbrevs;
|
||||
}
|
||||
}
|
72
lib/symfony/vendor/pake/pakeColor.class.php
vendored
Executable file
72
lib/symfony/vendor/pake/pakeColor.class.php
vendored
Executable file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package pake
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @copyright 2004-2005 Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @license see the LICENSE file included in the distribution
|
||||
* @version SVN: $Id: pakeColor.class.php 2990 2006-12-09 11:10:59Z fabien $
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* main pake class.
|
||||
*
|
||||
* This class is a singleton.
|
||||
*
|
||||
* @package pake
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @copyright 2004-2005 Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @license see the LICENSE file included in the distribution
|
||||
* @version SVN: $Id: pakeColor.class.php 2990 2006-12-09 11:10:59Z fabien $
|
||||
*/
|
||||
class pakeColor
|
||||
{
|
||||
static public $styles = array();
|
||||
|
||||
static function style($name, $options = array())
|
||||
{
|
||||
self::$styles[$name] = $options;
|
||||
}
|
||||
|
||||
static function colorize($text = '', $parameters = array(), $stream = STDOUT)
|
||||
{
|
||||
// disable colors if not supported (windows or non tty console)
|
||||
if (DIRECTORY_SEPARATOR == '\\' || !function_exists('posix_isatty') || !@posix_isatty($stream))
|
||||
{
|
||||
return $text;
|
||||
}
|
||||
|
||||
static $options = array('bold' => 1, 'underscore' => 4, 'blink' => 5, 'reverse' => 7, 'conceal' => 8);
|
||||
static $foreground = array('black' => 30, 'red' => 31, 'green' => 32, 'yellow' => 33, 'blue' => 34, 'magenta' => 35, 'cyan' => 36, 'white' => 37);
|
||||
static $background = array('black' => 40, 'red' => 41, 'green' => 42, 'yellow' => 43, 'blue' => 44, 'magenta' => 45, 'cyan' => 46, 'white' => 47);
|
||||
|
||||
if (!is_array($parameters) && isset(self::$styles[$parameters]))
|
||||
{
|
||||
$parameters = self::$styles[$parameters];
|
||||
}
|
||||
|
||||
$codes = array();
|
||||
if (isset($parameters['fg']))
|
||||
{
|
||||
$codes[] = $foreground[$parameters['fg']];
|
||||
}
|
||||
if (isset($parameters['bg']))
|
||||
{
|
||||
$codes[] = $background[$parameters['bg']];
|
||||
}
|
||||
foreach ($options as $option => $value)
|
||||
{
|
||||
if (isset($parameters[$option]) && $parameters[$option])
|
||||
{
|
||||
$codes[] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return "\033[".implode(';', $codes).'m'.$text."\033[0m";
|
||||
}
|
||||
}
|
||||
|
||||
pakeColor::style('ERROR', array('bg' => 'red', 'fg' => 'white', 'bold' => true));
|
||||
pakeColor::style('INFO', array('fg' => 'green', 'bold' => true));
|
||||
pakeColor::style('COMMENT', array('fg' => 'yellow'));
|
91
lib/symfony/vendor/pake/pakeException.class.php
vendored
Executable file
91
lib/symfony/vendor/pake/pakeException.class.php
vendored
Executable file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the pake package.
|
||||
* (c) 2004, 2005 Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* pakeException is the base class for all pake related exceptions and
|
||||
* provides an additional method for printing up a detailed view of an
|
||||
* exception.
|
||||
*
|
||||
* @package pake
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @version SVN: $Id: pakeException.class.php 2795 2006-11-23 19:51:21Z fabien $
|
||||
*/
|
||||
class pakeException extends Exception
|
||||
{
|
||||
public static function strlen($string)
|
||||
{
|
||||
return function_exists('mb_strlen') ? mb_strlen($string) : strlen($string);
|
||||
}
|
||||
|
||||
function render($e)
|
||||
{
|
||||
$title = ' ['.get_class($e).'] ';
|
||||
$len = self::strlen($title);
|
||||
$lines = array();
|
||||
foreach (explode("\n", $e->getMessage()) as $line)
|
||||
{
|
||||
$lines[] = ' '.$line.' ';
|
||||
$len = max(self::strlen($line) + 4, $len);
|
||||
}
|
||||
$messages = array(
|
||||
str_repeat(' ', $len),
|
||||
$title.str_repeat(' ', $len - self::strlen($title)),
|
||||
);
|
||||
|
||||
foreach ($lines as $line)
|
||||
{
|
||||
$messages[] = $line.str_repeat(' ', $len - self::strlen($line));
|
||||
}
|
||||
|
||||
$messages[] = str_repeat(' ', $len);
|
||||
|
||||
fwrite(STDERR, "\n");
|
||||
foreach ($messages as $message)
|
||||
{
|
||||
fwrite(STDERR, pakeColor::colorize($message, 'ERROR', STDERR)."\n");
|
||||
}
|
||||
fwrite(STDERR, "\n");
|
||||
|
||||
$pake = pakeApp::get_instance();
|
||||
|
||||
if ($pake->get_trace())
|
||||
{
|
||||
fwrite(STDERR, "exception trace:\n");
|
||||
|
||||
$trace = $this->trace($e);
|
||||
for ($i = 0, $count = count($trace); $i < $count; $i++)
|
||||
{
|
||||
$class = (isset($trace[$i]['class']) ? $trace[$i]['class'] : '');
|
||||
$type = (isset($trace[$i]['type']) ? $trace[$i]['type'] : '');
|
||||
$function = $trace[$i]['function'];
|
||||
$file = isset($trace[$i]['file']) ? $trace[$i]['file'] : 'n/a';
|
||||
$line = isset($trace[$i]['line']) ? $trace[$i]['line'] : 'n/a';
|
||||
|
||||
fwrite(STDERR, sprintf(" %s%s%s at %s:%s\n", $class, $type, $function, pakeColor::colorize($file, 'INFO', STDERR), pakeColor::colorize($line, 'INFO', STDERR)));
|
||||
}
|
||||
}
|
||||
|
||||
fwrite(STDERR, "\n");
|
||||
}
|
||||
|
||||
function trace($exception)
|
||||
{
|
||||
// exception related properties
|
||||
$trace = $exception->getTrace();
|
||||
array_unshift($trace, array(
|
||||
'function' => '',
|
||||
'file' => ($exception->getFile() != null) ? $exception->getFile() : 'n/a',
|
||||
'line' => ($exception->getLine() != null) ? $exception->getLine() : 'n/a',
|
||||
'args' => array(),
|
||||
));
|
||||
|
||||
return $trace;
|
||||
}
|
||||
}
|
64
lib/symfony/vendor/pake/pakeFileTask.class.php
vendored
Executable file
64
lib/symfony/vendor/pake/pakeFileTask.class.php
vendored
Executable file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package pake
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @copyright 2004-2005 Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @license see the LICENSE file included in the distribution
|
||||
* @version SVN: $Id: pakeFileTask.class.php 1791 2006-08-23 21:17:06Z fabien $
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* .
|
||||
*
|
||||
* .
|
||||
*
|
||||
* @package pake
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @copyright 2004-2005 Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @license see the LICENSE file included in the distribution
|
||||
* @version SVN: $Id: pakeFileTask.class.php 1791 2006-08-23 21:17:06Z fabien $
|
||||
*/
|
||||
class pakeFileTask extends pakeTask
|
||||
{
|
||||
public function is_needed()
|
||||
{
|
||||
if (!file_exists($this->get_name())) return true;
|
||||
$latest_prereq = 0;
|
||||
foreach ($this->prerequisites as $prerequisite)
|
||||
{
|
||||
$t = pakeTask::get($prerequisite)->timestamp();
|
||||
if ($t > $latest_prereq)
|
||||
{
|
||||
$latest_prereq = $t;
|
||||
}
|
||||
}
|
||||
|
||||
if ($latest_prereq == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return ($this->timestamp() < $latest_prereq);
|
||||
}
|
||||
|
||||
public function timestamp()
|
||||
{
|
||||
if (!file_exists($this->get_name()))
|
||||
{
|
||||
throw new pakeException(sprintf('File "%s" does not exist!', $this->get_name()));
|
||||
}
|
||||
|
||||
$stats = stat($this->get_name());
|
||||
|
||||
return $stats['mtime'];
|
||||
}
|
||||
|
||||
public static function define_task($name, $deps = null)
|
||||
{
|
||||
$task = pakeTask::lookup($name, 'pakeFileTask');
|
||||
$task->add_comment();
|
||||
$task->enhance($deps);
|
||||
}
|
||||
}
|
538
lib/symfony/vendor/pake/pakeFinder.class.php
vendored
Executable file
538
lib/symfony/vendor/pake/pakeFinder.class.php
vendored
Executable file
@ -0,0 +1,538 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package pake
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @copyright 2004-2005 Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @license see the LICENSE file included in the distribution
|
||||
* @version SVN: $Id: pakeFinder.class.php 3268 2007-01-13 20:19:33Z fabien $
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__).'/pakeGlobToRegex.class.php';
|
||||
require_once dirname(__FILE__).'/pakeNumberCompare.class.php';
|
||||
|
||||
if (class_exists('pakeFinder'))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Allow to build rules to find files and directories.
|
||||
*
|
||||
* All rules may be invoked several times, except for ->in() method.
|
||||
* Some rules are cumulative (->name() for example) whereas others are destructive
|
||||
* (most recent value is used, ->maxdepth() method for example).
|
||||
*
|
||||
* All methods return the current pakeFinder object to allow easy chaining:
|
||||
*
|
||||
* $files = pakeFinder::type('file')->name('*.php')->in(.);
|
||||
*
|
||||
* Interface loosely based on perl File::Find::Rule module.
|
||||
*
|
||||
* @package pake
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @copyright 2004-2005 Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @license see the LICENSE file included in the distribution
|
||||
* @version SVN: $Id: pakeFinder.class.php 3268 2007-01-13 20:19:33Z fabien $
|
||||
*/
|
||||
class pakeFinder
|
||||
{
|
||||
private $type = 'file';
|
||||
private $names = array();
|
||||
private $prunes = array();
|
||||
private $discards = array();
|
||||
private $execs = array();
|
||||
private $mindepth = 0;
|
||||
private $sizes = array();
|
||||
private $maxdepth = 1000000;
|
||||
private $relative = false;
|
||||
private $follow_link = false;
|
||||
private $search_dir = '';
|
||||
|
||||
/**
|
||||
* Sets maximum directory depth.
|
||||
*
|
||||
* Finder will descend at most $level levels of directories below the starting point.
|
||||
*
|
||||
* @param integer level
|
||||
* @return object current pakeFinder object
|
||||
*/
|
||||
public function maxdepth($level)
|
||||
{
|
||||
$this->maxdepth = $level;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets minimum directory depth.
|
||||
*
|
||||
* Finder will start applying tests at level $level.
|
||||
*
|
||||
* @param integer level
|
||||
* @return object current pakeFinder object
|
||||
*/
|
||||
public function mindepth($level)
|
||||
{
|
||||
$this->mindepth = $level;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function get_type()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the type of elements to returns.
|
||||
*
|
||||
* @param string directory or file or any (for both file and directory)
|
||||
* @return object new pakeFinder object
|
||||
*/
|
||||
public static function type($name)
|
||||
{
|
||||
$finder = new pakeFinder();
|
||||
|
||||
if (strtolower(substr($name, 0, 3)) == 'dir')
|
||||
{
|
||||
$finder->type = 'directory';
|
||||
}
|
||||
else if (strtolower($name) == 'any')
|
||||
{
|
||||
$finder->type = 'any';
|
||||
}
|
||||
else
|
||||
{
|
||||
$finder->type = 'file';
|
||||
}
|
||||
|
||||
return $finder;
|
||||
}
|
||||
|
||||
/*
|
||||
* glob, patterns (must be //) or strings
|
||||
*/
|
||||
private function to_regex($str)
|
||||
{
|
||||
if ($str[0] == '/' && $str[strlen($str) - 1] == '/')
|
||||
{
|
||||
return $str;
|
||||
}
|
||||
else
|
||||
{
|
||||
return pakeGlobToRegex::glob_to_regex($str);
|
||||
}
|
||||
}
|
||||
|
||||
private function args_to_array($arg_list, $not = false)
|
||||
{
|
||||
$list = array();
|
||||
|
||||
for ($i = 0; $i < count($arg_list); $i++)
|
||||
{
|
||||
if (is_array($arg_list[$i]))
|
||||
{
|
||||
foreach ($arg_list[$i] as $arg)
|
||||
{
|
||||
$list[] = array($not, $this->to_regex($arg));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$list[] = array($not, $this->to_regex($arg_list[$i]));
|
||||
}
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds rules that files must match.
|
||||
*
|
||||
* You can use patterns (delimited with / sign), globs or simple strings.
|
||||
*
|
||||
* $finder->name('*.php')
|
||||
* $finder->name('/\.php$/') // same as above
|
||||
* $finder->name('test.php')
|
||||
*
|
||||
* @param list a list of patterns, globs or strings
|
||||
* @return object current pakeFinder object
|
||||
*/
|
||||
public function name()
|
||||
{
|
||||
$args = func_get_args();
|
||||
$this->names = array_merge($this->names, $this->args_to_array($args));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds rules that files must not match.
|
||||
*
|
||||
* @see ->name()
|
||||
* @param list a list of patterns, globs or strings
|
||||
* @return object current pakeFinder object
|
||||
*/
|
||||
public function not_name()
|
||||
{
|
||||
$args = func_get_args();
|
||||
$this->names = array_merge($this->names, $this->args_to_array($args, true));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds tests for file sizes.
|
||||
*
|
||||
* $finder->size('> 10K');
|
||||
* $finder->size('<= 1Ki');
|
||||
* $finder->size(4);
|
||||
*
|
||||
* @param list a list of comparison strings
|
||||
* @return object current pakeFinder object
|
||||
*/
|
||||
public function size()
|
||||
{
|
||||
$args = func_get_args();
|
||||
for ($i = 0; $i < count($args); $i++)
|
||||
{
|
||||
$this->sizes[] = new pakeNumberCompare($args[$i]);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Traverses no further.
|
||||
*
|
||||
* @param list a list of patterns, globs to match
|
||||
* @return object current pakeFinder object
|
||||
*/
|
||||
public function prune()
|
||||
{
|
||||
$args = func_get_args();
|
||||
$this->prunes = array_merge($this->prunes, $this->args_to_array($args));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Discards elements that matches.
|
||||
*
|
||||
* @param list a list of patterns, globs to match
|
||||
* @return object current pakeFinder object
|
||||
*/
|
||||
public function discard()
|
||||
{
|
||||
$args = func_get_args();
|
||||
$this->discards = array_merge($this->discards, $this->args_to_array($args));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ignores version control directories.
|
||||
*
|
||||
* Currently supports subversion, CVS, DARCS, Gnu Arch, Monotone, Bazaar-NG
|
||||
*
|
||||
* @return object current pakeFinder object
|
||||
*/
|
||||
public function ignore_version_control()
|
||||
{
|
||||
$ignores = array('.svn', 'CVS', '_darcs', '.arch-params', '.monotone', '.bzr');
|
||||
|
||||
return $this->discard($ignores)->prune($ignores);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes function or method for each element.
|
||||
*
|
||||
* Element match if functino or method returns true.
|
||||
*
|
||||
* $finder->exec('myfunction');
|
||||
* $finder->exec(array($object, 'mymethod'));
|
||||
*
|
||||
* @param mixed function or method to call
|
||||
* @return object current pakeFinder object
|
||||
*/
|
||||
public function exec()
|
||||
{
|
||||
$args = func_get_args();
|
||||
for ($i = 0; $i < count($args); $i++)
|
||||
{
|
||||
if (is_array($args[$i]) && !method_exists($args[$i][0], $args[$i][1]))
|
||||
{
|
||||
throw new pakeException(sprintf("Method %s does not exist for object %s.", $args[$i][1], $args[$i][0]));
|
||||
}
|
||||
else if (!is_array($args[$i]) && !function_exists($args[$i]))
|
||||
{
|
||||
throw new pakeException(sprintf("Function %s does not exist.", $args[$i]));
|
||||
}
|
||||
|
||||
$this->execs[] = $args[$i];
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns relative paths for all files and directories.
|
||||
*
|
||||
* @return object current pakeFinder object
|
||||
*/
|
||||
public function relative()
|
||||
{
|
||||
$this->relative = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Symlink following.
|
||||
*
|
||||
* @return object current sfFinder object
|
||||
*/
|
||||
public function follow_link()
|
||||
{
|
||||
$this->follow_link = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches files and directories which match defined rules.
|
||||
*
|
||||
* @return array list of files and directories
|
||||
*/
|
||||
public function in()
|
||||
{
|
||||
$files = array();
|
||||
$here_dir = getcwd();
|
||||
$numargs = func_num_args();
|
||||
$arg_list = func_get_args();
|
||||
|
||||
// first argument is an array?
|
||||
if ($numargs == 1 && is_array($arg_list[0]))
|
||||
{
|
||||
$arg_list = $arg_list[0];
|
||||
$numargs = count($arg_list);
|
||||
}
|
||||
|
||||
$dirs = array();
|
||||
for ($i = 0; $i < $numargs; $i++)
|
||||
{
|
||||
if ($argDirs = glob($arg_list[$i]))
|
||||
{
|
||||
$dirs = array_merge($dirs, $argDirs);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($dirs as $dir)
|
||||
{
|
||||
$real_dir = realpath($dir);
|
||||
|
||||
// absolute path?
|
||||
if (!self::isPathAbsolute($real_dir))
|
||||
{
|
||||
$dir = $here_dir.DIRECTORY_SEPARATOR.$real_dir;
|
||||
}
|
||||
else
|
||||
{
|
||||
$dir = $real_dir;
|
||||
}
|
||||
|
||||
if (!is_dir($real_dir))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->search_dir = $dir;
|
||||
|
||||
if ($this->relative)
|
||||
{
|
||||
$files = array_merge($files, str_replace($dir.DIRECTORY_SEPARATOR, '', $this->search_in($dir)));
|
||||
}
|
||||
else
|
||||
{
|
||||
$files = array_merge($files, $this->search_in($dir));
|
||||
}
|
||||
}
|
||||
|
||||
return array_unique($files);
|
||||
}
|
||||
|
||||
private function search_in($dir, $depth = 0)
|
||||
{
|
||||
if ($depth > $this->maxdepth)
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
if (is_link($dir) && !$this->follow_link)
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
$files = array();
|
||||
|
||||
if (is_dir($dir))
|
||||
{
|
||||
$current_dir = opendir($dir);
|
||||
while (false !== $entryname = readdir($current_dir))
|
||||
{
|
||||
if ($entryname == '.' || $entryname == '..') continue;
|
||||
|
||||
$current_entry = $dir.DIRECTORY_SEPARATOR.$entryname;
|
||||
if (is_link($current_entry) && !$this->follow_link)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_dir($current_entry))
|
||||
{
|
||||
if (($this->type == 'directory' || $this->type == 'any') && ($depth >= $this->mindepth) && !$this->is_discarded($dir, $entryname) && $this->match_names($dir, $entryname) && $this->exec_ok($dir, $entryname))
|
||||
{
|
||||
$files[] = realpath($current_entry);
|
||||
}
|
||||
|
||||
if (!$this->is_pruned($dir, $entryname))
|
||||
{
|
||||
$files = array_merge($files, $this->search_in($current_entry, $depth + 1));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (($this->type != 'directory' || $this->type == 'any') && ($depth >= $this->mindepth) && !$this->is_discarded($dir, $entryname) && $this->match_names($dir, $entryname) && $this->size_ok($dir, $entryname) && $this->exec_ok($dir, $entryname))
|
||||
{
|
||||
$files[] = realpath($current_entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($current_dir);
|
||||
}
|
||||
|
||||
return $files;
|
||||
}
|
||||
|
||||
private function match_names($dir, $entry)
|
||||
{
|
||||
if (!count($this->names)) return true;
|
||||
|
||||
// we must match one "not_name" rules to be ko
|
||||
$one_not_name_rule = false;
|
||||
foreach ($this->names as $args)
|
||||
{
|
||||
list($not, $regex) = $args;
|
||||
if ($not)
|
||||
{
|
||||
$one_not_name_rule = true;
|
||||
if (preg_match($regex, $entry))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$one_name_rule = false;
|
||||
// we must match one "name" rules to be ok
|
||||
foreach ($this->names as $args)
|
||||
{
|
||||
list($not, $regex) = $args;
|
||||
if (!$not)
|
||||
{
|
||||
$one_name_rule = true;
|
||||
if (preg_match($regex, $entry))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($one_not_name_rule && $one_name_rule)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if ($one_not_name_rule)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if ($one_name_rule)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private function size_ok($dir, $entry)
|
||||
{
|
||||
if (!count($this->sizes)) return true;
|
||||
|
||||
if (!is_file($dir.DIRECTORY_SEPARATOR.$entry)) return true;
|
||||
|
||||
$filesize = filesize($dir.DIRECTORY_SEPARATOR.$entry);
|
||||
foreach ($this->sizes as $number_compare)
|
||||
{
|
||||
if (!$number_compare->test($filesize)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function is_pruned($dir, $entry)
|
||||
{
|
||||
if (!count($this->prunes)) return false;
|
||||
|
||||
foreach ($this->prunes as $args)
|
||||
{
|
||||
$regex = $args[1];
|
||||
if (preg_match($regex, $entry)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function is_discarded($dir, $entry)
|
||||
{
|
||||
if (!count($this->discards)) return false;
|
||||
|
||||
foreach ($this->discards as $args)
|
||||
{
|
||||
$regex = $args[1];
|
||||
if (preg_match($regex, $entry)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function exec_ok($dir, $entry)
|
||||
{
|
||||
if (!count($this->execs)) return true;
|
||||
|
||||
foreach ($this->execs as $exec)
|
||||
{
|
||||
if (!call_user_func_array($exec, array($dir, $entry))) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function isPathAbsolute($path)
|
||||
{
|
||||
if ($path{0} == '/' || $path{0} == '\\' ||
|
||||
(strlen($path) > 3 && ctype_alpha($path{0}) &&
|
||||
$path{1} == ':' &&
|
||||
($path{2} == '\\' || $path{2} == '/')
|
||||
)
|
||||
)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
429
lib/symfony/vendor/pake/pakeFunction.php
vendored
Executable file
429
lib/symfony/vendor/pake/pakeFunction.php
vendored
Executable file
@ -0,0 +1,429 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package pake
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @copyright 2004-2005 Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @license see the LICENSE file included in the distribution
|
||||
* @version SVN: $Id: pakeFunction.php 3263 2007-01-13 14:20:52Z fabien $
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__).'/pakeException.class.php';
|
||||
require_once dirname(__FILE__).'/pakeYaml.class.php';
|
||||
require_once dirname(__FILE__).'/pakeGetopt.class.php';
|
||||
require_once dirname(__FILE__).'/pakeFinder.class.php';
|
||||
require_once dirname(__FILE__).'/pakeTask.class.php';
|
||||
require_once dirname(__FILE__).'/pakeFileTask.class.php';
|
||||
require_once dirname(__FILE__).'/pakeColor.class.php';
|
||||
require_once dirname(__FILE__).'/pakeApp.class.php';
|
||||
|
||||
function pake_import($name, $import_default_tasks = true)
|
||||
{
|
||||
$class_name = 'pake'.ucfirst(strtolower($name)).'Task';
|
||||
|
||||
if (!class_exists($class_name))
|
||||
{
|
||||
// plugin available?
|
||||
$plugin_path = '';
|
||||
foreach (pakeApp::get_plugin_dirs() as $dir)
|
||||
{
|
||||
if (file_exists($dir.DIRECTORY_SEPARATOR.$class_name.'.class.php'))
|
||||
{
|
||||
$plugin_path = $dir.DIRECTORY_SEPARATOR.$class_name.'.class.php';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($plugin_path)
|
||||
{
|
||||
require_once $plugin_path;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new pakeException(sprintf('Plugin "%s" does not exist.', $name));
|
||||
}
|
||||
}
|
||||
|
||||
if ($import_default_tasks && is_callable($class_name, 'import_default_tasks'))
|
||||
{
|
||||
call_user_func(array($class_name, 'import_default_tasks'));
|
||||
}
|
||||
}
|
||||
|
||||
function pake_task($name)
|
||||
{
|
||||
$args = func_get_args();
|
||||
array_shift($args);
|
||||
pakeTask::define_task($name, $args);
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
function pake_alias($alias, $name)
|
||||
{
|
||||
pakeTask::define_alias($alias, $name);
|
||||
|
||||
return $alias;
|
||||
}
|
||||
|
||||
function pake_desc($comment)
|
||||
{
|
||||
pakeTask::define_comment($comment);
|
||||
}
|
||||
|
||||
function pake_properties($property_file)
|
||||
{
|
||||
$file = $property_file;
|
||||
if (!pakeFinder::isPathAbsolute($file))
|
||||
{
|
||||
$file = getcwd().DIRECTORY_SEPARATOR.$property_file;
|
||||
}
|
||||
|
||||
if (file_exists($file))
|
||||
{
|
||||
pakeApp::get_instance()->set_properties(parse_ini_file($file, true));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new pakeException('Properties file does not exist.');
|
||||
}
|
||||
}
|
||||
|
||||
function pake_file($name)
|
||||
{
|
||||
$args = func_get_args();
|
||||
array_shift($args);
|
||||
pakeFileTask::define_task($name, $args);
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
function pake_mkdirs($path, $mode = 0777)
|
||||
{
|
||||
if (is_dir($path))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
pake_echo_action('dir+', $path);
|
||||
|
||||
return @mkdir($path, $mode, true);
|
||||
}
|
||||
|
||||
/*
|
||||
override => boolean
|
||||
*/
|
||||
function pake_copy($origin_file, $target_file, $options = array())
|
||||
{
|
||||
if (!array_key_exists('override', $options))
|
||||
{
|
||||
$options['override'] = false;
|
||||
}
|
||||
|
||||
// we create target_dir if needed
|
||||
if (!is_dir(dirname($target_file)))
|
||||
{
|
||||
pake_mkdirs(dirname($target_file));
|
||||
}
|
||||
|
||||
$most_recent = false;
|
||||
if (file_exists($target_file))
|
||||
{
|
||||
$stat_target = stat($target_file);
|
||||
$stat_origin = stat($origin_file);
|
||||
$most_recent = ($stat_origin['mtime'] > $stat_target['mtime']) ? true : false;
|
||||
}
|
||||
|
||||
if ($options['override'] || !file_exists($target_file) || $most_recent)
|
||||
{
|
||||
pake_echo_action('file+', $target_file);
|
||||
copy($origin_file, $target_file);
|
||||
}
|
||||
}
|
||||
|
||||
function pake_rename($origin, $target, $options = array())
|
||||
{
|
||||
// we check that target does not exist
|
||||
if (is_readable($target))
|
||||
{
|
||||
throw new pakeException(sprintf('Cannot rename because the target "%" already exist.', $target));
|
||||
}
|
||||
|
||||
pake_echo_action('rename', $origin.' > '.$target);
|
||||
rename($origin, $target);
|
||||
}
|
||||
|
||||
function pake_mirror($arg, $origin_dir, $target_dir, $options = array())
|
||||
{
|
||||
$files = pakeApp::get_files_from_argument($arg, $origin_dir, true);
|
||||
|
||||
foreach ($files as $file)
|
||||
{
|
||||
if (is_dir($origin_dir.DIRECTORY_SEPARATOR.$file))
|
||||
{
|
||||
pake_mkdirs($target_dir.DIRECTORY_SEPARATOR.$file);
|
||||
}
|
||||
else if (is_file($origin_dir.DIRECTORY_SEPARATOR.$file))
|
||||
{
|
||||
pake_copy($origin_dir.DIRECTORY_SEPARATOR.$file, $target_dir.DIRECTORY_SEPARATOR.$file, $options);
|
||||
}
|
||||
else if (is_link($origin_dir.DIRECTORY_SEPARATOR.$file))
|
||||
{
|
||||
pake_symlink($origin_dir.DIRECTORY_SEPARATOR.$file, $target_dir.DIRECTORY_SEPARATOR.$file);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new pakeException(sprintf('Unable to determine "%s" type', $file));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function pake_remove($arg, $target_dir)
|
||||
{
|
||||
$files = array_reverse(pakeApp::get_files_from_argument($arg, $target_dir));
|
||||
|
||||
foreach ($files as $file)
|
||||
{
|
||||
if (is_dir($file) && !is_link($file))
|
||||
{
|
||||
pake_echo_action('dir-', $file);
|
||||
|
||||
rmdir($file);
|
||||
}
|
||||
else
|
||||
{
|
||||
pake_echo_action(is_link($file) ? 'link-' : 'file-', $file);
|
||||
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function pake_touch($arg, $target_dir)
|
||||
{
|
||||
$files = pakeApp::get_files_from_argument($arg, $target_dir);
|
||||
|
||||
foreach ($files as $file)
|
||||
{
|
||||
pake_echo_action('file+', $file);
|
||||
|
||||
touch($file);
|
||||
}
|
||||
}
|
||||
|
||||
function pake_replace_tokens($arg, $target_dir, $begin_token, $end_token, $tokens)
|
||||
{
|
||||
$files = pakeApp::get_files_from_argument($arg, $target_dir, true);
|
||||
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$replaced = false;
|
||||
$content = file_get_contents($target_dir.DIRECTORY_SEPARATOR.$file);
|
||||
foreach ($tokens as $key => $value)
|
||||
{
|
||||
$content = str_replace($begin_token.$key.$end_token, $value, $content, $count);
|
||||
if ($count) $replaced = true;
|
||||
}
|
||||
|
||||
pake_echo_action('tokens', $target_dir.DIRECTORY_SEPARATOR.$file);
|
||||
|
||||
file_put_contents($target_dir.DIRECTORY_SEPARATOR.$file, $content);
|
||||
}
|
||||
}
|
||||
|
||||
function pake_symlink($origin_dir, $target_dir, $copy_on_windows = false)
|
||||
{
|
||||
if (!function_exists('symlink') && $copy_on_windows)
|
||||
{
|
||||
$finder = pakeFinder::type('any')->ignore_version_control();
|
||||
pake_mirror($finder, $origin_dir, $target_dir);
|
||||
return;
|
||||
}
|
||||
|
||||
$ok = false;
|
||||
if (is_link($target_dir))
|
||||
{
|
||||
if (readlink($target_dir) != $origin_dir)
|
||||
{
|
||||
unlink($target_dir);
|
||||
}
|
||||
else
|
||||
{
|
||||
$ok = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$ok)
|
||||
{
|
||||
pake_echo_action('link+', $target_dir);
|
||||
symlink($origin_dir, $target_dir);
|
||||
}
|
||||
}
|
||||
|
||||
function pake_chmod($arg, $target_dir, $mode, $umask = 0000)
|
||||
{
|
||||
$current_umask = umask();
|
||||
umask($umask);
|
||||
|
||||
$files = pakeApp::get_files_from_argument($arg, $target_dir, true);
|
||||
|
||||
foreach ($files as $file)
|
||||
{
|
||||
pake_echo_action(sprintf('chmod %o', $mode), $target_dir.DIRECTORY_SEPARATOR.$file);
|
||||
chmod($target_dir.DIRECTORY_SEPARATOR.$file, $mode);
|
||||
}
|
||||
|
||||
umask($current_umask);
|
||||
}
|
||||
|
||||
function pake_sh($cmd)
|
||||
{
|
||||
$verbose = pakeApp::get_instance()->get_verbose();
|
||||
pake_echo_action('exec ', $cmd);
|
||||
|
||||
ob_start();
|
||||
passthru($cmd.' 2>&1', $return);
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
if ($return > 0)
|
||||
{
|
||||
throw new pakeException(sprintf('Problem executing command %s', $verbose ? "\n".$content : ''));
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
function pake_strip_php_comments($arg)
|
||||
{
|
||||
/* T_ML_COMMENT does not exist in PHP 5.
|
||||
* The following three lines define it in order to
|
||||
* preserve backwards compatibility.
|
||||
*
|
||||
* The next two lines define the PHP 5-only T_DOC_COMMENT,
|
||||
* which we will mask as T_ML_COMMENT for PHP 4.
|
||||
*/
|
||||
if (!defined('T_ML_COMMENT'))
|
||||
{
|
||||
define('T_ML_COMMENT', T_COMMENT);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!defined('T_DOC_COMMENT')) define('T_DOC_COMMENT', T_ML_COMMENT);
|
||||
}
|
||||
|
||||
$files = pakeApp::get_files_from_argument($arg);
|
||||
|
||||
foreach ($files as $file)
|
||||
{
|
||||
if (!is_file($file)) continue;
|
||||
|
||||
$source = file_get_contents($file);
|
||||
$output = '';
|
||||
|
||||
$tokens = token_get_all($source);
|
||||
foreach ($tokens as $token)
|
||||
{
|
||||
if (is_string($token))
|
||||
{
|
||||
// simple 1-character token
|
||||
$output .= $token;
|
||||
}
|
||||
else
|
||||
{
|
||||
// token array
|
||||
list($id, $text) = $token;
|
||||
switch ($id)
|
||||
{
|
||||
case T_COMMENT:
|
||||
case T_ML_COMMENT: // we've defined this
|
||||
case T_DOC_COMMENT: // and this
|
||||
// no action on comments
|
||||
break;
|
||||
default:
|
||||
// anything else -> output "as is"
|
||||
$output .= $text;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
file_put_contents($file, $output);
|
||||
}
|
||||
}
|
||||
|
||||
function pake_format_action($section, $text, $size = null)
|
||||
{
|
||||
if (pakeApp::get_instance()->get_verbose())
|
||||
{
|
||||
$width = 9 + strlen(pakeColor::colorize('', 'INFO'));
|
||||
return sprintf('>> %-'.$width.'s %s', pakeColor::colorize($section, 'INFO'), pakeApp::excerpt($text, $size))."\n";
|
||||
}
|
||||
}
|
||||
|
||||
function pake_echo_action($section, $text)
|
||||
{
|
||||
echo pake_format_action($section, $text);
|
||||
}
|
||||
|
||||
function pake_excerpt($text)
|
||||
{
|
||||
if (pakeApp::get_instance()->get_verbose())
|
||||
{
|
||||
echo pakeApp::excerpt($text)."\n";
|
||||
}
|
||||
}
|
||||
|
||||
function pake_echo($text)
|
||||
{
|
||||
if (pakeApp::get_instance()->get_verbose())
|
||||
{
|
||||
echo $text."\n";
|
||||
}
|
||||
}
|
||||
|
||||
function pake_echo_comment($text)
|
||||
{
|
||||
if (pakeApp::get_instance()->get_verbose())
|
||||
{
|
||||
echo sprintf(pakeColor::colorize(' # %s', 'COMMENT'), $text)."\n";
|
||||
}
|
||||
}
|
||||
|
||||
// register our default exception handler
|
||||
function pake_exception_default_handler($exception)
|
||||
{
|
||||
$e = new pakeException();
|
||||
$e->render($exception);
|
||||
exit(1);
|
||||
}
|
||||
set_exception_handler('pake_exception_default_handler');
|
||||
|
||||
// fix php behavior if using cgi php
|
||||
// from http://www.sitepoint.com/article/php-command-line-1/3
|
||||
if (false !== strpos(PHP_SAPI, 'cgi'))
|
||||
{
|
||||
// handle output buffering
|
||||
@ob_end_flush();
|
||||
ob_implicit_flush(true);
|
||||
|
||||
// PHP ini settings
|
||||
set_time_limit(0);
|
||||
ini_set('track_errors', true);
|
||||
ini_set('html_errors', false);
|
||||
ini_set('magic_quotes_runtime', false);
|
||||
|
||||
// define stream constants
|
||||
define('STDIN', fopen('php://stdin', 'r'));
|
||||
define('STDOUT', fopen('php://stdout', 'w'));
|
||||
define('STDERR', fopen('php://stderr', 'w'));
|
||||
|
||||
// change directory
|
||||
if (isset($_SERVER['PWD']))
|
||||
{
|
||||
chdir($_SERVER['PWD']);
|
||||
}
|
||||
|
||||
// close the streams on script termination
|
||||
register_shutdown_function(create_function('', 'fclose(STDIN); fclose(STDOUT); fclose(STDERR); return true;'));
|
||||
}
|
274
lib/symfony/vendor/pake/pakeGetopt.class.php
vendored
Executable file
274
lib/symfony/vendor/pake/pakeGetopt.class.php
vendored
Executable file
@ -0,0 +1,274 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package pake
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @copyright 2004-2005 Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @license see the LICENSE file included in the distribution
|
||||
* @version SVN: $Id: pakeGetopt.class.php 1791 2006-08-23 21:17:06Z fabien $
|
||||
*/
|
||||
|
||||
if (class_exists('pakeGetopt'))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Console options parsing class.
|
||||
*
|
||||
* @package pake
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @copyright 2004-2005 Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @license see the LICENSE file included in the distribution
|
||||
* @version SVN: $Id: pakeGetopt.class.php 1791 2006-08-23 21:17:06Z fabien $
|
||||
*/
|
||||
class pakeGetopt
|
||||
{
|
||||
const NO_ARGUMENT = 0;
|
||||
const REQUIRED_ARGUMENT = 1;
|
||||
const OPTIONAL_ARGUMENT = 2;
|
||||
private $short_options = array();
|
||||
private $long_options = array();
|
||||
private $args = '';
|
||||
private $options = array();
|
||||
private $arguments = array();
|
||||
|
||||
public function __construct($options)
|
||||
{
|
||||
$this->args = '';
|
||||
foreach ($options as $option)
|
||||
{
|
||||
if (!$option[0])
|
||||
{
|
||||
throw new pakeException(sprintf("pakeGetopt: You must define a long option name! for option %s (%s).", $option[1], $option[3]));
|
||||
}
|
||||
|
||||
$this->add_option($option[0], $option[1], $option[2], $option[3]);
|
||||
}
|
||||
}
|
||||
|
||||
public function add_option($long_opt, $short_opt, $mode = self::NO_ARGUMENT, $comment = '')
|
||||
{
|
||||
if ($long_opt{0} == '-' && $long_opt{1} == '-')
|
||||
{
|
||||
$long_opt = substr($long_opt, 2);
|
||||
}
|
||||
|
||||
if ($short_opt)
|
||||
{
|
||||
if ($short_opt{0} == '-')
|
||||
{
|
||||
$short_opt = substr($short_opt, 1);
|
||||
}
|
||||
$this->short_options[$short_opt] = array('mode' => $mode, 'comment' => $comment, 'name' => $long_opt);
|
||||
}
|
||||
|
||||
$this->long_options[$long_opt] = array('mode' => $mode, 'comment' => $comment, 'name' => $long_opt);
|
||||
}
|
||||
|
||||
public function parse($args = null)
|
||||
{
|
||||
if (is_string($args))
|
||||
{
|
||||
// hack to split arguments with spaces : --test="with some spaces"
|
||||
$args = preg_replace('/(\'|")(.+?)\\1/e', "str_replace(' ', '=PLACEHOLDER=', '\\2')", $args);
|
||||
$args = preg_split('/\s+/', $args);
|
||||
$args = str_replace('=PLACEHOLDER=', ' ', $args);
|
||||
}
|
||||
else if (!$args)
|
||||
{
|
||||
$args = $this->read_php_argv();
|
||||
|
||||
// we strip command line program
|
||||
if (isset($args[0]) && $args[0]{0} != '-')
|
||||
{
|
||||
array_shift($args);
|
||||
}
|
||||
}
|
||||
|
||||
$this->args = $args;
|
||||
|
||||
$this->options = array();
|
||||
$this->arguments = array();
|
||||
|
||||
while ($arg = array_shift($this->args))
|
||||
{
|
||||
/* '--' stop options parsing. */
|
||||
if ($arg == '--')
|
||||
{
|
||||
$this->arguments = array_merge($this->arguments, $this->args);
|
||||
break;
|
||||
}
|
||||
|
||||
if ($arg{0} != '-' || (strlen($arg) > 1 && $arg{1} == '-' && !$this->long_options))
|
||||
{
|
||||
$this->arguments = array_merge($this->arguments, array($arg), $this->args);
|
||||
break;
|
||||
}
|
||||
elseif (strlen($arg) > 1 && $arg{1} == '-')
|
||||
{
|
||||
$this->parse_long_option(substr($arg, 2));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->parse_short_option(substr($arg, 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function has_option($option)
|
||||
{
|
||||
return (array_key_exists($option, $this->options) ? true : false);
|
||||
}
|
||||
|
||||
public function get_option($option)
|
||||
{
|
||||
// is it a long option?
|
||||
if (array_key_exists($option, $this->long_options) && $this->long_options[$option]['mode'] != self::NO_ARGUMENT)
|
||||
{
|
||||
return (array_key_exists($option, $this->options) ? $this->options[$option] : '');
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new pakeException('pakeGetopt: You cannot get a value for a NO_ARGUMENT option.');
|
||||
}
|
||||
}
|
||||
|
||||
public function get_options()
|
||||
{
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
public function get_arguments()
|
||||
{
|
||||
return $this->arguments;
|
||||
}
|
||||
|
||||
private function parse_short_option($arg)
|
||||
{
|
||||
for ($i = 0; $i < strlen($arg); $i++)
|
||||
{
|
||||
$opt = $arg{$i};
|
||||
$opt_arg = true;
|
||||
|
||||
/* option exists? */
|
||||
if (!array_key_exists($opt, $this->short_options))
|
||||
{
|
||||
throw new pakeException(sprintf("pakeGetopt: unrecognized option -%s.", $opt));
|
||||
}
|
||||
|
||||
/* required or optional argument? */
|
||||
if ($this->short_options[$opt]['mode'] == self::REQUIRED_ARGUMENT)
|
||||
{
|
||||
if ($i + 1 < strlen($arg))
|
||||
{
|
||||
$this->options[$this->short_options[$opt]['name']] = substr($arg, $i + 1);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
// take next element as argument (if it doesn't start with a -)
|
||||
if (count($this->args) && $this->args[0]{0} != '-')
|
||||
{
|
||||
$this->options[$this->short_options[$opt]['name']] = array_shift($this->args);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new pakeException(sprintf("pakeGetopt: option -%s requires an argument", $opt));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ($this->short_options[$opt]['mode'] == self::OPTIONAL_ARGUMENT)
|
||||
{
|
||||
if (substr($arg, $i + 1) != '')
|
||||
{
|
||||
$this->options[$this->short_options[$opt]['name']] = substr($arg, $i + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// take next element as argument (if it doesn't start with a -)
|
||||
if (count($this->args) && $this->args[0]{0} != '-')
|
||||
{
|
||||
$this->options[$this->short_options[$opt]['name']] = array_shift($this->args);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->options[$this->short_options[$opt]['name']] = true;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
$this->options[$this->short_options[$opt]['name']] = $opt_arg;
|
||||
}
|
||||
}
|
||||
|
||||
private function parse_long_option($arg)
|
||||
{
|
||||
@list($opt, $opt_arg) = explode('=', $arg);
|
||||
|
||||
if (!$opt_arg)
|
||||
{
|
||||
$opt_arg = true;
|
||||
}
|
||||
|
||||
/* option exists? */
|
||||
if (!array_key_exists($opt, $this->long_options))
|
||||
{
|
||||
throw new pakeException(sprintf("pakeGetopt: unrecognized option --%s.", $opt));
|
||||
}
|
||||
|
||||
/* required or optional argument? */
|
||||
if ($this->long_options[$opt]['mode'] == self::REQUIRED_ARGUMENT)
|
||||
{
|
||||
if ($opt_arg)
|
||||
{
|
||||
$this->options[$this->long_options[$opt]['name']] = $opt_arg;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new pakeException(sprintf("pakeGetopt: option --%s requires an argument.", $opt));
|
||||
}
|
||||
}
|
||||
else if ($this->long_options[$opt]['mode'] == self::OPTIONAL_ARGUMENT)
|
||||
{
|
||||
$this->options[$this->long_options[$opt]['name']] = $opt_arg;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->options[$this->long_options[$opt]['name']] = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function from PEAR::Console_Getopt.
|
||||
* Safely read the $argv PHP array across different PHP configurations.
|
||||
* Will take care on register_globals and register_argc_argv ini directives
|
||||
*
|
||||
* @access public
|
||||
* @return mixed the $argv PHP array
|
||||
*/
|
||||
private function read_php_argv()
|
||||
{
|
||||
global $argv;
|
||||
if (!is_array($argv))
|
||||
{
|
||||
if (!@is_array($_SERVER['argv']))
|
||||
{
|
||||
if (!@is_array($GLOBALS['HTTP_SERVER_VARS']['argv']))
|
||||
{
|
||||
throw new pakeException("pakeGetopt: Could not read cmd args (register_argc_argv=Off?).");
|
||||
}
|
||||
|
||||
return $GLOBALS['HTTP_SERVER_VARS']['argv'];
|
||||
}
|
||||
return $_SERVER['argv'];
|
||||
}
|
||||
return $argv;
|
||||
}
|
||||
}
|
139
lib/symfony/vendor/pake/pakeGlobToRegex.class.php
vendored
Executable file
139
lib/symfony/vendor/pake/pakeGlobToRegex.class.php
vendored
Executable file
@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package pake
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com> php port
|
||||
* @author Richard Clamp <richardc@unixbeard.net> perl version
|
||||
* @copyright 2004-2005 Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @copyright 2002 Richard Clamp <richardc@unixbeard.net>
|
||||
* @license see the LICENSE file included in the distribution
|
||||
* @version SVN: $Id: pakeGlobToRegex.class.php 1791 2006-08-23 21:17:06Z fabien $
|
||||
*/
|
||||
|
||||
if (class_exists('pakeGlobToRegex'))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Match globbing patterns against text.
|
||||
*
|
||||
* if match_glob("foo.*", "foo.bar") echo "matched\n";
|
||||
*
|
||||
* // prints foo.bar and foo.baz
|
||||
* $regex = glob_to_regex("foo.*");
|
||||
* for (array('foo.bar', 'foo.baz', 'foo', 'bar') as $t)
|
||||
* {
|
||||
* if (/$regex/) echo "matched: $car\n";
|
||||
* }
|
||||
*
|
||||
* pakeGlobToRegex implements glob(3) style matching that can be used to match
|
||||
* against text, rather than fetching names from a filesystem.
|
||||
*
|
||||
* based on perl Text::Glob module.
|
||||
*
|
||||
* @package pake
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com> php port
|
||||
* @author Richard Clamp <richardc@unixbeard.net> perl version
|
||||
* @copyright 2004-2005 Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @copyright 2002 Richard Clamp <richardc@unixbeard.net>
|
||||
* @license see the LICENSE file included in the distribution
|
||||
* @version SVN: $Id: pakeGlobToRegex.class.php 1791 2006-08-23 21:17:06Z fabien $
|
||||
*/
|
||||
class pakeGlobToRegex
|
||||
{
|
||||
private static $strict_leading_dot = true;
|
||||
private static $strict_wildcard_slash = true;
|
||||
|
||||
public static function setStrictLeadingDot($boolean)
|
||||
{
|
||||
self::$strict_leading_dot = $boolean;
|
||||
}
|
||||
|
||||
public static function setStrictWildcardSlash($boolean)
|
||||
{
|
||||
self::$strict_wildcard_slash = $boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a compiled regex which is the equiavlent of the globbing pattern.
|
||||
*
|
||||
* @param string glob pattern
|
||||
* @return string regex
|
||||
*/
|
||||
public static function glob_to_regex($glob)
|
||||
{
|
||||
$first_byte = true;
|
||||
$escaping = false;
|
||||
$in_curlies = 0;
|
||||
$regex = '';
|
||||
for ($i = 0; $i < strlen($glob); $i++)
|
||||
{
|
||||
$car = $glob[$i];
|
||||
if ($first_byte)
|
||||
{
|
||||
if (self::$strict_leading_dot && $car != '.')
|
||||
{
|
||||
$regex .= '(?=[^\.])';
|
||||
}
|
||||
|
||||
$first_byte = false;
|
||||
}
|
||||
|
||||
if ($car == '/')
|
||||
{
|
||||
$first_byte = true;
|
||||
}
|
||||
|
||||
if ($car == '.' || $car == '(' || $car == ')' || $car == '|' || $car == '+' || $car == '^' || $car == '$')
|
||||
{
|
||||
$regex .= "\\$car";
|
||||
}
|
||||
else if ($car == '*')
|
||||
{
|
||||
$regex .= ($escaping ? "\\*" : (self::$strict_wildcard_slash ? "[^/]*" : ".*"));
|
||||
}
|
||||
else if ($car == '?')
|
||||
{
|
||||
$regex .= ($escaping ? "\\?" : (self::$strict_wildcard_slash ? "[^/]" : "."));
|
||||
}
|
||||
else if ($car == '{')
|
||||
{
|
||||
$regex .= ($escaping ? "\\{" : "(");
|
||||
if (!$escaping) ++$in_curlies;
|
||||
}
|
||||
else if ($car == '}' && $in_curlies)
|
||||
{
|
||||
$regex .= ($escaping ? "}" : ")");
|
||||
if (!$escaping) --$in_curlies;
|
||||
}
|
||||
else if ($car == ',' && $in_curlies)
|
||||
{
|
||||
$regex .= ($escaping ? "," : "|");
|
||||
}
|
||||
else if ($car == "\\")
|
||||
{
|
||||
if ($escaping)
|
||||
{
|
||||
$regex .= "\\\\";
|
||||
$escaping = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$escaping = true;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
$regex .= $car;
|
||||
$escaping = false;
|
||||
}
|
||||
$escaping = false;
|
||||
}
|
||||
|
||||
return "#^$regex$#";
|
||||
}
|
||||
}
|
120
lib/symfony/vendor/pake/pakeNumberCompare.class.php
vendored
Executable file
120
lib/symfony/vendor/pake/pakeNumberCompare.class.php
vendored
Executable file
@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package pake
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com> php port
|
||||
* @author Richard Clamp <richardc@unixbeard.net> perl version
|
||||
* @copyright 2004-2005 Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @copyright 2002 Richard Clamp <richardc@unixbeard.net>
|
||||
* @license see the LICENSE file included in the distribution
|
||||
* @version SVN: $Id: pakeNumberCompare.class.php 1791 2006-08-23 21:17:06Z fabien $
|
||||
*/
|
||||
|
||||
if (class_exists('pakeNumberCompare'))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Numeric comparisons.
|
||||
*
|
||||
* sfNumberCompare compiles a simple comparison to an anonymous
|
||||
* subroutine, which you can call with a value to be tested again.
|
||||
|
||||
* Now this would be very pointless, if sfNumberCompare didn't understand
|
||||
* magnitudes.
|
||||
|
||||
* The target value may use magnitudes of kilobytes (C<k>, C<ki>),
|
||||
* megabytes (C<m>, C<mi>), or gigabytes (C<g>, C<gi>). Those suffixed
|
||||
* with an C<i> use the appropriate 2**n version in accordance with the
|
||||
* IEC standard: http://physics.nist.gov/cuu/Units/binary.html
|
||||
*
|
||||
* based on perl Number::Compare module.
|
||||
*
|
||||
* @package pake
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com> php port
|
||||
* @author Richard Clamp <richardc@unixbeard.net> perl version
|
||||
* @copyright 2004-2005 Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @copyright 2002 Richard Clamp <richardc@unixbeard.net>
|
||||
* @see http://physics.nist.gov/cuu/Units/binary.html
|
||||
* @license see the LICENSE file included in the distribution
|
||||
* @version SVN: $Id: pakeNumberCompare.class.php 1791 2006-08-23 21:17:06Z fabien $
|
||||
*/
|
||||
class pakeNumberCompare
|
||||
{
|
||||
private $test = '';
|
||||
|
||||
public function __construct($test)
|
||||
{
|
||||
$this->test = $test;
|
||||
}
|
||||
|
||||
public function test($number)
|
||||
{
|
||||
if (!preg_match('{^([<>]=?)?(.*?)([kmg]i?)?$}i', $this->test, $matches))
|
||||
{
|
||||
throw new pakeException(sprintf('Don\'t understand "%s" as a test.', $this->test));
|
||||
}
|
||||
|
||||
$target = array_key_exists(2, $matches) ? $matches[2] : '';
|
||||
$magnitude = array_key_exists(3, $matches) ? $matches[3] : '';
|
||||
if (strtolower($magnitude) == 'k') $target *= 1000;
|
||||
if (strtolower($magnitude) == 'ki') $target *= 1024;
|
||||
if (strtolower($magnitude) == 'm') $target *= 1000000;
|
||||
if (strtolower($magnitude) == 'mi') $target *= 1024*1024;
|
||||
if (strtolower($magnitude) == 'g') $target *= 1000000000;
|
||||
if (strtolower($magnitude) == 'gi') $target *= 1024*1024*1024;
|
||||
|
||||
$comparison = array_key_exists(1, $matches) ? $matches[1] : '==';
|
||||
if ($comparison == '==' || $comparison == '')
|
||||
{
|
||||
return ($number == $target);
|
||||
}
|
||||
else if ($comparison == '>')
|
||||
{
|
||||
return ($number > $target);
|
||||
}
|
||||
else if ($comparison == '>=')
|
||||
{
|
||||
return ($number >= $target);
|
||||
}
|
||||
else if ($comparison == '<')
|
||||
{
|
||||
return ($number < $target);
|
||||
}
|
||||
else if ($comparison == '<=')
|
||||
{
|
||||
return ($number <= $target);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
=head1 SYNOPSIS
|
||||
|
||||
Number::Compare->new(">1Ki")->test(1025); # is 1025 > 1024
|
||||
|
||||
my $c = Number::Compare->new(">1M");
|
||||
$c->(1_200_000); # slightly terser invocation
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 ->new( $test )
|
||||
|
||||
Returns a new object that compares the specified test.
|
||||
|
||||
=head2 ->test( $value )
|
||||
|
||||
A longhanded version of $compare->( $value ). Predates blessed
|
||||
subroutine reference implementation.
|
||||
|
||||
=head2 ->parse_to_perl( $test )
|
||||
|
||||
Returns a perl code fragment equivalent to the test.
|
||||
*/
|
310
lib/symfony/vendor/pake/pakeTask.class.php
vendored
Executable file
310
lib/symfony/vendor/pake/pakeTask.class.php
vendored
Executable file
@ -0,0 +1,310 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package pake
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @copyright 2004-2005 Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @license see the LICENSE file included in the distribution
|
||||
* @version SVN: $Id: pakeTask.class.php 4358 2007-06-25 10:04:03Z fabien $
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* .
|
||||
*
|
||||
* .
|
||||
*
|
||||
* @package pake
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @copyright 2004-2005 Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @license see the LICENSE file included in the distribution
|
||||
* @version SVN: $Id: pakeTask.class.php 4358 2007-06-25 10:04:03Z fabien $
|
||||
*/
|
||||
class pakeTask
|
||||
{
|
||||
protected static $TASKS = array();
|
||||
protected static $ALIAS = array();
|
||||
protected static $last_comment = '';
|
||||
protected $prerequisites = array();
|
||||
protected $name = '';
|
||||
protected $comment = '';
|
||||
protected $already_invoked = false;
|
||||
protected $trace = null;
|
||||
protected $verbose = null;
|
||||
protected $dryrun = null;
|
||||
protected $alias = '';
|
||||
|
||||
public function __construct($task_name)
|
||||
{
|
||||
$this->name = $task_name;
|
||||
$this->comment = '';
|
||||
$this->prerequisites = array();
|
||||
$this->already_invoked = false;
|
||||
$pake = pakeApp::get_instance();
|
||||
$this->trace = $pake->get_trace();
|
||||
$this->dryrun = $pake->get_dryrun();
|
||||
$this->verbose = $pake->get_verbose();
|
||||
}
|
||||
|
||||
public function is_verbose()
|
||||
{
|
||||
return $this->verbose;
|
||||
}
|
||||
|
||||
public function enhance($deps = null)
|
||||
{
|
||||
if (!$deps) return;
|
||||
|
||||
if (is_array($deps))
|
||||
{
|
||||
$this->prerequisites = array_merge($this->prerequisites, $deps);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->prerequisites[] = $deps;
|
||||
}
|
||||
}
|
||||
|
||||
public static function get_tasks()
|
||||
{
|
||||
$tasks = pakeTask::$TASKS;
|
||||
// we merge tasks and aliases
|
||||
foreach (pakeTask::$ALIAS as $alias => $name)
|
||||
{
|
||||
if (!array_key_exists($name, $tasks))
|
||||
{
|
||||
throw new pakeException(sprintf('Task "%s" cannot be cloned to "%s" because it does not exist.', $name, $alias));
|
||||
}
|
||||
|
||||
$alias_task = clone $tasks[$name];
|
||||
$alias_task->alias = $name;
|
||||
$alias_task->name = $alias;
|
||||
$tasks[$alias] = $alias_task;
|
||||
}
|
||||
|
||||
return $tasks;
|
||||
}
|
||||
|
||||
public function get_property($name, $section = null)
|
||||
{
|
||||
$properties = pakeApp::get_instance()->get_properties();
|
||||
|
||||
if ($section)
|
||||
{
|
||||
if (!array_key_exists($section, $properties) || !array_key_exists($name, $properties[$section]))
|
||||
{
|
||||
throw new pakeException(sprintf('Property "%s/%s" does not exist.', $section, $name));
|
||||
}
|
||||
else
|
||||
{
|
||||
return $properties[$section][$name];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!array_key_exists($name, $properties))
|
||||
{
|
||||
throw new pakeException(sprintf('Property "%s" does not exist.', $name));
|
||||
}
|
||||
else
|
||||
{
|
||||
return $properties[$name];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function get_alias()
|
||||
{
|
||||
return $this->alias;
|
||||
}
|
||||
|
||||
public function get_prerequisites()
|
||||
{
|
||||
return $this->prerequisites;
|
||||
}
|
||||
|
||||
public function get_name()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function get_comment()
|
||||
{
|
||||
return $this->comment;
|
||||
}
|
||||
|
||||
// Format the trace flags for display.
|
||||
private function format_trace_flags()
|
||||
{
|
||||
$flags = array();
|
||||
if (!$this->already_invoked)
|
||||
{
|
||||
$flags[] = 'first_time';
|
||||
}
|
||||
if (!$this->is_needed())
|
||||
{
|
||||
$flags[] = 'not_needed';
|
||||
}
|
||||
|
||||
return (count($flags)) ? '('.join(', ', $flags).')' : '';
|
||||
}
|
||||
|
||||
public function invoke($args, $options)
|
||||
{
|
||||
if ($this->trace)
|
||||
{
|
||||
pake_echo_action('invoke', $this->name.' '.$this->format_trace_flags());
|
||||
}
|
||||
|
||||
// return if already invoked
|
||||
if ($this->already_invoked) return;
|
||||
$this->already_invoked = true;
|
||||
|
||||
// run prerequisites
|
||||
$tasks = self::get_tasks();
|
||||
foreach ($this->prerequisites as $prerequisite)
|
||||
{
|
||||
$real_prerequisite = self::get_full_task_name($prerequisite);
|
||||
if (array_key_exists($real_prerequisite, $tasks))
|
||||
{
|
||||
$tasks[$real_prerequisite]->invoke($args, $options);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new pakeException(sprintf('Prerequisite "%s" does not exist.', $prerequisite));
|
||||
}
|
||||
}
|
||||
|
||||
// only run if needed
|
||||
if ($this->is_needed())
|
||||
{
|
||||
return $this->execute($args, $options);
|
||||
}
|
||||
}
|
||||
|
||||
public function execute($args, $options)
|
||||
{
|
||||
if ($this->dryrun)
|
||||
{
|
||||
pake_echo_action('execute', '(dry run) '.$this->name);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->trace)
|
||||
{
|
||||
pake_echo_action('execute', $this->name);
|
||||
}
|
||||
|
||||
// action to run
|
||||
$function = ($this->get_alias() ? $this->get_alias() : $this->get_name());
|
||||
if ($pos = strpos($function, '::'))
|
||||
{
|
||||
$function = array(substr($function, 0, $pos), preg_replace('/\-/', '_', 'run_'.strtolower(substr($function, $pos + 2))));
|
||||
if (!is_callable($function))
|
||||
{
|
||||
throw new pakeException(sprintf('Task "%s" is defined but with no action defined.', $function[1]));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$function = preg_replace('/\-/', '_', 'run_'.strtolower($function));
|
||||
if (!function_exists($function))
|
||||
{
|
||||
throw new pakeException(sprintf('Task "%s" is defined but with no action defined.', $this->name));
|
||||
}
|
||||
}
|
||||
|
||||
// execute action
|
||||
return call_user_func_array($function, array($this, $args, $options));
|
||||
}
|
||||
|
||||
public function is_needed()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function timestamp()
|
||||
{
|
||||
$max = 0;
|
||||
foreach ($this->prerequisites as $prerequisite)
|
||||
{
|
||||
$t = pakeTask::get($prerequisite)->timestamp();
|
||||
if ($t > $max) $max = $t;
|
||||
}
|
||||
|
||||
return ($max ? $max : time());
|
||||
}
|
||||
|
||||
public static function define_task($name, $deps = null)
|
||||
{
|
||||
$task = pakeTask::lookup($name, 'pakeTask');
|
||||
$task->add_comment();
|
||||
$task->enhance($deps);
|
||||
}
|
||||
|
||||
public static function define_alias($alias, $name)
|
||||
{
|
||||
self::$ALIAS[$alias] = $name;
|
||||
}
|
||||
|
||||
public static function lookup($task_name, $class = 'pakeTask')
|
||||
{
|
||||
$tasks = self::get_tasks();
|
||||
$task_name = self::get_full_task_name($task_name);
|
||||
if (!array_key_exists($task_name, $tasks))
|
||||
{
|
||||
pakeTask::$TASKS[$task_name] = new $class($task_name);
|
||||
}
|
||||
|
||||
return pakeTask::$TASKS[$task_name];
|
||||
}
|
||||
|
||||
public static function get($task_name)
|
||||
{
|
||||
$tasks = self::get_tasks();
|
||||
$task_name = self::get_full_task_name($task_name);
|
||||
if (!array_key_exists($task_name, $tasks))
|
||||
{
|
||||
throw new pakeException(sprintf('Task "%s" is not defined.', $task_name));
|
||||
}
|
||||
|
||||
return $tasks[$task_name];
|
||||
}
|
||||
|
||||
public static function get_full_task_name($task_name)
|
||||
{
|
||||
foreach (self::get_tasks() as $task)
|
||||
{
|
||||
$mini_task_name = self::get_mini_task_name($task->get_name());
|
||||
if ($mini_task_name == $task_name)
|
||||
{
|
||||
return $task->get_name();
|
||||
}
|
||||
}
|
||||
|
||||
return $task_name;
|
||||
}
|
||||
|
||||
public static function get_mini_task_name($task_name)
|
||||
{
|
||||
$is_method_task = strpos($task_name, '::');
|
||||
return ($is_method_task ? substr($task_name, $is_method_task + 2) : $task_name);
|
||||
}
|
||||
|
||||
public static function define_comment($comment)
|
||||
{
|
||||
pakeTask::$last_comment = $comment;
|
||||
}
|
||||
|
||||
public function add_comment()
|
||||
{
|
||||
if (!pakeTask::$last_comment) return;
|
||||
if ($this->comment)
|
||||
{
|
||||
$this->comment .= ' / ';
|
||||
}
|
||||
|
||||
$this->comment .= pakeTask::$last_comment;
|
||||
pakeTask::$last_comment = '';
|
||||
}
|
||||
}
|
890
lib/symfony/vendor/pake/pakeYaml.class.php
vendored
Executable file
890
lib/symfony/vendor/pake/pakeYaml.class.php
vendored
Executable file
@ -0,0 +1,890 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package pake
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @copyright 2004-2005 Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @license see the LICENSE file included in the distribution
|
||||
* @version SVN: $Id: pakeYaml.class.php 2978 2006-12-08 19:15:44Z fabien $
|
||||
*/
|
||||
|
||||
class pakeYaml
|
||||
{
|
||||
public static function load($input)
|
||||
{
|
||||
// syck is prefered over spyc
|
||||
if (function_exists('syck_load')) {
|
||||
if (!empty($input) && is_readable($input))
|
||||
{
|
||||
$input = file_get_contents($input);
|
||||
}
|
||||
|
||||
return syck_load($input);
|
||||
}
|
||||
else
|
||||
{
|
||||
$spyc = new pakeSpyc();
|
||||
|
||||
return $spyc->load($input);
|
||||
}
|
||||
}
|
||||
|
||||
public static function dump($array)
|
||||
{
|
||||
$spyc = new pakeSpyc();
|
||||
|
||||
return $spyc->dump($array);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Spyc -- A Simple PHP YAML Class
|
||||
* @version 0.2.2 -- 2006-01-29
|
||||
* @author Chris Wanstrath <chris@ozmm.org>
|
||||
* @link http://spyc.sourceforge.net/
|
||||
* @copyright Copyright 2005-2006 Chris Wanstrath
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
* @package Spyc
|
||||
*/
|
||||
|
||||
/**
|
||||
* A node, used by Spyc for parsing YAML.
|
||||
* @package Spyc
|
||||
*/
|
||||
class pakeYAMLNode {
|
||||
/**#@+
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
public $parent;
|
||||
public $id;
|
||||
/**#@+*/
|
||||
/**
|
||||
* @access public
|
||||
* @var mixed
|
||||
*/
|
||||
public $data;
|
||||
/**
|
||||
* @access public
|
||||
* @var int
|
||||
*/
|
||||
public $indent;
|
||||
/**
|
||||
* @access public
|
||||
* @var bool
|
||||
*/
|
||||
public $children = false;
|
||||
|
||||
/**
|
||||
* The constructor assigns the node a unique ID.
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function pakeYAMLNode() {
|
||||
$this->id = uniqid('');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The Simple PHP YAML Class.
|
||||
*
|
||||
* This class can be used to read a YAML file and convert its contents
|
||||
* into a PHP array. It currently supports a very limited subsection of
|
||||
* the YAML spec.
|
||||
*
|
||||
* Usage:
|
||||
* <code>
|
||||
* $parser = new Spyc;
|
||||
* $array = $parser->load($file);
|
||||
* </code>
|
||||
* @package Spyc
|
||||
*/
|
||||
class pakeSpyc {
|
||||
|
||||
/**
|
||||
* Load YAML into a PHP array statically
|
||||
*
|
||||
* The load method, when supplied with a YAML stream (string or file),
|
||||
* will do its best to convert YAML in a file into a PHP array. Pretty
|
||||
* simple.
|
||||
* Usage:
|
||||
* <code>
|
||||
* $array = Spyc::YAMLLoad('lucky.yml');
|
||||
* print_r($array);
|
||||
* </code>
|
||||
* @access public
|
||||
* @return array
|
||||
* @param string $input Path of YAML file or string containing YAML
|
||||
*/
|
||||
public function YAMLLoad($input) {
|
||||
$spyc = new pakeSpyc;
|
||||
return $spyc->load($input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump YAML from PHP array statically
|
||||
*
|
||||
* The dump method, when supplied with an array, will do its best
|
||||
* to convert the array into friendly YAML. Pretty simple. Feel free to
|
||||
* save the returned string as nothing.yml and pass it around.
|
||||
*
|
||||
* Oh, and you can decide how big the indent is and what the wordwrap
|
||||
* for folding is. Pretty cool -- just pass in 'false' for either if
|
||||
* you want to use the default.
|
||||
*
|
||||
* Indent's default is 2 spaces, wordwrap's default is 40 characters. And
|
||||
* you can turn off wordwrap by passing in 0.
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
* @param array $array PHP array
|
||||
* @param int $indent Pass in false to use the default, which is 2
|
||||
* @param int $wordwrap Pass in 0 for no wordwrap, false for default (40)
|
||||
*/
|
||||
public function YAMLDump($array,$indent = false,$wordwrap = false) {
|
||||
$spyc = new pakeSpyc;
|
||||
return $spyc->dump($array,$indent,$wordwrap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load YAML into a PHP array from an instantiated object
|
||||
*
|
||||
* The load method, when supplied with a YAML stream (string or file path),
|
||||
* will do its best to convert the YAML into a PHP array. Pretty simple.
|
||||
* Usage:
|
||||
* <code>
|
||||
* $parser = new Spyc;
|
||||
* $array = $parser->load('lucky.yml');
|
||||
* print_r($array);
|
||||
* </code>
|
||||
* @access public
|
||||
* @return array
|
||||
* @param string $input Path of YAML file or string containing YAML
|
||||
*/
|
||||
public function load($input) {
|
||||
// See what type of input we're talking about
|
||||
// If it's not a file, assume it's a string
|
||||
if (!empty($input) && (strpos($input, "\n") === false)
|
||||
&& file_exists($input)) {
|
||||
$yaml = file($input);
|
||||
} else {
|
||||
$yaml = explode("\n",$input);
|
||||
}
|
||||
// Initiate some objects and values
|
||||
$base = new pakeYAMLNode;
|
||||
$base->indent = 0;
|
||||
$this->_lastIndent = 0;
|
||||
$this->_lastNode = $base->id;
|
||||
$this->_inBlock = false;
|
||||
$this->_isInline = false;
|
||||
|
||||
foreach ($yaml as $linenum => $line) {
|
||||
$ifchk = trim($line);
|
||||
|
||||
// If the line starts with a tab (instead of a space), throw a fit.
|
||||
if (preg_match('/^(\t)+(\w+)/', $line)) {
|
||||
$err = 'ERROR: Line '. ($linenum + 1) .' in your input YAML begins'.
|
||||
' with a tab. YAML only recognizes spaces. Please reformat.';
|
||||
throw new Exception($err);
|
||||
}
|
||||
|
||||
if ($this->_inBlock === false && empty($ifchk)) {
|
||||
continue;
|
||||
} elseif ($this->_inBlock == true && empty($ifchk)) {
|
||||
$last =& $this->_allNodes[$this->_lastNode];
|
||||
$last->data[key($last->data)] .= "\n";
|
||||
} elseif ($ifchk{0} != '#' && substr($ifchk,0,3) != '---') {
|
||||
// Create a new node and get its indent
|
||||
$node = new pakeYAMLNode;
|
||||
$node->indent = $this->_getIndent($line);
|
||||
|
||||
// Check where the node lies in the hierarchy
|
||||
if ($this->_lastIndent == $node->indent) {
|
||||
// If we're in a block, add the text to the parent's data
|
||||
if ($this->_inBlock === true) {
|
||||
$parent =& $this->_allNodes[$this->_lastNode];
|
||||
$parent->data[key($parent->data)] .= trim($line).$this->_blockEnd;
|
||||
} else {
|
||||
// The current node's parent is the same as the previous node's
|
||||
if (isset($this->_allNodes[$this->_lastNode])) {
|
||||
$node->parent = $this->_allNodes[$this->_lastNode]->parent;
|
||||
}
|
||||
}
|
||||
} elseif ($this->_lastIndent < $node->indent) {
|
||||
if ($this->_inBlock === true) {
|
||||
$parent =& $this->_allNodes[$this->_lastNode];
|
||||
$parent->data[key($parent->data)] .= trim($line).$this->_blockEnd;
|
||||
} elseif ($this->_inBlock === false) {
|
||||
// The current node's parent is the previous node
|
||||
$node->parent = $this->_lastNode;
|
||||
|
||||
// If the value of the last node's data was > or | we need to
|
||||
// start blocking i.e. taking in all lines as a text value until
|
||||
// we drop our indent.
|
||||
$parent =& $this->_allNodes[$node->parent];
|
||||
$this->_allNodes[$node->parent]->children = true;
|
||||
if (is_array($parent->data)) {
|
||||
$chk = $parent->data[key($parent->data)];
|
||||
if ($chk === '>') {
|
||||
$this->_inBlock = true;
|
||||
$this->_blockEnd = ' ';
|
||||
$parent->data[key($parent->data)] =
|
||||
str_replace('>','',$parent->data[key($parent->data)]);
|
||||
$parent->data[key($parent->data)] .= trim($line).' ';
|
||||
$this->_allNodes[$node->parent]->children = false;
|
||||
$this->_lastIndent = $node->indent;
|
||||
} elseif ($chk === '|') {
|
||||
$this->_inBlock = true;
|
||||
$this->_blockEnd = "\n";
|
||||
$parent->data[key($parent->data)] =
|
||||
str_replace('|','',$parent->data[key($parent->data)]);
|
||||
$parent->data[key($parent->data)] .= trim($line)."\n";
|
||||
$this->_allNodes[$node->parent]->children = false;
|
||||
$this->_lastIndent = $node->indent;
|
||||
}
|
||||
}
|
||||
}
|
||||
} elseif ($this->_lastIndent > $node->indent) {
|
||||
// Any block we had going is dead now
|
||||
if ($this->_inBlock === true) {
|
||||
$this->_inBlock = false;
|
||||
if ($this->_blockEnd = "\n") {
|
||||
$last =& $this->_allNodes[$this->_lastNode];
|
||||
$last->data[key($last->data)] =
|
||||
trim($last->data[key($last->data)]);
|
||||
}
|
||||
}
|
||||
|
||||
// We don't know the parent of the node so we have to find it
|
||||
// foreach ($this->_allNodes as $n) {
|
||||
foreach ($this->_indentSort[$node->indent] as $n) {
|
||||
if ($n->indent == $node->indent) {
|
||||
$node->parent = $n->parent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_inBlock === false) {
|
||||
// Set these properties with information from our current node
|
||||
$this->_lastIndent = $node->indent;
|
||||
// Set the last node
|
||||
$this->_lastNode = $node->id;
|
||||
// Parse the YAML line and return its data
|
||||
$node->data = $this->_parseLine($line);
|
||||
// Add the node to the master list
|
||||
$this->_allNodes[$node->id] = $node;
|
||||
// Add a reference to the node in an indent array
|
||||
$this->_indentSort[$node->indent][] =& $this->_allNodes[$node->id];
|
||||
// Add a reference to the node in a References array if this node
|
||||
// has a YAML reference in it.
|
||||
if (
|
||||
( (is_array($node->data)) &&
|
||||
isset($node->data[key($node->data)]) &&
|
||||
(!is_array($node->data[key($node->data)])) )
|
||||
&&
|
||||
( (preg_match('/^&([^ ]+)/',$node->data[key($node->data)]))
|
||||
||
|
||||
(preg_match('/^\*([^ ]+)/',$node->data[key($node->data)])) )
|
||||
) {
|
||||
$this->_haveRefs[] =& $this->_allNodes[$node->id];
|
||||
} elseif (
|
||||
( (is_array($node->data)) &&
|
||||
isset($node->data[key($node->data)]) &&
|
||||
(is_array($node->data[key($node->data)])) )
|
||||
) {
|
||||
// Incomplete reference making code. Ugly, needs cleaned up.
|
||||
foreach ($node->data[key($node->data)] as $d) {
|
||||
if ( !is_array($d) &&
|
||||
( (preg_match('/^&([^ ]+)/',$d))
|
||||
||
|
||||
(preg_match('/^\*([^ ]+)/',$d)) )
|
||||
) {
|
||||
$this->_haveRefs[] =& $this->_allNodes[$node->id];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($node);
|
||||
|
||||
// Here we travel through node-space and pick out references (& and *)
|
||||
$this->_linkReferences();
|
||||
|
||||
// Build the PHP array out of node-space
|
||||
$trunk = $this->_buildArray();
|
||||
return $trunk;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump PHP array to YAML
|
||||
*
|
||||
* The dump method, when supplied with an array, will do its best
|
||||
* to convert the array into friendly YAML. Pretty simple. Feel free to
|
||||
* save the returned string as tasteful.yml and pass it around.
|
||||
*
|
||||
* Oh, and you can decide how big the indent is and what the wordwrap
|
||||
* for folding is. Pretty cool -- just pass in 'false' for either if
|
||||
* you want to use the default.
|
||||
*
|
||||
* Indent's default is 2 spaces, wordwrap's default is 40 characters. And
|
||||
* you can turn off wordwrap by passing in 0.
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
* @param array $array PHP array
|
||||
* @param int $indent Pass in false to use the default, which is 2
|
||||
* @param int $wordwrap Pass in 0 for no wordwrap, false for default (40)
|
||||
*/
|
||||
public function dump($array,$indent = false,$wordwrap = false) {
|
||||
// Dumps to some very clean YAML. We'll have to add some more features
|
||||
// and options soon. And better support for folding.
|
||||
|
||||
// New features and options.
|
||||
if ($indent === false or !is_numeric($indent)) {
|
||||
$this->_dumpIndent = 2;
|
||||
} else {
|
||||
$this->_dumpIndent = $indent;
|
||||
}
|
||||
|
||||
if ($wordwrap === false or !is_numeric($wordwrap)) {
|
||||
$this->_dumpWordWrap = 40;
|
||||
} else {
|
||||
$this->_dumpWordWrap = $wordwrap;
|
||||
}
|
||||
|
||||
// New YAML document
|
||||
$string = "---\n";
|
||||
|
||||
// Start at the base of the array and move through it.
|
||||
foreach ($array as $key => $value) {
|
||||
$string .= $this->_yamlize($key,$value,0);
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**** Private Properties ****/
|
||||
|
||||
/**#@+
|
||||
* @access private
|
||||
* @var mixed
|
||||
*/
|
||||
private $_haveRefs;
|
||||
private $_allNodes;
|
||||
private $_lastIndent;
|
||||
private $_lastNode;
|
||||
private $_inBlock;
|
||||
private $_isInline;
|
||||
private $_dumpIndent;
|
||||
private $_dumpWordWrap;
|
||||
/**#@+*/
|
||||
|
||||
/**** Private Methods ****/
|
||||
|
||||
/**
|
||||
* Attempts to convert a key / value array item to YAML
|
||||
* @access private
|
||||
* @return string
|
||||
* @param $key The name of the key
|
||||
* @param $value The value of the item
|
||||
* @param $indent The indent of the current node
|
||||
*/
|
||||
private function _yamlize($key,$value,$indent) {
|
||||
if (is_array($value)) {
|
||||
// It has children. What to do?
|
||||
// Make it the right kind of item
|
||||
$string = $this->_dumpNode($key,NULL,$indent);
|
||||
// Add the indent
|
||||
$indent += $this->_dumpIndent;
|
||||
// Yamlize the array
|
||||
$string .= $this->_yamlizeArray($value,$indent);
|
||||
} elseif (!is_array($value)) {
|
||||
// It doesn't have children. Yip.
|
||||
$string = $this->_dumpNode($key,$value,$indent);
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to convert an array to YAML
|
||||
* @access private
|
||||
* @return string
|
||||
* @param $array The array you want to convert
|
||||
* @param $indent The indent of the current level
|
||||
*/
|
||||
private function _yamlizeArray($array,$indent) {
|
||||
if (is_array($array)) {
|
||||
$string = '';
|
||||
foreach ($array as $key => $value) {
|
||||
$string .= $this->_yamlize($key,$value,$indent);
|
||||
}
|
||||
return $string;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns YAML from a key and a value
|
||||
* @access private
|
||||
* @return string
|
||||
* @param $key The name of the key
|
||||
* @param $value The value of the item
|
||||
* @param $indent The indent of the current node
|
||||
*/
|
||||
private function _dumpNode($key,$value,$indent) {
|
||||
// do some folding here, for blocks
|
||||
if (strpos($value,"\n")) {
|
||||
$value = $this->_doLiteralBlock($value,$indent);
|
||||
} else {
|
||||
$value = $this->_doFolding($value,$indent);
|
||||
}
|
||||
|
||||
$spaces = str_repeat(' ',$indent);
|
||||
|
||||
if (is_int($key)) {
|
||||
// It's a sequence
|
||||
$string = $spaces.'- '.$value."\n";
|
||||
} else {
|
||||
// It's mapped
|
||||
$string = $spaces.$key.': '.$value."\n";
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a literal block for dumping
|
||||
* @access private
|
||||
* @return string
|
||||
* @param $value
|
||||
* @param $indent int The value of the indent
|
||||
*/
|
||||
private function _doLiteralBlock($value,$indent) {
|
||||
$exploded = explode("\n",$value);
|
||||
$newValue = '|';
|
||||
$indent += $this->_dumpIndent;
|
||||
$spaces = str_repeat(' ',$indent);
|
||||
foreach ($exploded as $line) {
|
||||
$newValue .= "\n" . $spaces . trim($line);
|
||||
}
|
||||
return $newValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Folds a string of text, if necessary
|
||||
* @access private
|
||||
* @return string
|
||||
* @param $value The string you wish to fold
|
||||
*/
|
||||
private function _doFolding($value,$indent) {
|
||||
// Don't do anything if wordwrap is set to 0
|
||||
if ($this->_dumpWordWrap === 0) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (strlen($value) > $this->_dumpWordWrap) {
|
||||
$indent += $this->_dumpIndent;
|
||||
$indent = str_repeat(' ',$indent);
|
||||
$wrapped = wordwrap($value,$this->_dumpWordWrap,"\n$indent");
|
||||
$value = ">\n".$indent.$wrapped;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
/* Methods used in loading */
|
||||
|
||||
/**
|
||||
* Finds and returns the indentation of a YAML line
|
||||
* @access private
|
||||
* @return int
|
||||
* @param string $line A line from the YAML file
|
||||
*/
|
||||
private function _getIndent($line) {
|
||||
preg_match('/^\s{1,}/',$line,$match);
|
||||
if (!empty($match[0])) {
|
||||
$indent = substr_count($match[0],' ');
|
||||
} else {
|
||||
$indent = 0;
|
||||
}
|
||||
return $indent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses YAML code and returns an array for a node
|
||||
* @access private
|
||||
* @return array
|
||||
* @param string $line A line from the YAML file
|
||||
*/
|
||||
private function _parseLine($line) {
|
||||
$line = trim($line);
|
||||
|
||||
$array = array();
|
||||
|
||||
if (preg_match('/^-(.*):$/',$line)) {
|
||||
// It's a mapped sequence
|
||||
$key = trim(substr(substr($line,1),0,-1));
|
||||
$array[$key] = '';
|
||||
} elseif ($line[0] == '-' && substr($line,0,3) != '---') {
|
||||
// It's a list item but not a new stream
|
||||
if (strlen($line) > 1) {
|
||||
$value = trim(substr($line,1));
|
||||
// Set the type of the value. Int, string, etc
|
||||
$value = $this->_toType($value);
|
||||
$array[] = $value;
|
||||
} else {
|
||||
$array[] = array();
|
||||
}
|
||||
} elseif (preg_match('/^(.+):/',$line,$key)) {
|
||||
// It's a key/value pair most likely
|
||||
// If the key is in double quotes pull it out
|
||||
if (preg_match('/^(["\'](.*)["\'](\s)*:)/',$line,$matches)) {
|
||||
$value = trim(str_replace($matches[1],'',$line));
|
||||
$key = $matches[2];
|
||||
} else {
|
||||
// Do some guesswork as to the key and the value
|
||||
$explode = explode(':',$line);
|
||||
$key = trim($explode[0]);
|
||||
array_shift($explode);
|
||||
$value = trim(implode(':',$explode));
|
||||
}
|
||||
|
||||
// Set the type of the value. Int, string, etc
|
||||
$value = $this->_toType($value);
|
||||
if (empty($key)) {
|
||||
$array[] = $value;
|
||||
} else {
|
||||
$array[$key] = $value;
|
||||
}
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the type of the passed value, returns the value as the new type.
|
||||
* @access private
|
||||
* @param string $value
|
||||
* @return mixed
|
||||
*/
|
||||
private function _toType($value) {
|
||||
if (preg_match('/^("(.*)"|\'(.*)\')/',$value,$matches)) {
|
||||
$value = (string)preg_replace('/(\'\'|\\\\\')/',"'",end($matches));
|
||||
$value = preg_replace('/\\\\"/','"',$value);
|
||||
} elseif (preg_match('/^\\[(.+)\\]$/',$value,$matches)) {
|
||||
// Inline Sequence
|
||||
|
||||
// Take out strings sequences and mappings
|
||||
$explode = $this->_inlineEscape($matches[1]);
|
||||
|
||||
// Propogate value array
|
||||
$value = array();
|
||||
foreach ($explode as $v) {
|
||||
$value[] = $this->_toType($v);
|
||||
}
|
||||
} elseif (strpos($value,': ')!==false && !preg_match('/^{(.+)/',$value)) {
|
||||
// It's a map
|
||||
$array = explode(': ',$value);
|
||||
$key = trim($array[0]);
|
||||
array_shift($array);
|
||||
$value = trim(implode(': ',$array));
|
||||
$value = $this->_toType($value);
|
||||
$value = array($key => $value);
|
||||
} elseif (preg_match("/{(.+)}$/",$value,$matches)) {
|
||||
// Inline Mapping
|
||||
|
||||
// Take out strings sequences and mappings
|
||||
$explode = $this->_inlineEscape($matches[1]);
|
||||
|
||||
// Propogate value array
|
||||
$array = array();
|
||||
foreach ($explode as $v) {
|
||||
$array = $array + $this->_toType($v);
|
||||
}
|
||||
$value = $array;
|
||||
} elseif (strtolower($value) == 'null' or $value == '' or $value == '~') {
|
||||
$value = NULL;
|
||||
} elseif (ctype_digit($value)) {
|
||||
$value = (int)$value;
|
||||
} elseif (in_array(strtolower($value),
|
||||
array('true', 'on', '+', 'yes', 'y'))) {
|
||||
$value = TRUE;
|
||||
} elseif (in_array(strtolower($value),
|
||||
array('false', 'off', '-', 'no', 'n'))) {
|
||||
$value = FALSE;
|
||||
} elseif (is_numeric($value)) {
|
||||
$value = (float)$value;
|
||||
} else {
|
||||
// Just a normal string, right?
|
||||
$value = trim(preg_replace('/#(.+)$/','',$value));
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used in inlines to check for more inlines or quoted strings
|
||||
* @access private
|
||||
* @return array
|
||||
*/
|
||||
private function _inlineEscape($inline) {
|
||||
// There's gotta be a cleaner way to do this...
|
||||
// While pure sequences seem to be nesting just fine,
|
||||
// pure mappings and mappings with sequences inside can't go very
|
||||
// deep. This needs to be fixed.
|
||||
|
||||
// Check for strings
|
||||
$regex = '/(?:(")|(?:\'))((?(1)[^"]+|[^\']+))(?(1)"|\')/';
|
||||
if (preg_match_all($regex,$inline,$strings)) {
|
||||
$strings = $strings[2];
|
||||
$inline = preg_replace($regex,'YAMLString',$inline);
|
||||
}
|
||||
unset($regex);
|
||||
|
||||
// Check for sequences
|
||||
if (preg_match_all('/\[(.+)\]/U',$inline,$seqs)) {
|
||||
$inline = preg_replace('/\[(.+)\]/U','YAMLSeq',$inline);
|
||||
$seqs = $seqs[0];
|
||||
}
|
||||
|
||||
// Check for mappings
|
||||
if (preg_match_all('/{(.+)}/U',$inline,$maps)) {
|
||||
$inline = preg_replace('/{(.+)}/U','YAMLMap',$inline);
|
||||
$maps = $maps[0];
|
||||
}
|
||||
|
||||
$explode = explode(', ',$inline);
|
||||
|
||||
// Re-add the strings
|
||||
if (!empty($strings)) {
|
||||
$i = 0;
|
||||
foreach ($explode as $key => $value) {
|
||||
if ($value == 'YAMLString') {
|
||||
$explode[$key] = $strings[$i];
|
||||
++$i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Re-add the sequences
|
||||
if (!empty($seqs)) {
|
||||
$i = 0;
|
||||
foreach ($explode as $key => $value) {
|
||||
if (strpos($value,'YAMLSeq') !== false) {
|
||||
$explode[$key] = str_replace('YAMLSeq',$seqs[$i],$value);
|
||||
++$i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Re-add the mappings
|
||||
if (!empty($maps)) {
|
||||
$i = 0;
|
||||
foreach ($explode as $key => $value) {
|
||||
if (strpos($value,'YAMLMap') !== false) {
|
||||
$explode[$key] = str_replace('YAMLMap',$maps[$i],$value);
|
||||
++$i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $explode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the PHP array from all the YAML nodes we've gathered
|
||||
* @access private
|
||||
* @return array
|
||||
*/
|
||||
private function _buildArray() {
|
||||
$trunk = array();
|
||||
|
||||
if (!isset($this->_indentSort[0])) {
|
||||
return $trunk;
|
||||
}
|
||||
|
||||
foreach ($this->_indentSort[0] as $n) {
|
||||
if (empty($n->parent)) {
|
||||
$this->_nodeArrayizeData($n);
|
||||
// Check for references and copy the needed data to complete them.
|
||||
$this->_makeReferences($n);
|
||||
// Merge our data with the big array we're building
|
||||
$trunk = $this->_array_kmerge($trunk,$n->data);
|
||||
}
|
||||
}
|
||||
|
||||
return $trunk;
|
||||
}
|
||||
|
||||
/**
|
||||
* Traverses node-space and sets references (& and *) accordingly
|
||||
* @access private
|
||||
* @return bool
|
||||
*/
|
||||
private function _linkReferences() {
|
||||
if (is_array($this->_haveRefs)) {
|
||||
foreach ($this->_haveRefs as $node) {
|
||||
if (!empty($node->data)) {
|
||||
$key = key($node->data);
|
||||
// If it's an array, don't check.
|
||||
if (is_array($node->data[$key])) {
|
||||
foreach ($node->data[$key] as $k => $v) {
|
||||
$this->_linkRef($node,$key,$k,$v);
|
||||
}
|
||||
} else {
|
||||
$this->_linkRef($node,$key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function _linkRef(&$n,$key,$k = NULL,$v = NULL) {
|
||||
if (empty($k) && empty($v)) {
|
||||
// Look for &refs
|
||||
if (preg_match('/^&([^ ]+)/',$n->data[$key],$matches)) {
|
||||
// Flag the node so we know it's a reference
|
||||
$this->_allNodes[$n->id]->ref = substr($matches[0],1);
|
||||
$this->_allNodes[$n->id]->data[$key] =
|
||||
substr($n->data[$key],strlen($matches[0])+1);
|
||||
// Look for *refs
|
||||
} elseif (preg_match('/^\*([^ ]+)/',$n->data[$key],$matches)) {
|
||||
$ref = substr($matches[0],1);
|
||||
// Flag the node as having a reference
|
||||
$this->_allNodes[$n->id]->refKey = $ref;
|
||||
}
|
||||
} elseif (!empty($k) && !empty($v)) {
|
||||
if (preg_match('/^&([^ ]+)/',$v,$matches)) {
|
||||
// Flag the node so we know it's a reference
|
||||
$this->_allNodes[$n->id]->ref = substr($matches[0],1);
|
||||
$this->_allNodes[$n->id]->data[$key][$k] =
|
||||
substr($v,strlen($matches[0])+1);
|
||||
// Look for *refs
|
||||
} elseif (preg_match('/^\*([^ ]+)/',$v,$matches)) {
|
||||
$ref = substr($matches[0],1);
|
||||
// Flag the node as having a reference
|
||||
$this->_allNodes[$n->id]->refKey = $ref;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the children of a node and aids in the building of the PHP array
|
||||
* @access private
|
||||
* @param int $nid The id of the node whose children we're gathering
|
||||
* @return array
|
||||
*/
|
||||
private function _gatherChildren($nid) {
|
||||
$return = array();
|
||||
$node =& $this->_allNodes[$nid];
|
||||
foreach ($this->_allNodes as $z) {
|
||||
if ($z->parent == $node->id) {
|
||||
// We found a child
|
||||
$this->_nodeArrayizeData($z);
|
||||
// Check for references
|
||||
$this->_makeReferences($z);
|
||||
// Merge with the big array we're returning
|
||||
// The big array being all the data of the children of our parent node
|
||||
$return = $this->_array_kmerge($return,$z->data);
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns a node's data and its children's data into a PHP array
|
||||
*
|
||||
* @access private
|
||||
* @param array $node The node which you want to arrayize
|
||||
* @return boolean
|
||||
*/
|
||||
private function _nodeArrayizeData(&$node) {
|
||||
if (is_array($node->data) && $node->children == true) {
|
||||
// This node has children, so we need to find them
|
||||
$childs = $this->_gatherChildren($node->id);
|
||||
// We've gathered all our children's data and are ready to use it
|
||||
$key = key($node->data);
|
||||
$key = empty($key) ? 0 : $key;
|
||||
// If it's an array, add to it of course
|
||||
if (is_array($node->data[$key])) {
|
||||
$node->data[$key] = $this->_array_kmerge($node->data[$key],$childs);
|
||||
} else {
|
||||
$node->data[$key] = $childs;
|
||||
}
|
||||
} elseif (!is_array($node->data) && $node->children == true) {
|
||||
// Same as above, find the children of this node
|
||||
$childs = $this->_gatherChildren($node->id);
|
||||
$node->data = array();
|
||||
$node->data[] = $childs;
|
||||
}
|
||||
|
||||
// We edited $node by reference, so just return true
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Traverses node-space and copies references to / from this object.
|
||||
* @access private
|
||||
* @param object $z A node whose references we wish to make real
|
||||
* @return bool
|
||||
*/
|
||||
private function _makeReferences(&$z) {
|
||||
// It is a reference
|
||||
if (isset($z->ref)) {
|
||||
$key = key($z->data);
|
||||
// Copy the data to this object for easy retrieval later
|
||||
$this->ref[$z->ref] =& $z->data[$key];
|
||||
// It has a reference
|
||||
} elseif (isset($z->refKey)) {
|
||||
if (isset($this->ref[$z->refKey])) {
|
||||
$key = key($z->data);
|
||||
// Copy the data from this object to make the node a real reference
|
||||
$z->data[$key] =& $this->ref[$z->refKey];
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Merges arrays and maintains numeric keys.
|
||||
*
|
||||
* An ever-so-slightly modified version of the array_kmerge() function posted
|
||||
* to php.net by mail at nospam dot iaindooley dot com on 2004-04-08.
|
||||
*
|
||||
* http://us3.php.net/manual/en/function.array-merge.php#41394
|
||||
*
|
||||
* @access private
|
||||
* @param array $arr1
|
||||
* @param array $arr2
|
||||
* @return array
|
||||
*/
|
||||
private function _array_kmerge($arr1,$arr2) {
|
||||
if(!is_array($arr1))
|
||||
$arr1 = array();
|
||||
|
||||
if(!is_array($arr2))
|
||||
$arr2 = array();
|
||||
|
||||
$keys1 = array_keys($arr1);
|
||||
$keys2 = array_keys($arr2);
|
||||
$keys = array_merge($keys1,$keys2);
|
||||
$vals1 = array_values($arr1);
|
||||
$vals2 = array_values($arr2);
|
||||
$vals = array_merge($vals1,$vals2);
|
||||
$ret = array();
|
||||
|
||||
foreach($keys as $key) {
|
||||
list($unused,$val) = each($vals);
|
||||
// This is the good part! If a key already exists, but it's part of a
|
||||
// sequence (an int), just keep addin numbers until we find a fresh one.
|
||||
if (isset($ret[$key]) and is_int($key)) {
|
||||
while (array_key_exists($key, $ret)) {
|
||||
$key++;
|
||||
}
|
||||
}
|
||||
$ret[$key] = $val;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
27
lib/symfony/vendor/pake/tasks/pakePearTask.class.php
vendored
Executable file
27
lib/symfony/vendor/pake/tasks/pakePearTask.class.php
vendored
Executable file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package pake
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @copyright 2004-2005 Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @license see the LICENSE file included in the distribution
|
||||
* @version SVN: $Id: pakePearTask.class.php 1791 2006-08-23 21:17:06Z fabien $
|
||||
*/
|
||||
|
||||
class pakePearTask
|
||||
{
|
||||
public static function import_default_tasks()
|
||||
{
|
||||
pake_desc('create a PEAR package');
|
||||
pake_task('pakePearTask::pear');
|
||||
}
|
||||
|
||||
public static function run_pear($task, $args)
|
||||
{
|
||||
$results = pake_sh('pear package');
|
||||
if ($task->is_verbose())
|
||||
{
|
||||
echo $results;
|
||||
}
|
||||
}
|
||||
}
|
72
lib/symfony/vendor/pake/tasks/pakePhingTask.class.php
vendored
Executable file
72
lib/symfony/vendor/pake/tasks/pakePhingTask.class.php
vendored
Executable file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package pake
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @copyright 2004-2005 Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @license see the LICENSE file included in the distribution
|
||||
* @version SVN: $Id: pakePhingTask.class.php 4977 2007-09-05 09:14:45Z noel $
|
||||
*/
|
||||
|
||||
include_once 'phing/Phing.php';
|
||||
if (!class_exists('Phing'))
|
||||
{
|
||||
throw new pakeException('You must install Phing to use this task. (pear install http://phing.info/pear/phing-current.tgz)');
|
||||
}
|
||||
|
||||
class pakePhingTask
|
||||
{
|
||||
public static function import_default_tasks()
|
||||
{
|
||||
}
|
||||
|
||||
public static function call_phing($task, $target, $build_file = '', $options = array())
|
||||
{
|
||||
$args = array();
|
||||
foreach ($options as $key => $value)
|
||||
{
|
||||
$args[] = "-D$key=$value";
|
||||
}
|
||||
|
||||
if ($build_file)
|
||||
{
|
||||
$args[] = '-f';
|
||||
$args[] = realpath($build_file);
|
||||
}
|
||||
|
||||
if (!$task->is_verbose())
|
||||
{
|
||||
$args[] = '-q';
|
||||
}
|
||||
|
||||
if (is_array($target))
|
||||
{
|
||||
$args = array_merge($args, $target);
|
||||
}
|
||||
else
|
||||
{
|
||||
$args[] = $target;
|
||||
}
|
||||
|
||||
if (DIRECTORY_SEPARATOR != '\\' && (function_exists('posix_isatty') && @posix_isatty(STDOUT)))
|
||||
{
|
||||
$args[] = '-logger';
|
||||
$args[] = 'phing.listener.AnsiColorLogger';
|
||||
}
|
||||
|
||||
Phing::startup();
|
||||
Phing::setProperty('phing.home', getenv('PHING_HOME'));
|
||||
|
||||
$m = new pakePhing();
|
||||
$m->execute($args);
|
||||
$m->runBuild();
|
||||
}
|
||||
}
|
||||
|
||||
class pakePhing extends Phing
|
||||
{
|
||||
function getPhingVersion()
|
||||
{
|
||||
return 'pakePhing';
|
||||
}
|
||||
}
|
112
lib/symfony/vendor/pake/tasks/pakeSimpletestTask.class.php
vendored
Executable file
112
lib/symfony/vendor/pake/tasks/pakeSimpletestTask.class.php
vendored
Executable file
@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package pake
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @copyright 2004-2005 Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @license see the LICENSE file included in the distribution
|
||||
* @version SVN: $Id: pakeSimpletestTask.class.php 1791 2006-08-23 21:17:06Z fabien $
|
||||
*/
|
||||
|
||||
class pakeSimpletestTask
|
||||
{
|
||||
public static function import_default_tasks()
|
||||
{
|
||||
pake_desc('launch project test suite');
|
||||
pake_task('pakeSimpletestTask::test');
|
||||
}
|
||||
|
||||
public static function call_simpletest($task, $type = 'text', $dirs = array())
|
||||
{
|
||||
// remove E_STRICT because simpletest is not E_STRICT compatible
|
||||
$old_error_reporting = ini_get('error_reporting');
|
||||
if ($old_error_reporting & E_STRICT)
|
||||
{
|
||||
error_reporting($old_error_reporting ^ E_STRICT);
|
||||
}
|
||||
|
||||
set_include_path('test'.PATH_SEPARATOR.'lib'.PATH_SEPARATOR.'classes'.PATH_SEPARATOR.get_include_path());
|
||||
|
||||
include_once('simpletest/unit_tester.php');
|
||||
include_once('simpletest/web_tester.php');
|
||||
if (!class_exists('GroupTest'))
|
||||
{
|
||||
throw new pakeException('You must install SimpleTest to use this task.');
|
||||
}
|
||||
|
||||
require_once('simpletest/reporter.php');
|
||||
require_once('simpletest/mock_objects.php');
|
||||
|
||||
$base_test_dir = 'test';
|
||||
$test_dirs = array();
|
||||
|
||||
// run tests only in these subdirectories
|
||||
if ($dirs)
|
||||
{
|
||||
foreach ($dirs as $dir)
|
||||
{
|
||||
$test_dirs[] = $base_test_dir.DIRECTORY_SEPARATOR.$dir;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$test_dirs[] = $base_test_dir;
|
||||
}
|
||||
|
||||
$test = new GroupTest('Test suite in ('.implode(', ', $test_dirs).')');
|
||||
$files = pakeFinder::type('file')->name('*Test.php')->in($test_dirs);
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$test->addTestFile($file);
|
||||
}
|
||||
|
||||
if (count($files))
|
||||
{
|
||||
ob_start();
|
||||
if ($type == 'html')
|
||||
{
|
||||
$result = $test->run(new HtmlReporter());
|
||||
}
|
||||
else if ($type == 'xml')
|
||||
{
|
||||
$result = $test->run(new XmlReporter());
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $test->run(new TextReporter());
|
||||
}
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
if ($task->is_verbose())
|
||||
{
|
||||
echo $content;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new pakeException('No test to run.');
|
||||
}
|
||||
|
||||
error_reporting($old_error_reporting);
|
||||
}
|
||||
|
||||
public static function run_test($task, $args)
|
||||
{
|
||||
$types = array('text', 'html', 'xml');
|
||||
$type = 'text';
|
||||
if (array_key_exists(0, $args) && in_array($args[0], $types))
|
||||
{
|
||||
$type = $args[0];
|
||||
array_shift($args);
|
||||
}
|
||||
|
||||
$dirs = array();
|
||||
if (is_array($args) && array_key_exists(0, $args))
|
||||
{
|
||||
$dirs[] = $args[0];
|
||||
}
|
||||
|
||||
self::call_simpletest($task, $type, $dirs);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user