예제 #1
0
 /**
  * @param Configuration  $configuration
  * @param ServiceManager $serviceManager
  */
 public function __construct(Configuration $configuration, ServiceManager $serviceManager)
 {
     if (!$configuration->get('twig', null)) {
         return;
     }
     $cachePath = $configuration->getApplicationPath() . DIRECTORY_SEPARATOR . 'storage' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
     $options = [];
     if ($configuration->get('cache.config.enabled', false)) {
         $options['cache'] = $cachePath;
     }
     $paths = $configuration->get('twig.paths', []);
     foreach ($paths as $offset => $path) {
         $paths[$offset] = dirname($configuration->getApplicationPath()) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . $path;
     }
     $loader = new \Twig_Loader_Filesystem($paths);
     $this->twig = new \Twig_Environment($loader, $options + $configuration->get('twig.options', []));
     if (isset($configuration->get('twig.options', [])['debug']) && $configuration->get('twig.options', [])['debug']) {
         $this->twig->addExtension(new \Twig_Extension_Debug());
     }
     foreach ($configuration->get('twig.helpers', []) as $functionName => $helperClass) {
         $func = new \Twig_SimpleFunction($functionName, function () use($helperClass, $serviceManager) {
             $instance = $serviceManager->load($helperClass);
             return call_user_func_array($instance, func_get_args());
         });
         $this->twig->addFunction($func);
     }
     foreach ($configuration->get('twig.filters', []) as $functionName => $helperClass) {
         $func = new \Twig_SimpleFilter($functionName, function () use($helperClass, $serviceManager) {
             $instance = $serviceManager->load($helperClass);
             return call_user_func_array($instance, func_get_args());
         });
         $this->twig->addFilter($func);
     }
 }
    /**
     * @param Input $input
     */
    public function __invoke(Input $input)
    {
        $this->climate->br();
        $name = $input->getArgument('name');
        if (FALSE === strstr($name, '/')) {
            $name = 'middleout/arhitect-' . $name;
        }
        $ownerName = explode('/', $name);
        $packageName = $ownerName[1];
        $ownerName = $ownerName[0];
        $this->climate->yellow('Installing Arhitect Package ' . $ownerName . '/' . $packageName);
        $version = '';
        $inputVersion = $input->getArgument('version');
        if ($inputVersion) {
            $version = ':' . $inputVersion;
        }
        $preferDev = ' require ';
        $inputVersion = $input->getOption('dev');
        if ($inputVersion) {
            $preferDev = ' require --dev ';
        }
        $this->climate->darkGray("composer" . $preferDev . $name . $version . ' --prefer-dist');
        $result = shell_exec("composer" . $preferDev . $name . $version . ' --prefer-dist');
        $this->climate->yellow($result);
        $configOwnerName = $ownerName;
        $configPackageName = $packageName;
        if ($configOwnerName == 'middleout') {
            $configOwnerName = 'arhitect';
            $configPackageName = str_replace('arhitect-', '', $configPackageName);
        }
        $path = getcwd() . '/vendor/' . $ownerName . '/' . $packageName . '/app/config';
        $path = str_replace('config/middleout/arhitect-', 'config/arhitect/', $path);
        if (is_dir($path)) {
            $this->copy($path, $this->configuration->getApplicationPath() . '/config/' . $configOwnerName);
        }
        $readme = getcwd() . '/vendor/' . $ownerName . '/' . $packageName . '/post-install.md';
        if (is_file($readme)) {
            $postInstallMessage = file_get_contents($readme);
        }
        $this->climate->br(2);
        if (!$postInstallMessage) {
            $this->climate->green(<<<ART
               ______________________________________
      ________|                                      |_______
      \\       |            MODULE INSTALLED          |      /
       \\      |    Let the coding session begin !    |     /
       /      |______________________________________|     \\
      /__________)                                (_________\\

ART
);
        } else {
            $this->climate->green('Module installed. The developer would like to tell you the following:');
            $this->climate->br(2);
            $this->climate->yellow($postInstallMessage);
        }
        $this->climate->br(2);
    }
 /**
  * @param Request  $request
  * @param callable $next
  *
  * @return mixed
  */
 public function handle(Request $request, callable $next)
 {
     $storagePath = $this->configuration->getApplicationPath();
     $storagePath .= DIRECTORY_SEPARATOR . 'storage' . DIRECTORY_SEPARATOR . 'maintenance';
     if (file_exists($storagePath)) {
         return new Response($this->getHtml(), Response::HTTP_SERVICE_UNAVAILABLE);
     }
     return $next($request);
 }
예제 #4
0
 /**
  * @return null
  */
 public function __invoke()
 {
     $cachePath = $this->configuration->getApplicationPath();
     $cachePath .= '/storage';
     if (file_exists($cachePath . '/maintenance')) {
         unlink($cachePath . '/maintenance');
     }
     $this->climate->green('Application is now live.');
     $this->climate->out('');
 }
