Exemple #1
0
 /**
  * Check dependencies
  *
  * @param Compiler $compiler
  */
 public function checkDependencies(Compiler $compiler)
 {
     $classDefinition = $this->_classDefinition;
     $extendedClass = $classDefinition->getExtendsClass();
     if ($extendedClass) {
         if ($classDefinition->getType() == 'class') {
             if ($compiler->isClass($extendedClass)) {
                 $extendedDefinition = $compiler->getClassDefinition($extendedClass);
                 $classDefinition->setExtendsClassDefinition($extendedDefinition);
             } else {
                 if ($compiler->isBundledClass($extendedClass)) {
                     $extendedDefinition = $compiler->getInternalClassDefinition($extendedClass);
                     $classDefinition->setExtendsClassDefinition($extendedDefinition);
                 } else {
                     $extendedDefinition = new ClassDefinitionRuntime($extendedClass);
                     $classDefinition->setExtendsClassDefinition($extendedDefinition);
                     $this->_logger->warning('Cannot locate class "' . $extendedClass . '" when extending class "' . $classDefinition->getCompleteName() . '"', 'nonexistent-class', $this->_originalNode);
                 }
             }
         } else {
             if ($compiler->isInterface($extendedClass)) {
                 $extendedDefinition = $compiler->getClassDefinition($extendedClass);
                 $classDefinition->setExtendsClassDefinition($extendedDefinition);
             } else {
                 if ($compiler->isBundledInterface($extendedClass)) {
                     $extendedDefinition = $compiler->getInternalClassDefinition($extendedClass);
                     $classDefinition->setExtendsClassDefinition($extendedDefinition);
                 } else {
                     $extendedDefinition = new ClassDefinitionRuntime($extendedClass);
                     $classDefinition->setExtendsClassDefinition($extendedDefinition);
                     $this->_logger->warning('Cannot locate class "' . $extendedClass . '" when extending interface "' . $classDefinition->getCompleteName() . '"', 'nonexistent-class', $this->_originalNode);
                 }
             }
         }
     }
     $implementedInterfaces = $classDefinition->getImplementedInterfaces();
     if ($implementedInterfaces) {
         $interfaceDefinitions = array();
         foreach ($implementedInterfaces as $interface) {
             if ($compiler->isInterface($interface)) {
                 $interfaceDefinitions[$interface] = $compiler->getClassDefinition($interface);
             } else {
                 if ($compiler->isBundledInterface($interface)) {
                     $interfaceDefinitions[$interface] = $compiler->getInternalClassDefinition($interface);
                 } else {
                     $extendedDefinition = new ClassDefinitionRuntime($extendedClass);
                     $classDefinition->setExtendsClassDefinition($extendedDefinition);
                     $this->_logger->warning('Cannot locate class "' . $interface . '" when extending interface "' . $classDefinition->getCompleteName() . '"', 'nonexistent-class', $this->_originalNode);
                 }
             }
         }
         if ($interfaceDefinitions) {
             $classDefinition->setImplementedInterfaceDefinitions($interfaceDefinitions);
         }
     }
 }
Exemple #2
0
 /**
  * Checks which files in the base kernel must be copied
  *
  * @return boolean
  */
 protected function checkKernelFiles()
 {
     $configured = $this->recursiveProcess(realpath(__DIR__ . '/../ext/kernel'), 'ext/kernel', '@^.*\\.c|h$@', array($this, 'checkKernelFile'));
     if (!$configured) {
         $this->logger->output('Copying new kernel files...');
         exec("rm -fr ext/kernel/*");
         $this->recursiveProcess(realpath(__DIR__ . '/../ext/kernel'), 'ext/kernel', '@^.*\\.c|h$@');
     }
     return !$configured;
 }
