This class is a singleton.
Author: Fabien Potencier (fabien.potencier@symfony-project.com)
 public static function package_pear_package($package_xml_path, $target_dir)
 {
     if (!file_exists($package_xml_path)) {
         throw new pakeException('"' . $package_xml_path . '" file does not exist');
     }
     pake_mkdirs($target_dir);
     $current = getcwd();
     chdir($target_dir);
     if (!class_exists('PEAR_Packager')) {
         @(include 'PEAR/Packager.php');
         if (!class_exists('PEAR_Packager')) {
             // falling back to cli-call
             $results = pake_sh(escapeshellarg(pake_which('pear')) . ' package ' . escapeshellarg($package_xml_path));
             if (pakeApp::get_instance()->get_verbose()) {
                 echo $results;
             }
             chdir($current);
             return;
         }
     }
     $packager = new PEAR_Packager();
     $packager->debug = 0;
     // silence output
     $archive = $packager->package($package_xml_path, true);
     pake_echo_action('file+', $target_dir . '/' . $archive);
     chdir($current);
 }
Example #2
0
function echo_cms_sep()
{
    if (pakeApp::get_instance()->get_verbose()) {
        $width = 9 + strlen(pakeColor::colorize('', 'SEP'));
        echo sprintf(' %-' . $width . 's %s', pakeColor::colorize("", 'SEP'), pakeApp::excerpt("", null)) . "\n";
    }
}
 static function colorize($text = '', $parameters = array(), $stream = STDOUT)
 {
     // disable colors if not supported (windows or non tty console)
     if (!pakeApp::isTTY()) {
         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 "[" . implode(';', $codes) . 'm' . $text . "";
 }
 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");
 }
 public function setUp()
 {
     pakeApp::get_instance()->do_option('quiet', null);
     $dir = dirname(__FILE__);
     $this->test_dir = $dir . DIRECTORY_SEPARATOR . 'temporary-files';
     if (!is_dir($this->test_dir)) {
         mkdir($this->test_dir);
     }
     $this->_cleanup();
 }
 public static function render($e)
 {
     $isatty = pakeApp::isTTY();
     $title = '  [' . get_class($e) . ']  ';
     $len = self::strlen($title);
     $lines = array();
     foreach (explode("\n", $e->getMessage()) as $line) {
         if ($isatty) {
             $pieces = explode("\n", wordwrap($line, pakeApp::screenWidth() - 4, "\n", true));
         } else {
             $pieces = array($line);
         }
         foreach ($pieces as $piece) {
             $lines[] = '  ' . $piece . '  ';
             $len = max(self::strlen($piece) + 4, $len);
         }
     }
     if ($isatty) {
         $messages = array(str_repeat(' ', $len), $title . str_repeat(' ', $len - self::strlen($title)));
     } else {
         $messages = array('', $title);
     }
     foreach ($lines as $line) {
         if ($isatty) {
             $messages[] = $line . str_repeat(' ', $len - self::strlen($line));
         } else {
             $messages[] = $line;
         }
     }
     if ($isatty) {
         $messages[] = str_repeat(' ', $len);
     } else {
         $messages[] = '';
     }
     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 = self::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, pake_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 run_help($task = null, $args = array(), $cliopts = array())
{
    /*if ( count( $args ) == 0 )
      {
          // ...
      }*/
    // work around a pake bug
    if (count($args) > 0) {
        $args[0] = pakeTask::get_full_task_name($args[0]);
    }
    $pake = pakeApp::get_instance();
    $pake->run_help($task, $args);
}
 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 showVersion()
 {
     parent::showVersion();
     echo sprintf('AiP  version %s', \pakeColor::colorize(self::VERSION, 'INFO')) . "\n";
 }
Example #10
0
 public function do_option($opt, $value)
 {
     switch ($opt) {
         case 'interactive':
             $this->interactive = true;
             break;
         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':
             self::$PAKEFILES = array($value);
             break;
         case 'require':
             require $value;
             break;
         case 'import':
             pake_import($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 'force-tty':
             define('PAKE_FORCE_TTY', true);
             break;
         case 'version':
             $this->showVersion();
             exit;
         default:
             throw new pakeException(sprintf("Unknown option: %s", $opt));
     }
 }
Example #11
0
function pake_echo_comment($text)
{
    if (pakeApp::get_instance()->get_verbose()) {
        echo sprintf(pakeColor::colorize('   # %s', 'COMMENT'), $text) . "\n";
    }
}
Example #12
0
<?php

Phar::interceptFileFuncs();
$phar_name = dirname(__FILE__);
define('PAKE_DIR', $phar_name . '/lib/pake');
require PAKE_DIR . '/autoload.php';
require PAKE_DIR . '/cli_init.php';
$retval = pakeApp::get_instance()->run();
if (false === $retval) {
    exit(1);
}
 public static function run_help_pake()
 {
     pakeApp::get_instance()->display_tasks_and_comments();
 }
 protected function initAndRunTaskInSubprocess($command)
 {
     if (function_exists('pcntl_fork')) {
         // UNIX
         $argv = explode(' ', $command);
         list($task_name, $args, $options) = self::parseTaskAndParameters($argv);
         $task_name = pakeTask::get_full_task_name($task_name);
         $pid = pcntl_fork();
         if ($pid == -1) {
             die('could not fork');
         }
         if ($pid) {
             // we are the parent
             pcntl_wait($status);
             $status = pcntl_wexitstatus($status);
             if ($status == self::QUIT_INTERACTIVE) {
                 exit(0);
             }
         } else {
             try {
                 $status = $this->initAndRunTask($task_name, $args, $options);
                 if (true === $status) {
                     exit(0);
                 }
                 exit($status);
             } catch (pakeException $e) {
                 pakeException::render($e);
                 exit(1);
             }
         }
     } else {
         // WINDOWS or missing PCNTL functions
         $php_exec = escapeshellarg((isset($_SERVER['_']) and substr($_SERVER['_'], -4) != 'pake') ? $_SERVER['_'] : 'php');
         $force_tty = '';
         if (pakeApp::isTTY()) {
             $force_tty = ' --force-tty';
         }
         $pake_php = escapeshellarg($_SERVER['SCRIPT_NAME']);
         $import_flag = ' --import=interactive';
         system($php_exec . ' ' . $pake_php . $force_tty . $import_flag . ' ' . $command, $status);
         if ($status == self::QUIT_INTERACTIVE) {
             exit(0);
         }
     }
 }
 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));
     }
 }
        $initialized = true;
    }
    return simpleAutoloader::__autoload($class);
}
// trap -V before pake
if (in_array('-V', $argv) || in_array('--version', $argv)) {
    printf("symfony version %s\n", pakeColor::colorize(trim(file_get_contents($sf_symfony_lib_dir . '/VERSION')), 'INFO'));
    exit(0);
}
if (count($argv) <= 1) {
    $argv[] = '-T';
}
require_once $sf_symfony_lib_dir . '/config/sfConfig.class.php';
sfConfig::add(array('sf_root_dir' => getcwd(), 'sf_symfony_lib_dir' => $sf_symfony_lib_dir, 'sf_symfony_data_dir' => $sf_symfony_data_dir));
// directory layout
include $sf_symfony_data_dir . '/config/constants.php';
// include path
set_include_path(sfConfig::get('sf_lib_dir') . PATH_SEPARATOR . sfConfig::get('sf_app_lib_dir') . PATH_SEPARATOR . sfConfig::get('sf_model_dir') . PATH_SEPARATOR . sfConfig::get('sf_symfony_lib_dir') . DIRECTORY_SEPARATOR . 'vendor' . PATH_SEPARATOR . get_include_path());
// register tasks
$dirs = array(sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . 'tasks' => 'myPake*.php', sfConfig::get('sf_symfony_data_dir') . DIRECTORY_SEPARATOR . 'tasks' => 'sfPake*.php', sfConfig::get('sf_root_dir') . '/plugins/*/data/tasks' => '*.php');
foreach ($dirs as $globDir => $name) {
    if ($dirs = glob($globDir)) {
        $tasks = pakeFinder::type('file')->ignore_version_control()->name($name)->in($dirs);
        foreach ($tasks as $task) {
            include_once $task;
        }
    }
}
// run task
pakeApp::get_instance()->run(null, null, false);
exit(0);
Example #17
0
<?php

