/** * Return the entry translation model attribute. * * @param StreamInterface $stream * @return null|string */ public function parse(StreamInterface $stream) { if (!$stream->isTranslatable()) { return null; } $namespace = studly_case($stream->getNamespace()); $class = studly_case("{$stream->getNamespace()}_{$stream->getSlug()}") . 'EntryTranslationsModel'; return 'protected $translationModel = \'Anomaly\\Streams\\Platform\\Model\\' . $namespace . '\\' . $class . '\';'; }
/** * Handle the command. * * @param AddonCollection $addons * @param Repository $repository */ public function handle(AddonCollection $addons, Repository $repository) { $slug = $this->stream->getSlug(); $namespace = $this->stream->getNamespace(); foreach ($addons->withConfig("streams.{$namespace}.{$slug}") as $config) { $this->stream->mergeConfig($config); } $this->stream->mergeConfig($repository->get("streams::streams.{$namespace}.{$slug}", [])); }
/** * 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 $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); } }
/** * Set the stream namespace. * * @param StreamInterface $stream */ public function setStreamAttribute(StreamInterface $stream) { $this->attributes['namespace'] = $stream->getNamespace(); }
/** * Return the entry model base namespace. * * @param StreamInterface $stream * @return string */ public function parse(StreamInterface $stream) { return studly_case($stream->getNamespace()); }
/** * Get the compiled entry model path for a stream. * * @param StreamInterface $stream * @return string */ protected function getFilePath(StreamInterface $stream) { $path = $this->application->getStoragePath('models/' . studly_case($stream->getNamespace())); $path .= '/' . studly_case($stream->getNamespace()) . studly_case($stream->getSlug()); return $path . 'EntryTranslationsModel.php'; }
/** * Get the destination path the compiled entry model. * * @param StreamInterface $stream * @return string */ protected function getFilePath(StreamInterface $stream) { $path = $this->application->getStoragePath('models/' . studly_case($stream->getNamespace())); $this->files->makeDirectory($path, 0777, true, true); return $path . '/' . studly_case($stream->getNamespace()) . studly_case($stream->getSlug()) . 'EntryModel.php'; }
/** * Return the entry model class. * * @param StreamInterface $stream * @return string */ public function parse(StreamInterface $stream) { return studly_case("{$stream->getNamespace()}_{$stream->getSlug()}") . 'EntryModel'; }