/**
  * Configure Streams.
  *
  * @param Application $application
  */
 public function boot(Application $application)
 {
     if (!$application->isInstalled()) {
         return;
     }
     $this->dispatch(new ConfigureSystem());
 }
 /**
  * Get the storage path.
  *
  * @return string
  */
 public function getStoragePath()
 {
     if (!($path = $this->getFilePath())) {
         return null;
     }
     return $this->application->getStoragePath($path);
 }
 /**
  * Handle the command.
  *
  * @param Application $application
  */
 public function handle(Application $application, Filesystem $files)
 {
     if (!class_exists('TeamTNT\\TNTSearch\\TNTSearch')) {
         return;
     }
     if (!class_exists($this->stream->getEntryModelName())) {
         return;
     }
     $model = $this->stream->getEntryModel();
     $index = $application->getStoragePath('search/' . $model->searchableAs() . '.index');
     if ($this->stream->isSearchable() && file_exists($index)) {
         return;
     }
     if (!$this->stream->isSearchable() && file_exists($index)) {
         $files->delete($index);
         return;
     }
     if (!$this->stream->isSearchable()) {
         return;
     }
     try {
         app(EngineManager::class)->engine('tntsearch')->initIndex($model);
     } catch (\Exception $e) {
         // Kewl.
     }
 }
 /**
  * Handle the command.
  */
 public function handle(Image $image, Container $container, Application $application)
 {
     $image->addPath('public', base_path('public'));
     $image->addPath('node', base_path('node_modules'));
     $image->addPath('asset', $application->getAssetsPath());
     $image->addPath('streams', $container->make('streams.path') . '/resources');
     $image->addPath('bower', $container->make('path.base') . '/bin/bower_components');
 }
 /**
  * Handle the command.
  *
  * @param  Filesystem  $filesystem
  * @param  Application $application
  * @return string
  */
 public function handle(Filesystem $filesystem, Application $application)
 {
     $destination = $application->getResourcesPath('streams/lang');
     if (is_dir($destination) && !$this->command->option('force')) {
         return $this->command->error("{$destination} already exists.");
     }
     $filesystem->copyDirectory(__DIR__ . '/../../../../resources/lang', $destination);
     $this->command->info("Published {$destination}");
 }
 /**
  * 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'));
 }
 /**
  * Handle the command.
  *
  * @param Filesystem  $files
  * @param Application $application
  */
 public function handle(Filesystem $files, Application $application)
 {
     $paths = ['storage', $application->getStoragePath(), 'public/assets', $application->getAssetsPath()];
     foreach ($paths as $path) {
         if ($files->exists(base_path($path)) && !$files->isWritable(base_path($path))) {
             die('chmod -R 777 ' . base_path($path));
         }
     }
 }
 /**
  * Handle the command.
  *
  * @param Application $application
  */
 public function handle(Application $application)
 {
     if (file_exists($routes = base_path('resources/streams/routes.php'))) {
         include $routes;
     }
     if (file_exists($routes = $application->getResourcesPath('routes.php'))) {
         include $routes;
     }
 }
 /**
  * Map additional routes.
  *
  * @param Filesystem  $files
  * @param Application $application
  */
 public function map(Filesystem $files, Application $application)
 {
     // Include public routes.
     if ($files->exists($routes = $application->getStoragePath('posts/routes.php'))) {
         $files->requireOnce($routes);
     } else {
         $files->requireOnce(__DIR__ . '/../resources/routes.php');
     }
 }
 /**
  * Handle the command.
  *
  * @param  Filesystem  $filesystem
  * @param  Application $application
  * @return string
  */
 public function handle(Filesystem $filesystem, Application $application)
 {
     $destination = $application->getResourcesPath('addons/' . $this->addon->getVendor() . '/' . $this->addon->getSlug() . '-' . $this->addon->getType() . '/views');
     if (is_dir($destination) && !$this->command->option('force')) {
         $this->command->error("{$destination} already exists.");
         return;
     }
     $filesystem->copyDirectory($this->addon->getPath('resources/views'), $destination);
     $this->command->info("Published {$destination}");
 }
 /**
  * Handle the command.
  */
 public function handle(Asset $asset, Container $container, Application $application)
 {
     $asset->addPath('public', public_path());
     $asset->addPath('node', base_path('node_modules'));
     $asset->addPath('asset', $application->getAssetsPath());
     $asset->addPath('storage', $application->getStoragePath());
     $asset->addPath('download', $application->getAssetsPath('assets/downloads'));
     $asset->addPath('streams', $container->make('streams.path') . '/resources');
     $asset->addPath('bower', $container->make('path.base') . '/bin/bower_components');
 }
 /**
  * Render a string template.
  *
  * @param       $template
  * @param array $payload
  * @return string
  * @throws \Exception
  */
 function render($template, array $payload = [])
 {
     $view = 'templates/' . md5($template);
     $path = $this->application->getStoragePath($view);
     if (!$this->files->isDirectory($directory = dirname($path))) {
         $this->files->makeDirectory($directory, 0777, true);
     }
     $this->files->put($path . '.twig', $template);
     return $this->view->make('storage::' . $view, $payload)->render();
 }
 /**
  * Handle the command.
  *
  * @param Application $application
  * @param Factory $views
  */
 public function handle(Application $application, Factory $views)
 {
     $views->composer('*', 'Anomaly\\Streams\\Platform\\View\\ViewComposer');
     $views->addNamespace('streams', __DIR__ . '/../../../resources/views');
     $views->addNamespace('resources', base_path('resources/views'));
     $views->addNamespace('storage', $application->getStoragePath());
     $views->addNamespace('app', $application->getResourcesPath());
     $views->addNamespace('root', base_path());
     $views->addExtension('html', 'php');
 }
 /**
  * Handle the comand.
  *
  * @param Parser      $parser
  * @param Application $application
  */
 public function handle(Parser $parser, Application $application)
 {
     $data = ['namespace' => (new EntryNamespaceParser())->parse($this->stream), 'class' => (new EntryTranslationsClassParser())->parse($this->stream), 'table' => (new EntryTranslationsTableParser())->parse($this->stream)];
     $template = file_get_contents(__DIR__ . '/../../../resources/stubs/models/translation.stub');
     $path = $application->getStoragePath('models/' . studly_case($this->stream->getNamespace()));
     $path .= '/' . studly_case($this->stream->getNamespace()) . studly_case($this->stream->getSlug());
     $file = $path . 'EntryTranslationsModel.php';
     @unlink($file);
     // Don't judge me..
     file_put_contents($file, $parser->parse($template, $data));
 }
 /**
  * Handle the command.
  *
  * @param Filesystem  $files
  * @param Parser      $parser
  * @param Application $application
  */
 public function handle(Filesystem $files, Parser $parser, Application $application)
 {
     $data = ['class' => (new EntryClassParser())->parse($this->stream), 'title' => (new EntryTitleParser())->parse($this->stream), 'table' => (new EntryTableParser())->parse($this->stream), 'rules' => (new EntryRulesParser())->parse($this->stream), 'dates' => (new EntryDatesParser())->parse($this->stream), 'stream' => (new EntryStreamParser())->parse($this->stream), 'trashable' => (new EntryTrashableParser())->parse($this->stream), 'relations' => (new EntryRelationsParser())->parse($this->stream), 'namespace' => (new EntryNamespaceParser())->parse($this->stream), 'field_slugs' => (new EntryFieldSlugsParser())->parse($this->stream), 'searchable' => (new EntrySearchableParser())->parse($this->stream), 'relationships' => (new EntryRelationshipsParser())->parse($this->stream), 'translation_model' => (new EntryTranslationModelParser())->parse($this->stream), 'translated_attributes' => (new EntryTranslatedAttributesParser())->parse($this->stream), 'translation_foreign_key' => (new EntryTranslationForeignKeyParser())->parse($this->stream)];
     $template = file_get_contents(__DIR__ . '/../../../resources/stubs/models/entry.stub');
     $path = $application->getStoragePath('models/' . studly_case($this->stream->getNamespace()));
     $files->makeDirectory($path, 0777, true, true);
     $file = $path . '/' . studly_case($this->stream->getNamespace()) . studly_case($this->stream->getSlug()) . 'EntryModel.php';
     $files->makeDirectory(dirname($file), 0777, true, true);
     $files->delete($file);
     $files->put($file, $parser->parse($template, $data));
 }
 /**
  * Handle the command.
  *
  * @param Filesystem  $filesystem
  * @param Application $application
  * @return string
  */
 public function handle(Filesystem $filesystem, Application $application)
 {
     $shared = $this->command->option('shared') ? 'shared' : $application->getReference();
     $path = base_path("addons/{$shared}/{$this->vendor}/{$this->slug}-{$this->type}");
     $config = "{$path}/resources/config";
     $views = "{$path}/resources/views";
     $filesystem->makeDirectory($path, 0755, true, true);
     $filesystem->makeDirectory($views, 0755, true, true);
     $filesystem->makeDirectory($config, 0755, true, true);
     return $path;
 }
 /**
  * Handle the command.
  *
  * @param SetupApplication $command
  */
 public function handle(SetupApplication $command)
 {
     $reference = array_get($command->getParameters(), 'application_reference');
     /**
      * Set the reference manually since we
      * can not locate it quite yet.
      */
     $this->application->setReference($reference);
     // Setup the application.
     $this->application->setup();
 }
 /**
  * Handle the command.
  *
  * @param Filesystem  $filesystem
  * @param Application $application
  * @return string
  */
 public function handle(Filesystem $filesystem, Application $application)
 {
     $reference = $this->command->option('shared') ? 'shared' : $application->getReference();
     $path = base_path("addons/{$reference}/{$this->vendor}/{$this->slug}-{$this->type}");
     $modulePath = __DIR__ . '/../../../resources/assets/module';
     $data = $this->getTemplateData();
     /* Make module's folder */
     $filesystem->makeDirectory($path, 0755, true, true);
     /* Copy module template files */
     $filesystem->parseDirectory($modulePath . "/template", $path . '/', $data);
     return $path;
 }
 /**
  * Handle the command.
  *
  * @param Application $application
  */
 public function handle(Application $application)
 {
     if (!is_file($file = $application->getResourcesPath('.env'))) {
         return;
     }
     foreach (file($file, FILE_IGNORE_NEW_LINES) as $line) {
         // Check for # comments.
         if (!starts_with($line, '#')) {
             putenv($line);
         }
     }
 }
 /**
  * Handle the command.
  *
  * @param Application $application
  */
 public function handle(Application $application, Filesystem $files)
 {
     if (!class_exists('TeamTNT\\TNTSearch\\TNTSearch')) {
         return;
     }
     $model = $this->stream->getEntryModel();
     $index = $application->getStoragePath('search/' . $model->searchableAs() . '.index');
     if (!file_exists($index)) {
         return;
     }
     $files->delete($index);
 }
 /**
  * Handle the command.
  *
  * @param  Filesystem  $filesystem
  * @param  Application $application
  * @return string
  */
 public function handle(Filesystem $filesystem, Application $application)
 {
     $destination = $application->getResourcesPath('.env');
     if (!is_dir(dirname($destination))) {
         $filesystem->makeDirectory(dirname($destination), 0777, true, true);
     }
     if (is_file($destination) && !$this->command->option('force')) {
         return $this->command->error("{$destination} already exists.");
     }
     $filesystem->put($destination, '#EXAMPLE=foo');
     $this->command->info("Published {$destination}");
 }
 /**
  * Handle the command.
  *
  * @param  Filesystem  $filesystem
  * @param  Application $application
  * @return string
  */
 public function handle(Filesystem $filesystem, Application $application)
 {
     $destination = $application->getResourcesPath('routes.php');
     if (!is_dir(dirname($destination))) {
         $filesystem->makeDirectory(dirname($destination), 0777, true, true);
     }
     if (is_file($destination) && !$this->command->option('force')) {
         return $this->command->error("{$destination} already exists.");
     }
     $content = "<?php\n\n// Route::get('/', function () {\n//     return view('welcome');\n// });\n";
     $filesystem->put($destination, $content);
     $this->command->info("Published {$destination}");
 }
 /**
  * Handle the command.
  *
  * @param Filesystem  $files
  * @param Application $application
  * @return string
  */
 public function handle(Filesystem $files, Application $application)
 {
     $path = $application->getStoragePath('models/' . studly_case($this->stream->getNamespace()));
     $model = $path . '/' . studly_case($this->stream->getNamespace()) . studly_case($this->stream->getSlug()) . 'EntryModel.php';
     if ($files->exists($model)) {
         $files->delete($model);
     }
     if (!$this->stream->isTranslatable()) {
         return;
     }
     $model = $path . '/' . studly_case($this->stream->getNamespace()) . studly_case($this->stream->getSlug()) . 'EntryTranslationsModel.php';
     if ($files->exists($model)) {
         $files->delete($model);
     }
 }
 /**
  * Return the output path.
  *
  * @param $collection
  * @return string
  */
 public function outputPath($collection)
 {
     /**
      * If the path is already public
      * then just use it as it is.
      */
     if (str_contains($collection, public_path())) {
         return str_replace(public_path(), '', $collection);
     }
     /**
      * Get the real path relative to our installation.
      */
     $path = str_replace(base_path(), '', $this->realPath($collection));
     /**
      * Build out path parts.
      */
     $directory = ltrim(dirname($path), '/\\') . '/';
     $application = $this->application->getReference();
     $filename = basename($path, $this->extension($path)) . $this->hint($path);
     if (starts_with($directory, 'vendor/')) {
         $directory = substr($directory, 7);
     }
     if (starts_with($directory, './')) {
         $directory = in_array($this->request->segment(1), ['admin', 'installer']) ? 'admin/' : 'public/';
     }
     return "/app/{$application}/assets/{$directory}{$filename}";
 }
 /**
  * Return all application addon paths in a given folder.
  *
  * @return bool
  */
 public function application()
 {
     $path = base_path('addons/' . $this->application->getReference());
     if (!is_dir($path)) {
         return false;
     }
     return $this->vendorAddons(glob("{$path}/*", GLOB_ONLYDIR));
 }
