Esempio n. 1
0
 /**
  * Dispatch the command line actions.
  * @param array command line arguments
  */
 public function run($args)
 {
     echo "Command line tools for Prado " . Prado::getVersion() . ".\n";
     if (count($args) > 1) {
         array_shift($args);
     }
     $valid = false;
     foreach ($this->_actions as $class => $action) {
         if ($action->isValidAction($args)) {
             $valid |= $action->performAction($args);
             break;
         } else {
             $valid = false;
         }
     }
     if (!$valid) {
         $this->printHelp();
     }
 }
Esempio n. 2
0
 protected function resolvePaths($basePath)
 {
     if (empty($basePath) || ($basePath = realpath($basePath)) === false) {
         throw new TConfigurationException('application_basepath_invalid', $basePath);
     }
     if (is_dir($basePath) && is_file($basePath . DIRECTORY_SEPARATOR . $this->getConfigurationFileName())) {
         $configFile = $basePath . DIRECTORY_SEPARATOR . $this->getConfigurationFileName();
     } else {
         if (is_file($basePath)) {
             $configFile = $basePath;
             $basePath = dirname($configFile);
         } else {
             $configFile = null;
         }
     }
     $runtimePath = $basePath . DIRECTORY_SEPARATOR . self::RUNTIME_PATH;
     if (is_writable($runtimePath)) {
         if ($configFile !== null) {
             $runtimePath .= DIRECTORY_SEPARATOR . basename($configFile) . '-' . Prado::getVersion();
             if (!is_dir($runtimePath)) {
                 if (@mkdir($runtimePath) === false) {
                     throw new TConfigurationException('application_runtimepath_failed', $runtimePath);
                 }
                 @chmod($runtimePath, PRADO_CHMOD);
             }
             $this->setConfigurationFile($configFile);
         }
         $this->setBasePath($basePath);
         $this->setRuntimePath($runtimePath);
     } else {
         throw new TConfigurationException('application_runtimepath_invalid', $runtimePath);
     }
 }
Esempio n. 3
0
 /**
  * Generate a CRC32 hash for the directory path. Collisions are higher
  * than MD5 but generates a much smaller hash string.
  * @param string string to be hashed.
  * @return string hashed string.
  */
 protected function hash($dir)
 {
     return sprintf('%x', crc32($dir . Prado::getVersion()));
 }
Esempio n. 4
0
 /**
  * Displays exception information.
  * Exceptions are displayed with rich context information, including
  * the call stack and the context source code.
  * This method is only invoked when application is in <b>Debug</b> mode.
  * @param Exception exception instance
  */
 protected function displayException($exception)
 {
     if (php_sapi_name() === 'cli') {
         echo $exception->getMessage() . "\n";
         echo $exception->getTraceAsString();
         return;
     }
     if ($exception instanceof TTemplateException) {
         $fileName = $exception->getTemplateFile();
         $lines = empty($fileName) ? explode("\n", $exception->getTemplateSource()) : @file($fileName);
         $source = $this->getSourceCode($lines, $exception->getLineNumber());
         if ($fileName === '') {
             $fileName = '---embedded template---';
         }
         $errorLine = $exception->getLineNumber();
     } else {
         if (($trace = $this->getExactTrace($exception)) !== null) {
             $fileName = $trace['file'];
             $errorLine = $trace['line'];
         } else {
             $fileName = $exception->getFile();
             $errorLine = $exception->getLine();
         }
         $source = $this->getSourceCode(@file($fileName), $errorLine);
     }
     if ($this->getApplication()->getMode() === TApplicationMode::Debug) {
         $version = $_SERVER['SERVER_SOFTWARE'] . ' <a href="http://www.pradosoft.com/">PRADO</a>/' . Prado::getVersion();
     } else {
         $version = '';
     }
     $tokens = array('%%ErrorType%%' => get_class($exception), '%%ErrorMessage%%' => $this->addLink(htmlspecialchars($exception->getMessage())), '%%SourceFile%%' => htmlspecialchars($fileName) . ' (' . $errorLine . ')', '%%SourceCode%%' => $source, '%%StackTrace%%' => htmlspecialchars($exception->getTraceAsString()), '%%Version%%' => $version, '%%Time%%' => @strftime('%Y-%m-%d %H:%M', time()));
     $content = $this->getExceptionTemplate($exception);
     echo strtr($content, $tokens);
 }
Esempio n. 5
0
 public static function printGreeting()
 {
     echo "Command line tools for Prado " . Prado::getVersion() . ".\n";
 }
Esempio n. 6
0
 /**
  * @param Exception exception details.
  * @return array exception stack trace details.
  */
 private function getExceptionStackTrace($exception)
 {
     $data['code'] = $exception->getCode() > 0 ? $exception->getCode() : 500;
     $data['file'] = $exception->getFile();
     $data['line'] = $exception->getLine();
     $data['trace'] = $exception->getTrace();
     if ($exception instanceof TPhpErrorException) {
         // if PHP exception, we want to show the 2nd stack level context
         // because the 1st stack level is of little use (it's in error handler)
         if (isset($trace[0]) && isset($trace[0]['file']) && isset($trace[0]['line'])) {
             $data['file'] = $trace[0]['file'];
             $data['line'] = $trace[0]['line'];
         }
     }
     $data['type'] = get_class($exception);
     $data['message'] = $exception->getMessage();
     $data['version'] = $_SERVER['SERVER_SOFTWARE'] . ' ' . Prado::getVersion();
     $data['time'] = @strftime('%Y-%m-%d %H:%M', time());
     return $data;
 }
Esempio n. 7
0
 public function saveAsDWExtension($basePath)
 {
     $tagPath = $basePath . '/Configuration/TagLibraries/PRADO';
     // prepare the directory to save tag lib
     @mkdir($basePath . '/Configuration');
     @mkdir($basePath . '/Configuration/TagLibraries');
     @mkdir($basePath . '/Configuration/TagLibraries/PRADO');
     $docMXI = new PradoMXIDocument(Prado::getVersion());
     $tagChooser = new PradoTagChooser();
     $controlClass = new ReflectionClass('TControl');
     foreach ($this->_classes as $className => $classInfo) {
         $class = new ReflectionClass($className);
         if ($class->isInstantiable() && ($className === 'TControl' || $class->isSubclassOf($controlClass))) {
             $docMXI->addTag($className);
             $tagChooser->addElement($className);
             $docVTM = new PradoVTMDocument($className);
             foreach ($classInfo['Properties'] as $name => $property) {
                 $type = $property['type'];
                 if (isset($this->_classes[$type]) && ($type === 'TFont' || strrpos($type, 'Style') === strlen($type) - 5 && $type !== 'TStyle')) {
                     $this->processObjectType($type, $this->_classes[$type], $name, $docVTM);
                 }
                 if ($property['readonly'] || $property['protected']) {
                     continue;
                 }
                 if (($type = $this->checkType($className, $name, $property['type'])) !== '') {
                     $docVTM->addAttribute($name, $type);
                 }
             }
             foreach ($classInfo['Events'] as $name => $event) {
                 $docVTM->addEvent($name);
             }
             file_put_contents($tagPath . '/' . $className . '.vtm', $docVTM->getXML());
         }
     }
     file_put_contents($basePath . '/PRADO.mxi', $docMXI->getXML());
     file_put_contents($tagPath . '/TagChooser.xml', $tagChooser->getXML());
 }