setupBaseSprinkleList(); } // Create Symfony Console App $this->app = new Application("UserFrosting Bakery", \UserFrosting\VERSION); // Setup the sprinkles $uf = new UserFrosting(); // Set argument as false, we are using the CLI $uf->setupSprinkles(FALSE); // Get the container $this->ci = $uf->getContainer(); // Add each commands to the Console App $this->loadCommands(); } /** * Run the Symfony Console App */ public function run() { $this->app->run(); } /** * Return the list of available commands for a specific sprinkle */ protected function loadCommands() { // Get base Bakery command $commands = $this->getBakeryCommands(); // Get the sprinkles commands $sprinkles = $this->ci->sprinkleManager->getSprinkleNames(); foreach ($sprinkles as $sprinkle) { $commands = $commands->merge($this->getSprinkleCommands($sprinkle)); } // Add commands to the App $commands->each(function ($command) { $instance = new $command(); $instance->setContainer($this->ci); $this->app->add($instance); }); } /** * Return the list of available commands for a specific sprinkle * Sprinkles commands should be located in `src/Bakery/` */ protected function getSprinkleCommands($sprinkle) { // Find all the migration files $path = $this->commandDirectoryPath($sprinkle); $files = glob($path . "*.php"); $commands = collect($files); // Transform the path into a class names $commands->transform(function ($file) use ($sprinkle, $path) { $className = basename($file, '.php'); $sprinkleName = Str::studly($sprinkle); $className = "\\UserFrosting\\Sprinkle\\" . $sprinkleName . "\\Bakery\\" . $className; return $className; }); return $commands; } /** * Return the list of available commands in system/Bakery/Command/ */ protected function getBakeryCommands() { // Find all the migration files $files = glob(\UserFrosting\APP_DIR . "/system/Bakery/Command/" . "*.php"); $commands = collect($files); // Transform the path into a class names $commands->transform(function ($file) { $className = basename($file, '.php'); $className = "\\UserFrosting\\System\\Bakery\\Command\\" . $className; return $className; }); return $commands; } /** * Returns the path of the Migration directory. * * @access protected * @param mixed $sprinkleName * @return void */ protected function commandDirectoryPath($sprinkleName) { return \UserFrosting\SPRINKLES_DIR . \UserFrosting\DS . $sprinkleName . \UserFrosting\DS . \UserFrosting\SRC_DIR_NAME . "/Bakery/"; } /** * Write the base Sprinkles schema file if it doesn't exist. * * @access protected * @return void */ protected function setupBaseSprinkleList() { $model = \UserFrosting\APP_DIR . '/sprinkles.example.json'; $destination = \UserFrosting\SPRINKLES_SCHEMA_FILE; $sprinklesModelFile = @file_get_contents($model); if ($sprinklesModelFile === FALSE) { $this->io->error("File `$sprinklesModelFile` not found. Please create '$destination' manually and try again."); exit(1); } file_put_contents($destination, $sprinklesModelFile); return $sprinklesModelFile; } }