From 937100e9bb2a2f5ab035e283e01e6d96e569ee51 Mon Sep 17 00:00:00 2001 From: marvin-borner@live.com Date: Sat, 14 Apr 2018 21:01:44 +0200 Subject: Added login things --- login/app/system/Bakery/Bakery.php | 166 +++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100755 login/app/system/Bakery/Bakery.php (limited to 'login/app/system/Bakery/Bakery.php') diff --git a/login/app/system/Bakery/Bakery.php b/login/app/system/Bakery/Bakery.php new file mode 100755 index 0000000..8be8480 --- /dev/null +++ b/login/app/system/Bakery/Bakery.php @@ -0,0 +1,166 @@ +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; + } +} -- cgit v1.2.3