Exemple #26
0
 /**
  * Load system overrides.
  *
  * @param  array $lines
  * @param        $locale
  * @param        $group
  * @param        $namespace
  * @return array
  */
 protected function loadApplicationOverrides(array $lines, $locale, $group, $namespace)
 {
     if ($namespace == 'streams') {
         $file = $this->application->getResourcesPath("streams/lang/{$locale}/{$group}.php");
         if ($this->files->exists($file)) {
             $lines = array_replace_recursive($lines, $this->files->getRequire($file));
         }
     }
     if (str_is('*.*.*', $namespace)) {
         list($vendor, $type, $slug) = explode('.', $namespace);
         $file = $this->application->getResourcesPath("addons/{$vendor}/{$slug}-{$type}/lang/{$locale}/{$group}.php");
         if ($this->files->exists($file)) {
             $lines = array_replace_recursive($lines, $this->files->getRequire($file));
         }
     }
     return $lines;
 }
 /**
  * Get the Builder storage path (create if it doesn't exist).
  *
  * @param string path,
  *
  * @return string
  */
 protected function getBuilderPath($path = '')
 {
     $path = $this->application->getStoragePath(_config('config.path') . ($path ? "/{$path}" : ''));
     /* make sure the parent folder is a directory or parent directory is a folder */
     if (!$this->files->isDirectory($parent = dirname($path))) {
         $this->files->makeDirectory($parent, 0777, true);
     }
     return $path;
 }
 /**
  * Handle the command.
  *
  * @param Application $application
  */
 public function handle(Application $application)
 {
     $loader = null;
     foreach (spl_autoload_functions() as $autoloader) {
         if ($autoloader[0] instanceof ClassLoader) {
             $loader = $autoloader[0];
         }
     }
     if (!$loader) {
         throw new \Exception("The ClassLoader could not be found.");
     }
     /*if (file_exists($classmap = $application->getStoragePath('models/classmap.php'))) {
     
                 $loader->addClassMap(include $classmap);
     
                 return;
             }*/
     /* @var ClassLoader $loader */
     $loader->addPsr4('Anomaly\\Streams\\Platform\\Model\\', $application->getStoragePath('models'));
     $loader->register();
 }
 /**
  * Return the output path for an image.
  *
  * @param $path
  * @return string
  */
 public function outputPath(Image $image)
 {
     $path = $image->getImage();
     if ($path instanceof FileInterface) {
         $path = $path->path();
     }
     /**
      * If the path is already public
      * then just use it as it is.
      */
     if (str_contains($path, public_path())) {
         return str_replace(public_path(), '', $path);
     }
     /**
      * If the path is a file or file path then
      * put it in /app/{$application}/files/disk/folder/filename.ext
      */
     if (is_string($path) && str_is('*://*', $path)) {
         $application = $this->application->getReference();
         list($disk, $folder, $filename) = explode('/', str_replace('://', '/', $path));
         if ($rename = $image->getFilename()) {
             $filename = $rename;
             if (strpos($filename, DIRECTORY_SEPARATOR)) {
                 $directory = null;
             }
         }
         return "/app/{$application}/files/{$disk}/{$folder}/{$filename}";
     }
     /**
      * Get the real path relative to our installation.
      */
     $path = str_replace(base_path(), '', $this->realPath($path));
     /**
      * Build out path parts.
      */
     $filename = basename($path);
     $directory = ltrim(dirname($path), '/\\') . '/';
     $application = $this->application->getReference();
     if ($image->getAlterations() || $image->getQuality()) {
         $filename = md5(var_export([$path, $image->getAlterations()], true) . $image->getQuality()) . '.' . $image->getExtension();
     }
     if ($rename = $image->getFilename()) {
         $directory = null;
         $filename = ltrim($rename, '/\\');
     }
     return "/app/{$application}/assets/{$directory}{$filename}";
 }
 /**
  * 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));
 }