コード例 #1
0
 /**
  * Checks that given project path does not already exist, and
  * finds the app directory in it. Then it calls bake() with that information.
  *
  * @return mixed
  */
 public function main()
 {
     $project = null;
     if (isset($this->args[0])) {
         $project = $this->args[0];
     } else {
         $appContents = array_diff(scandir(APP), ['.', '..']);
         if (empty($appContents)) {
             $suggestedPath = rtrim(APP, DS);
         } else {
             $suggestedPath = APP . 'MyApp';
         }
     }
     while (!$project) {
         $prompt = __d('cake_console', 'What is the path to the project you want to bake?');
         $project = $this->in($prompt, null, $suggestedPath);
     }
     $namespace = basename($project);
     if (!preg_match('/^\\w[\\w\\d_]+$/', $namespace)) {
         $this->err(__d('cake_console', 'Project Name/Namespace needs to start with a letter and can only contain letters, digits and underscore'));
         $this->args = [];
         return $this->execute();
     }
     if ($project && !Folder::isAbsolute($project) && isset($_SERVER['PWD'])) {
         $project = $_SERVER['PWD'] . DS . $project;
     }
     $response = false;
     while (!$response && is_dir($project) === true && file_exists($project . 'Config' . 'boostrap.php')) {
         $prompt = __d('cake_console', '<warning>A project already exists in this location:</warning> %s Overwrite?', $project);
         $response = $this->in($prompt, ['y', 'n'], 'n');
         if (strtolower($response) === 'n') {
             $response = $project = false;
         }
     }
     if ($project === false) {
         $this->out(__d('cake_console', 'Aborting project creation.'));
         return;
     }
     if ($this->bake($project)) {
         $this->out(__d('cake_console', '<success>Project baked successfully!</success>'));
         return $path;
     }
 }
コード例 #2
0
 /**
  * testIsAbsolute method
  *
  * @return void
  */
 public function testIsAbsolute()
 {
     $this->assertFalse(Folder::isAbsolute('path/to/file'));
     $this->assertFalse(Folder::isAbsolute('cake/'));
     $this->assertFalse(Folder::isAbsolute('path\\to\\file'));
     $this->assertFalse(Folder::isAbsolute('0:\\path\\to\\file'));
     $this->assertFalse(Folder::isAbsolute('\\path/to/file'));
     $this->assertFalse(Folder::isAbsolute('\\path\\to\\file'));
     $this->assertTrue(Folder::isAbsolute('/usr/local'));
     $this->assertTrue(Folder::isAbsolute('//path/to/file'));
     $this->assertTrue(Folder::isAbsolute('C:\\cake'));
     $this->assertTrue(Folder::isAbsolute('C:\\path\\to\\file'));
     $this->assertTrue(Folder::isAbsolute('d:\\path\\to\\file'));
     $this->assertTrue(Folder::isAbsolute('\\\\vmware-host\\Shared Folders\\file'));
 }