function boot($rootDir, $urlDepth = 0, callable $onStartUp = null)
 {
     $rootDir = normalizePath($rootDir);
     // Initialize some settings from environment variables
     $dotenv = new Dotenv("{$rootDir}/.env");
     try {
         $dotenv->load();
     } catch (ConfigException $e) {
         echo $e->getMessage();
         return 1;
     }
     // Load the kernel's configuration.
     /** @var KernelSettings $kernelSettings */
     $kernelSettings = $this->kernelSettings = $this->injector->share(KernelSettings::class, 'app')->make(KernelSettings::class);
     $kernelSettings->isWebBased = true;
     $kernelSettings->setApplicationRoot($rootDir, $urlDepth);
     // Setup debugging (must be done before instantiating the kernel, but after instantiating its settings).
     $this->setupDebugging($rootDir);
     // Boot up the framework's kernel.
     $this->injector->execute([KernelModule::class, 'register']);
     // Boot up the framework's subsytems and the application's modules.
     /** @var KernelInterface $kernel */
     $kernel = $this->injector->make(KernelInterface::class);
     if ($onStartUp) {
         $onStartUp($kernel);
     }
     // Boot up all modules.
     try {
         $kernel->boot();
     } catch (ConfigException $e) {
         $NL = "<br>\n";
         echo $e->getMessage() . $NL . $NL;
         if ($e->getCode() == -1) {
             echo sprintf('Possile error causes:%2$s%2$s- the class name may be misspelled,%2$s- the class may no longer exist,%2$s- module %1$s may be missing or it may be corrupted.%2$s%2$s', str_match($e->getMessage(), '/from module (\\S+)/')[1], $NL);
         }
         $path = "{$kernelSettings->storagePath}/" . ModulesRegistry::REGISTRY_FILE;
         if (file_exists($path)) {
             echo "Tip: one possible solution is to remove the '{$path}' file and run 'workman' to rebuild the module registry.";
         }
     }
     // Finalize.
     if ($kernel->devEnv()) {
         $this->setDebugPathsMap($this->injector->make(ModulesRegistry::class));
     }
     return $kernel->getExitCode();
 }
Example #2
0
 /**
  * Pre-compiles the given simple binding expression.
  *
  * <p>Simple expressions do not have operators or filters. They are comprised of constants or property access chains
  * only.
  *
  * <p>**Ex:** `'a.b.c'`, `'123'`, `'"text"'`, `'false'`, `'Class::constant'`, '&#64;prop', `'#block'`.
  *
  * > <p>**Note:** simple expressions are used on the main part of a databinding expression and as expression filter
  * arguments.
  *
  * @param string[] $segments Expression segments split by dot.
  * @return string
  * @throws DataBindingException
  */
 static function translateSimpleExpSegs(array $segments)
 {
     if (count($segments) == 1) {
         $seg = $segments[0];
         if ($seg[0] == '#') {
             return sprintf('%s->renderBlock("%s")', self::BINDER_PARAM, substr($seg, 1));
         }
         PhpCode::evalConstant($seg, $ok);
         if ($ok) {
             return $seg;
         }
         if (is_callable($seg)) {
             return "{$seg}()";
         }
     }
     $exp = $unary = '';
     foreach ($segments as $i => $seg) {
         if ($i) {
             $exp = "_g({$exp},'{$seg}')";
         } else {
             list(, $unary, $seg) = str_match($seg, '/^(!*)(.*)/', 2);
             // If not a constant value, convert it to a property access expression fragment.
             if ($seg[0] == '"' || $seg[0] == "'" || ctype_digit($seg)) {
                 $exp = $seg;
             } else {
                 $exp = $seg[0] == '@' ? sprintf("%s->prop('%s')", self::BINDER_PARAM, substr($seg, 1)) : self::BINDER_PARAM . "->get('{$seg}')";
             }
         }
     }
     $exp = "{$unary}{$exp}";
     if (!PhpCode::validateExpression($exp)) {
         throw new DataBindingException(sprintf("Invalid expression <kbd>%s</kbd>.", implode('.', $segments)));
     }
     return $exp;
 }