public function execute(InputInterface $input, OutputInterface $output) { $ioc = IoC::getInstance(); $this->input = $input; $this->output = $ioc->make(StyleInterface::class, ['input' => $input, 'output' => $output]); return $this->runCommand(); }
protected function _before() { parent::_before(); $ioc = IoC::getInstance(); $ioc->registerServiceProviders([FilesystemServiceProvider::class, ConfigServiceProvider::class, CacheServiceProvider::class]); CacheHelper::setCacheDirectory($this->outputPath()); }
/** * Configure the cache * * @param Repository $config * @param string $cachePath */ protected function configureCache(Repository $config, $cachePath) { // Set the IoC's configuration instance $ioc = IoC::getInstance(); $ioc->container()['config'] = $config; // Set the cache directory CacheHelper::setCacheDirectory($cachePath); }
/** * Returns a cache repository instance * * @return Repository */ public static function make() { if (!isset(self::$cache)) { $ioc = IoC::getInstance(); $repository = $ioc->make(Repository::class); self::$cache = $repository; } return self::$cache; }
/** * Resolve a handler * * @param string $alias * @param array $parameters [optional] * * @return \Aedart\Scaffold\Contracts\Handlers\Handler * @see IoC::resolveHandler() * */ protected function resolveHandler($alias, array $parameters = []) { // Resolve from IoC $ioc = IoC::getInstance(); $handler = $ioc->resolveHandler($alias, $this->config, $parameters); // Output some information about what handler is being // applied for something $this->outputAppliedHandler($handler); // Finally, return the handler return $handler; }
/** * Execute the command * * @return int|null */ public function runCommand() { // Configure the cache $this->configureCache(new Repository(), $this->input->getOption('cache')); $this->output->title('Building index'); /** @var IndexBuilder $builder */ $builder = IoC::getInstance()->make(IndexBuilder::class, ['output' => $this->output]); $builder->setDirectory($this->input->getOption('output')); $builder->build($this->input->getOption('directories'), $this->input->getOption('force'), $this->input->getOption('expire')); $this->output->success('Indexing completed'); return 0; }
/** * Returns a new populated instance of a CLI Script * * @param string|array $data * * @return CliScript */ protected function makeCliScript($data) { // Execute closure, if given if ($data instanceof Closure) { return call_user_func($data, $this->config->all()); } // Convert to array if string given if (is_string($data)) { $data = ['script' => $data]; } // Lastly, just attempt to make CLI Script instance return IoC::getInstance()->make(CliScript::class, $data); }
public function populate(array $data = []) { $ioc = IoC::getInstance(); foreach ($data as $id => $property) { if (is_string($id) && $property instanceof Property) { $property->setId($id); $this->put($id, $property); continue; } if (is_string($id) && is_array($property)) { $property['id'] = $id; $this->put($id, $ioc->make(Property::class, $property)); continue; } throw new InvalidArgumentException(sprintf('Cannot populate Template Properties Collection with ["%s" => %s]', var_export($id, true), var_export($property, true))); } }
/** * Override the output style to be used inside commands, * and set it's question helper's input stream * * @param array $inputValues [optional] */ public function registerExtendedStyle(array $inputValues = []) { $ioc = IoC::getInstance()->container(); // NB: Has to be singleton or stream might get screwed! $ioc->singleton(StyleInterface::class, function ($app, array $data = []) use($inputValues) { if (!array_key_exists('input', $data) || !array_key_exists('output', $data)) { $target = StyleInterface::class; $msg = "Target {$target} cannot be build. Missing arguments; e.g. ['input' => (InputInterface), 'output' => (OutputInterface)]"; throw new BindingResolutionException($msg); } $style = new ExtendedStyle($data['input'], $data['output']); // Set the input stream on the question helper if (!empty($inputValues)) { $style->getQuestionHelper()->setInputStream($this->writeInput($inputValues)); } return $style; }); }
/** * Parse the given files paths and return a collection * * @param array $files [optional] * * @return Files */ protected function parseFiles(array $files = []) { $ioc = IoC::getInstance(); return $ioc->make(Files::class, $files); }
/** * @test * * @covers ::__wakeup * * @expectedException \Aedart\Scaffold\Exceptions\ForbiddenException */ public function failsWhenWakeupMethodIsInvoked() { $ioc = IoC::getInstance(); $ioc->__wakeup(); }
/** * Boot the IoC */ protected function bootIoC() { IoC::boot(); }
/** * Returns a populated index * * @return Index */ public function getIndex() { /** @var IndexBuilder $builder */ $builder = IoC::getInstance()->make(IndexBuilder::class, ['output' => $this->output]); $builder->setDirectory($this->input->getOption('index-output')); return $builder->load(); }
/** * Parse the given properties list and return a collection * * @param array $properties * * @return TemplateProperties */ public function parsePropertiesCollection(array $properties = []) { $ioc = IoC::getInstance(); return $ioc->make(TemplateProperties::class, $properties); }
/** * Destroy the IoC * * This might be needed in some situations where * tests are expected to behave in certain ways, * whenever an IoC has not registered specific * providers or able to resolve instances... */ public function destroyIoC() { $ioc = IoC::getInstance(); $ioc->destroy(); }
/** * Returns a new index instance * * @param array $locations [optional] * * @return Index */ public function makeIndex(array $locations = []) { return IoC::getInstance()->make(Index::class, $locations); }
/** * Returns a new Scaffold Location object * * @param array $data [optional] * * @return ScaffoldLocation */ public function makeLocation(array $data = []) { return IoC::getInstance()->make(ScaffoldLocation::class, $data); }
/** * Parse the given directories paths and return a collection * * @param array $directories [optional] * * @return Directories */ protected function parseDirectories(array $directories = []) { $ioc = IoC::getInstance(); return $ioc->make(Directories::class, $this->transformIntoPaths($directories)); }
/** * Creates the destination directory, if it does not * already exist * * @param string $destination */ protected function prepareDestinationPath($destination) { // Before a file is generated, we need to make sure // that it's destination directory exists. If not, // then we need to make sure that it is created or // the end-user will get frustrated that this handler // doesn't take care of it automatically. However, skip // if already exists - no need to process this via the // directory handler if ($this->getFile()->exists($destination)) { return; } // We could do simply use the file system (see getFile()), // to check and create the directory. However, in case // that the end-user specified a different handler for // making directories, which follows a different set of // rules, e.g. the access mode, then it would be nice // if this handler could re-use that and avoid dual // implementation. // Remove the "output path" from the destination, before // passing it further to the directories handler, which // automatically ensures to apply the output path! $destination = str_replace($this->getOutputPath(), '', $destination); // Configure the directory handler - this needs to be // done here, because the file system, logger and paths // might change per iteration $this->configureDirectoryHandler(); /** @var Directories $collection */ $collection = IoC::getInstance()->make(Directories::class, [$destination]); // Process the destination directory $this->directoryHandler->processDirectories($collection); }