/**
     * @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);
 }
Beispiel #3
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('');
 }
 /**
  * @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('');
 }
    /**
     * @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);
    }
 /**
  * @param Configuration $configuration
  */
 public function __construct(Configuration $configuration)
 {
     $cacheOptions = $configuration->get('cache.application');
     if (!$cacheOptions['enabled']) {
         $this->enabled = false;
         return;
     }
     $options = !isset($cacheOptions['options']) ? [] : $cacheOptions['options'];
     if (!is_array($options)) {
         $options = [$options];
     }
     $driverClassName = 'Stash\\Driver\\' . $cacheOptions['driver'];
     $driver = new $driverClassName();
     $driver->setOptions($options);
     $this->pool = new Stash\Pool($driver);
 }
 /**
  * @return null
  */
 public function __invoke()
 {
     $requestMiddlewares = $this->configuration->get('middlewares', []);
     $routeMiddlewares = $this->configuration->get('routes', []);
     ksort($requestMiddlewares);
     $table = [];
     foreach ($requestMiddlewares as $priority => $className) {
         $table[] = ['Priority' => $priority, 'Class name' => $className, 'Route' => 'Any', 'When' => 'On Request'];
     }
     foreach ($routeMiddlewares as $routeName => $details) {
         if (!isset($details['middlewares']) || !is_array($details['middlewares'])) {
             continue;
         }
         foreach ($details['middlewares'] as $priority => $className) {
             $table[] = ['Priority' => $priority, 'Class name' => $className, 'Route' => $routeName, 'When' => 'Only on route match'];
         }
     }
     $this->climate->out('');
     $this->climate->yellowTable($table);
     $this->climate->out('');
 }
 /**
  * @return null
  */
 public function __invoke()
 {
     $services = $this->configuration->get('services', []);
     $table = [];
     foreach ($services as $providerClass) {
         /** @var ServiceProvider $provider */
         $provider = new $providerClass();
         $provides = $provider->provide();
         if (is_callable($provides)) {
             try {
                 $provides = $this->serviceManager->get(is_array($provider->alias()) ? $provider->alias()[0] : $provider->alias());
                 $provides = 'Factory => ' . get_class($provides);
             } catch (\Exception $e) {
                 $provides = 'Factory => (ERROR. Could not load by "Class")';
             }
         }
         $table[] = ['Class' => implode(',', is_array($provider->alias()) ? $provider->alias() : [$provider->alias()]), 'Provides' => $provides, 'Defined by' => $providerClass];
     }
     $this->climate->out('');
     $this->climate->yellowTable($table);
     $this->climate->out('');
 }
Beispiel #9
0
 /**
  * @param Configuration $configuration
  *
  * @return LeagueContainer
  */
 protected function prepareServiceManager(Configuration $configuration)
 {
     $container = $this->config->get('services', []);
     $serviceManager = new LeagueAdapter();
     foreach ($container as $className) {
         /** @var ServiceProvider $provider */
         $provider = new $className();
         if ($provider instanceof ServiceProvider) {
             throw new \InvalidArgumentException(sprintf('Provider %s must be ServiceProvider', $className));
         }
         $aliases = $provider->alias();
         if (!is_array($aliases)) {
             $aliases = [$aliases];
         }
         foreach ($aliases as $alias) {
             if ($provider->share()) {
                 $serviceManager->share($alias);
             }
             if ($provider instanceof ServiceManager\SetterInjectorProvider) {
                 $serviceManager->inflector($provider->inflector())->invokeMethod($provider->method(), [$alias]);
             }
             $provides = $provider->provide();
             if (!is_callable($provides)) {
                 $serviceManager->alias($alias, $provides);
                 continue;
             }
             $serviceManager->add($alias, function () use($provides, $serviceManager) {
                 return $serviceManager->call($provides);
             });
         }
     }
     // Add the ServiceManager and the Configuration
     $serviceManager->add(LeagueAdapter::class, $serviceManager);
     $serviceManager->add(ConfigurationContainer::class, $this->config);
     return $serviceManager;
 }
 /**
  * @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));
     }
 }
Beispiel #11
0
 /**
  * @param Configuration $configuration
  * @param Request       $request
  */
 public function __construct(Configuration $configuration, Request $request)
 {
     $this->version = $configuration->get('twig.assets.version', time());
     $this->path = $configuration->get('twig.assets.path', $request->getBasePath());
 }
Beispiel #12
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);
     }
 }