/** * Set exception / error handlers * * @return void */ public static function setExceptionHandlers() { set_exception_handler(array('XDT_CLI_ExceptionHandler', 'handleException')); set_error_handler(array('XDT_CLI_ExceptionHandler', 'handleError')); XDT_CLI_Abstract::$_useExceptions = true; XDT_CLI_Abstract::$_exceptionClass = 'XDT_CLI_Exception'; }
public static function writeToFile($file, $contents, $createPath = false) { $config = XDT_CLI_Application::getConfig(); $filePath = dirname($file); if (!is_dir($filePath) and $createPath) { mkdir($filePath, octdec($config->dir_mask), true); } if (!is_dir($filePath) or !file_put_contents($file, trim($contents))) { XDT_CLI_Abstract::getInstance()->bail("File could not be created: " . $file); return false; } chmod($file, octdec($config['file_mask'])); return true; }
protected static function _print($string, $title = null) { if ($cli = XDT_CLI_Abstract::getInstance()) { $cli->printMessage(''); if ($title != null) { $cli->printMessage($cli->colorText($title . ': ', XDT_CLI_Abstract::RED), false); } $cli->printMessage($string); } else { echo "\n"; if ($title != null) { echo $title . ': '; } echo $string . "\n"; } }
/** * Class Constructor * * @param null|bool $initialize * * @return void */ public function __construct($initialize = true) { if ($initialize instanceof XDT_CLI_Abstract) { $arguments = $initialize->getArguments(); array_shift($arguments); $callStructure = $initialize->getCallStructure(); $callStructure[] = $initialize; $this->setFlags($initialize->getFlags()); $this->setOptions($initialize->getOptions()); $this->setArguments($arguments); $this->setCallStructure($callStructure); } else { if ($initialize == true) { // Parse arguments from user input $this->parseArguments(); } } if ($initialize) { self::$_instance = $this; // Run the command $this->_run(); } }
public function initialize() { parent::initialize(); $this->loadConfig(); }
/** * Create (or modify) given class * * @param string $className * @param Zend_CodeGenerator_Php_Class $class * * @return Zend_CodeGenerator_Php_Class */ public static function create($className, Zend_CodeGenerator_Php_Class $class = null) { // If no class data is given and the class already exists there's no point in "creating" it if ($class == null and XDT_CLI_Helper::classExists($className)) { return self::get($className); } // Only create class if the file is available or we have class data $filePath = self::getClassPath($className); $fileContents = file_exists($filePath) ? file_get_contents($filePath) : false; if (empty($fileContents) or $class != null) { // Load blank CodeGenerator file $file = new Zend_CodeGenerator_Php_File(); // Create CodeGenerato Class if it wasn't provided as a parm if ($class == null) { $class = new Zend_CodeGenerator_Php_Class(); $class->setName($className); } // Append class to file $file->setClass($class); // Write to file XDT_CLI_Helper::writeToFile($filePath, $file->generate(), true); XDT_CLI_Abstract::getInstance()->printMessage("File: " . $filePath); } else { XDT_CLI_Abstract::getInstance()->bail("File already exists: " . $filePath); } return self::get($className); }