/**
  * Handle the command.
  *
  * @param Configurator $configurator
  * @param Application  $application
  */
 public function handle(Configurator $configurator, Application $application)
 {
     // Load package configuration.
     $configurator->addNamespace('streams', realpath(__DIR__ . '/../../../resources/config'));
     // Load application overrides.
     $configurator->addNamespaceOverrides('streams', $application->getResourcesPath('streams/config'));
     // Load system overrides.
     $configurator->addNamespaceOverrides('streams', base_path('resources/streams/config'));
 }
 /**
  * Register an addon.
  *
  * @param $path
  * @param $enabled
  * @param $installed
  */
 public function register($path, array $enabled, array $installed)
 {
     if (!is_dir($path)) {
         return;
     }
     $vendor = strtolower(basename(dirname($path)));
     $slug = strtolower(substr(basename($path), 0, strpos(basename($path), '-')));
     $type = strtolower(substr(basename($path), strpos(basename($path), '-') + 1));
     $class = studly_case($vendor) . '\\' . studly_case($slug) . studly_case($type) . '\\' . studly_case($slug) . studly_case($type);
     /* @var Addon|Module|Extension|Twig_ExtensionInterface $addon */
     $addon = app($class)->setPath($path)->setType($type)->setSlug($slug)->setVendor($vendor);
     // If the addon supports states - set the state now.
     if ($addon->getType() === 'module' || $addon->getType() === 'extension') {
         $addon->setInstalled(in_array($addon->getNamespace(), $installed));
         $addon->setEnabled(in_array($addon->getNamespace(), $enabled));
     }
     // Bind to the service container.
     $this->container->alias($addon->getNamespace(), $alias = get_class($addon));
     $this->container->instance($alias, $addon);
     // Load package configuration.
     $this->configurator->addNamespace($addon->getNamespace(), $addon->getPath('resources/config'));
     // Load system overrides.
     $this->configurator->addNamespaceOverrides($addon->getNamespace(), base_path('resources/addons/' . $addon->getVendor() . '/' . $addon->getSlug() . '-' . $addon->getType()));
     // Load application overrides.
     $this->configurator->addNamespaceOverrides($addon->getNamespace(), $this->application->getResourcesPath('addons/' . $addon->getVendor() . '/' . $addon->getSlug() . '-' . $addon->getType() . '/config'));
     // Continue loading things.
     $this->provider->register($addon);
     // Add the view / translation namespaces.
     $this->views->addNamespace($addon->getNamespace(), $addon->getPath('resources/views'));
     $this->translator->addNamespace($addon->getNamespace(), $addon->getPath('resources/lang'));
     /*
      * If the addon is a plugin then
      * load it into Twig when appropriate.
      */
     if ($addon->getType() === 'plugin') {
         $this->events->listen('Anomaly\\Streams\\Platform\\View\\Event\\RegisteringTwigPlugins', function (RegisteringTwigPlugins $event) use($addon) {
             $twig = $event->getTwig();
             $twig->addExtension($addon);
         });
     }
     $this->collection->put($addon->getNamespace(), $addon);
     $this->events->fire(new AddonWasRegistered($addon));
 }