Exemple #3
0
 /**
  * Checks which files in the base kernel must be copied
  *
  * @return boolean
  */
 protected function checkKernelFiles()
 {
     $kernelPath = "ext/kernel";
     if (!file_exists($kernelPath)) {
         $kernelDone = mkdir($kernelPath, 0775, true);
         if (!$kernelDone) {
             throw new Exception("Cannot create kernel directory");
         }
     }
     $kernelPath = realpath($kernelPath);
     $sourceKernelPath = $this->backend->getInternalKernelPath();
     $configured = $this->recursiveProcess($sourceKernelPath, $kernelPath, '@.*\\.[ch]$@', array($this, 'checkKernelFile'));
     if (!$configured) {
         $this->logger->output('Copying new kernel files...');
         $this->recursiveDeletePath($kernelPath, '@^.*\\.[lcho]$@');
         @mkdir($kernelPath);
         $this->recursiveProcess($sourceKernelPath, $kernelPath, '@^.*\\.[ch]$@');
     }
     return !$configured;
 }
Exemple #4
0
 /**
  * Boots the compiler executing the specified action
  */
 public static function boot()
 {
     try {
         /**
          * Global config
          */
         $config = new Config();
         register_shutdown_function(array($config, 'saveOnExit'));
         /**
          * Global logger
          */
         $logger = new Logger($config);
         if (isset($_SERVER['argv'][1])) {
             $action = $_SERVER['argv'][1];
         } else {
             $action = 'help';
         }
         /**
          * Change configurations flags
          */
         if ($_SERVER['argc'] >= 2) {
             for ($i = 2; $i < $_SERVER['argc']; $i++) {
                 $parameter = $_SERVER['argv'][$i];
                 if (preg_match('/^-fno-([a-z0-9\\-]+)$/', $parameter, $matches)) {
                     $config->set($matches[1], false, 'optimizations');
                     continue;
                 }
                 if (preg_match('/^-f([a-z0-9\\-]+)$/', $parameter, $matches)) {
                     $config->set($matches[1], true, 'optimizations');
                 }
                 if (preg_match('/^-W([a-z0-9\\-]+)$/', $parameter, $matches)) {
                     $logger->set($matches[1], false, 'warnings');
                     continue;
                 }
                 if (preg_match('/^-w([a-z0-9\\-]+)$/', $parameter, $matches)) {
                     $logger->set($matches[1], true, 'warnings');
                     continue;
                 }
                 if (preg_match('/^--([a-z0-9\\-]+)$/', $parameter, $matches)) {
                     $config->set($matches[1], true, 'extra');
                     continue;
                 }
                 if (preg_match('/^--([a-z0-9\\-]+)=(.*)$/', $parameter, $matches)) {
                     $config->set($matches[1], $matches[2], 'extra');
                     continue;
                 }
                 switch ($parameter) {
                     case '-w':
                         $config->set('silent', true);
                         break;
                     case '-v':
                         $config->set('verbose', true);
                         break;
                     case '-V':
                         $config->set('verbose', false);
                         break;
                     default:
                         break;
                 }
             }
         }
         /**
          * Register built-in commands
          * @var $item \DirectoryIterator
          */
         foreach (new \DirectoryIterator(ZEPHIRPATH . 'Library/Commands') as $item) {
             if (!$item->isDir()) {
                 $className = 'Zephir\\Commands\\' . str_replace('.php', '', $item->getBaseName());
                 $class = new \ReflectionClass($className);
                 if (!$class->isAbstract() && !$class->isInterface()) {
                     /**
                      * @var $command CommandAbstract
                      */
                     $command = new $className();
                     if (!$command instanceof CommandAbstract) {
                         throw new \Exception('Class ' . $class->name . ' must be instance of CommandAbstract');
                     }
                     self::$commands[$command->getCommand()] = $command;
                 }
             }
         }
         if (!isset(self::$commands[$action])) {
             $message = 'Unrecognized action "' . $action . '"';
             $metaphone = metaphone($action);
             foreach (self::$commands as $key => $command) {
                 if (metaphone($key) == $metaphone) {
                     $message .= PHP_EOL . PHP_EOL . 'Did you mean "' . $key . '"?';
                 }
             }
             throw new \Exception($message);
         }
         /**
          * Execute the command
          */
         self::$commands[$action]->execute($config, $logger);
     } catch (\Exception $e) {
         self::showException($e, isset($config) ? $config : null);
     }
 }