Example #1
0
 public function testDeleteWriteReadFile()
 {
     $path = '/tmp/juriya_test.txt';
     $expected = 'This is a test';
     $this->assertTrue(file_exists($path));
     File::delete($path);
     $this->assertFalse(file_exists($path));
     File::write($path, $expected);
     $this->assertTrue(file_exists($path));
     $this->assertEquals($expected, File::read($path));
 }
Example #2
0
 /**
  * Generate app skeleton on current directory
  *
  * @param  string Namespace
  * @return stream
  */
 public static function generate($namespace = 'App')
 {
     $namespace = ucfirst(strtolower($namespace));
     $isApp = (bool) ($namespace === 'App');
     $currentDirectory = new \DirectoryIterator($_SERVER['PWD']);
     // Initialize by validate current directory
     if ($currentDirectory->isDir() && $currentDirectory->isWritable()) {
         // Create directory structure
         self::out(I18n::translate('command_generate_folders'));
         $appFolder = $currentDirectory->getPath() . DIRECTORY_SEPARATOR . $namespace;
         $controllerFolder = $currentDirectory->getPath() . DIRECTORY_SEPARATOR . $namespace . DIRECTORY_SEPARATOR . 'Controller';
         $testsFolder = $currentDirectory->getPath() . DIRECTORY_SEPARATOR . $namespace . DIRECTORY_SEPARATOR . 'Tests';
         $directories = compact('appFolder', 'controllerFolder', 'testsFolder');
         foreach ($directories as $name => $directory) {
             $directory = $isApp ? str_replace($namespace, strtolower($namespace), $directory) : $directory;
             is_dir($directory) or mkdir($directory, 0755, TRUE);
             // Reset paths
             ${$name} = $directory;
         }
         // Create controller and model
         self::out(I18n::translate('command_generate_files'));
         $controllerTemplate = File::read(PATH_SYS . DIRECTORY_SEPARATOR . 'Templates' . DIRECTORY_SEPARATOR . 'Controller.php.tpl');
         $phpunitTemplate = File::read(PATH_SYS . DIRECTORY_SEPARATOR . 'Templates' . DIRECTORY_SEPARATOR . 'phpunit.xml.tpl');
         $bootstrapTemplate = File::read(PATH_SYS . DIRECTORY_SEPARATOR . 'Templates' . DIRECTORY_SEPARATOR . 'bootstrap.php.tpl');
         $testTemplate = File::read(PATH_SYS . DIRECTORY_SEPARATOR . 'Templates' . DIRECTORY_SEPARATOR . 'ControllerTest.php.tpl');
         $routePath = $isApp ? '' : strtolower($namespace) . '.';
         File::write($controllerFolder . DIRECTORY_SEPARATOR . 'HelloController.php', sprintf($controllerTemplate, $namespace, $namespace, $namespace));
         File::write($testsFolder . DIRECTORY_SEPARATOR . 'phpunit.xml', sprintf($phpunitTemplate, $namespace));
         File::write($testsFolder . DIRECTORY_SEPARATOR . 'bootstrap.php', sprintf($bootstrapTemplate, PATH_SYS . DIRECTORY_SEPARATOR . 'Juriya.php'));
         File::write($testsFolder . DIRECTORY_SEPARATOR . 'HelloControllerTest.php', sprintf($testTemplate, $namespace, $namespace, $routePath, $routePath, $routePath));
         // Generate basic YAML configuration files
         self::out(I18n::translate('command_generate_configuration'));
         $routesTemplate = File::read(PATH_SYS . DIRECTORY_SEPARATOR . 'Templates' . DIRECTORY_SEPARATOR . 'routes.yml.tpl');
         $packagesTemplate = File::read(PATH_SYS . DIRECTORY_SEPARATOR . 'Templates' . DIRECTORY_SEPARATOR . 'packages.yml.tpl');
         $modulesTemplate = File::read(PATH_SYS . DIRECTORY_SEPARATOR . 'Templates' . DIRECTORY_SEPARATOR . 'modules.yml.tpl');
         File::write($appFolder . DIRECTORY_SEPARATOR . 'routes.yml', sprintf($routesTemplate, $namespace));
         File::write($appFolder . DIRECTORY_SEPARATOR . 'packages.yml', $packagesTemplate);
         File::write($appFolder . DIRECTORY_SEPARATOR . 'modules.yml', $modulesTemplate);
         if ($isApp) {
             // Generate front socket if the requsted app is Application
             self::out(I18n::translate('command_generate_front_socket'));
             $publicDirectory = $currentDirectory->getPath() . DIRECTORY_SEPARATOR . 'public';
             is_dir($publicDirectory) or mkdir($publicDirectory, 0755, TRUE);
             $indexTemplate = File::read(PATH_SYS . DIRECTORY_SEPARATOR . 'Templates' . DIRECTORY_SEPARATOR . 'index.php.tpl');
             File::write($publicDirectory . DIRECTORY_SEPARATOR . 'index.php', sprintf($indexTemplate, PATH_SYS . DIRECTORY_SEPARATOR . 'Juriya.php'));
         }
         self::out(Utility::getColoredString(I18n::translate('command_generate_done'), 'black', 'green'));
     } else {
         self::out(I18n::translate('file_not_writable', $currentDirectory->getPath()));
         self::out(Utility::getColoredString(I18n::translate('command_generate_fail'), 'black', 'red'));
     }
 }