Beispiel #1
0
 /**
  * Controller generator.
  *
  * @param string $mode Framework mode name.
  * @param string $name Controller name.
  *
  * @return void
  */
 public static function controller($mode, $name)
 {
     $action_names = array_slice(func_get_args(), 2);
     $result = self::parseTemplate('controller', array('mode' => $mode, 'controller' => $name, 'actions' => $action_names));
     Helpers\File::putContents($mode . DIRECTORY_SEPARATOR . 'controllers' . DIRECTORY_SEPARATOR . strtolower($name) . '.php', $result);
     /* Generate views */
     try {
         Helpers\Directory::create($mode . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . strtolower($name));
     } catch (\Exception $e) {
         /* @todo Explain why we are not handling exception. */
     }
     foreach ($action_names as $action) {
         $path = $mode . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . strtolower($name) . DIRECTORY_SEPARATOR . $action . '.html';
         $view = self::parseTemplate('view', array('controller' => $name, 'action' => $action, 'path' => $path));
         Helpers\File::putContents($path, $view);
     }
 }
Beispiel #2
0
 /**
  * Uploads a file.
  *
  * @param array  $file      Value from $_FILES.
  * @param string $directory Full path to storage.
  * @param string $saveName  Filename in storage.
  *
  * @throws \DomainException If upload file is not valid or cannot be moved.
  * @uses self::filterFilename To filter the filename used in storage.
  * @uses Directory::create()  To create a directory for the file, if necessary.
  *
  * @return boolean If the file was successfully uploaded.
  */
 public static function upload(array $file, $directory, $saveName = null)
 {
     if (is_null($saveName)) {
         $saveName = self::filterFilename($file['name']);
     }
     if (!is_dir($directory)) {
         Directory::create($directory);
     }
     $destination = rtrim($directory, '\\/') . DIRECTORY_SEPARATOR . $saveName;
     $uploaded = move_uploaded_file($file['tmp_name'], $destination);
     return $uploaded;
 }
Beispiel #3
0
 /**
  * @covers Core\Helpers\Directory::delete
  */
 public function testDeletingDirectory()
 {
     $this->assertTrue(Directory::delete(dirname($this->path)));
 }