예제 #5
0
 /**
  * @return null
  */
 public function __invoke()
 {
     $cachePath = $this->configuration->getApplicationPath();
     $cachePath .= '/storage';
     if (!file_exists($cachePath . '/maintenance')) {
         file_put_contents($cachePath . '/maintenance', '');
     }
     $this->climate->yellow('Application is now in maintenance mode.');
     $this->climate->out('');
 }
예제 #6
0
    /**
     * @param Input $input
     */
    public function __invoke(Input $input)
    {
        $this->climate->br();
        $name = $input->getArgument('name');
        if (FALSE === strstr($name, '/')) {
            $name = 'middleout/arhitect-' . $name;
        }
        $ownerName = explode('/', $name);
        $packageName = $ownerName[1];
        $ownerName = $ownerName[0];
        $this->climate->yellow('Updating Arhitect Package ' . $ownerName . '/' . $packageName);
        $version = '';
        $inputVersion = $input->getArgument('version');
        if ($inputVersion) {
            $version = ':' . $inputVersion;
        }
        $preferDev = ' require ';
        $inputVersion = $input->getOption('dev');
        if ($inputVersion) {
            $preferDev = ' require --dev ';
        }
        $this->climate->darkGray("composer" . $preferDev . $name . $version . ' --prefer-dist');
        $result = shell_exec("composer" . $preferDev . $name . $version . ' --prefer-dist');
        $this->climate->yellow($result);
        $configOwnerName = $ownerName;
        $configPackageName = $packageName;
        if ($configOwnerName == 'middleout') {
            $configOwnerName = 'arhitect';
            $configPackageName = str_replace('arhitect-', '', $configPackageName);
        }
        $path = getcwd() . '/vendor/' . $ownerName . '/' . $packageName . '/app/config/' . $configOwnerName . '/' . $configPackageName;
        $path = str_replace('config/middleout/arhitect-', 'config/arhitect/', $path);
        if (is_dir($path)) {
            $this->copy($path, $this->configuration->getApplicationPath() . '/config/' . $configOwnerName . '/' . $configPackageName);
        }
        $this->climate->br(2);
        $this->climate->green(<<<ART
           ______________________________________
  ________|                                      |_______
  \\       |            MODULE UPDATED            |      /
   \\      |  Let the coding session continue :)  |     /
   /      |______________________________________|     \\
  /__________)                                (_________\\

ART
);
        $this->climate->br(2);
    }
예제 #7
0
 /**
  * @param Configuration $config
  * @param Request       $request
  */
 public function __construct(Configuration $config, Request $request)
 {
     $this->request = $request;
     $container = $config->get('routes', []);
     if (!$container) {
         throw new \InvalidArgumentException('Routes must be defined in the configuration');
     }
     if ($config->get('cache.config.enabled', FALSE)) {
         $cachePath = $config->getApplicationPath() . DIRECTORY_SEPARATOR . 'storage' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'router';
         if (file_exists($cachePath)) {
             $oldRouter = unserialize(file_get_contents($cachePath));
             foreach ($oldRouter as $prop => $value) {
                 $this->{$prop} = $value;
             }
             return;
         }
     }
     parent::__construct(new RouteCollection(new RouteFactory('Arhitect\\Router\\Adapter\\RouteAdapter')), new Generator());
     foreach ($container as $routeName => $details) {
         if (isset($details['middlewares'])) {
             if (is_array($details['middlewares'])) {
                 $this->middlewares[$routeName] = $details['middlewares'];
             }
         }
         if (isset($details['extends']) && FALSE != $details['extends']) {
             $path = [$routeName];
             $parent = isset($container[$details['extends']]) ? $container[$details['extends']] : NULL;
             $parentName = isset($container[$details['extends']]) ? $details['extends'] : NULL;
             while ($parent) {
                 $path[] = $parentName;
                 if (isset($parent['extends'])) {
                     $parentName = $parent['extends'];
                     $parent = $container[$parent['extends']];
                 } else {
                     $parent = NULL;
                 }
             }
             $call = [];
             $that = $this;
             foreach ($path as $offset => $item) {
                 if (!$call) {
                     $call[$item] = function ($router) use($that, $container, $item) {
                         /** @var Route $route */
                         $route = $router->add($item, $container[$item]['path']);
                         $container[$item]['path'] = $route->path;
                         $tmp = $that->addRoute($route->name, $container[$item]);
                         $router->offsetSet($route->name, $tmp);
                     };
                     continue;
                 }
                 if ($offset == count($path) - 1) {
                     break;
                 }
                 $call[$item] = function ($router) use($container, $item, $call, $offset, $path) {
                     $router->attach($item, $container[$item]['path'], $call[$path[$offset - 1]]);
                 };
             }
             $this->attach($path[$offset], $container[$path[$offset]]['path'], $call[$path[$offset - 1]]);
             continue;
         }
         if (!$this->offsetExists($routeName)) {
             $this->offsetSet($routeName, $this->addRoute($routeName, $details));
         }
     }
     if ($config->get('cache.config.enabled', FALSE)) {
         file_put_contents($cachePath, serialize($this));
     }
 }