Phar::interceptFileFuncs();
$phar_name = dirname(__FILE__);
define('PAKE_DIR', $phar_name . '/lib/pake');
require PAKE_DIR . '/init.php';
$pake = pakeApp::get_instance();
$pake->run();
 private static function _get_php_executable()
 {
     static $php_exec = null;
     if (null === $php_exec) {
         $root = dirname(pakeApp::get_instance()->getPakefilePath());
         if (!file_exists($root . '/Makefile')) {
             throw new LogicException("Makefile is missing. You have to build extension before testing it!");
         }
         $makefile_rows = file($root . '/Makefile');
         foreach ($makefile_rows as $row) {
             if (strpos($row, 'PHP_EXECUTABLE = ') !== 0) {
                 continue;
             }
             $row = rtrim($row);
             $parts = explode(' = ', $row);
             if (!isset($parts[1]) or strlen($parts[1]) == 0) {
                 continue;
             }
             $php_exec = $parts[1];
             break;
         }
         unset($makefile_rows);
     }
     if (!$php_exec) {
         // Fallback
         $php_exec = 'php';
     }
     return $php_exec;
 }
Example #19
0
 public static function run_pear_package($task, $args)
 {
     $path = dirname(pakeApp::get_instance()->getPakefilePath());
     self::package_pear_package($path . '/package.xml', $path);
 }