Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make phalcon self-healing when executing an external false command wh…
…en .phalcon folder is missing
- Loading branch information
1 parent
61e8163
commit c9a0257
Showing
3 changed files
with
76 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
/* | ||
+------------------------------------------------------------------------+ | ||
| Phalcon Developer Tools | | ||
+------------------------------------------------------------------------+ | ||
| Copyright (c) 2011-2017 Phalcon Team (https://www.phalconphp.com) | | ||
+------------------------------------------------------------------------+ | ||
| This source file is subject to the New BSD License that is bundled | | ||
| with this package in the file LICENSE.txt. | | ||
| | | ||
| If you did not receive a copy of the license and are unable to | | ||
| obtain it through the world-wide-web, please send an email | | ||
| to license@phalconphp.com so we can send you a copy immediately. | | ||
+------------------------------------------------------------------------+ | ||
| Authors: Paul Scarrone <paul@savvysoftworks.com> | | ||
+------------------------------------------------------------------------+ | ||
*/ | ||
|
||
namespace Phalcon\Commands; | ||
|
||
use Phalcon\Exception; | ||
use Phalcon\Generator\Stub; | ||
use Phalcon\Script\Color; | ||
|
||
/** | ||
* .phalcon is missing Exception | ||
* This is thrown when a CLI command is run without a .phalcon file | ||
* In the CWD | ||
* @package Phalcon\Commands | ||
*/ | ||
class DotPhalconMissingException extends CommandsException | ||
{ | ||
const DEFAULT_MESSAGE = "This command must be run inside a Phalcon project with a .phalcon directory."; | ||
const RESOLUTION_PROMPT = "Shall I create the .phalcon directory now? (y/n)"; | ||
|
||
public function __construct (string $message = self::DEFAULT_MESSAGE , int $code = 0) | ||
{ | ||
$this->message = $message; | ||
$this->code = $code; | ||
} | ||
|
||
public function scanPathMessage() | ||
{ | ||
return "One was not found at " . getcwd(); | ||
} | ||
|
||
public function promptResolution() { | ||
fwrite(STDOUT, Color::info(self::RESOLUTION_PROMPT)); | ||
$handle = fopen ("php://stdin","r"); | ||
$line = fgets($handle); | ||
if(trim($line) != 'y'){ | ||
echo "ABORTING!\n"; | ||
return false; | ||
} | ||
fclose($handle); | ||
echo "\n"; | ||
echo "Retrying command...\n"; | ||
$this->resolve(); | ||
return true; | ||
} | ||
|
||
public function resolve() { | ||
return mkdir(getcwd() . "/.phalcon"); | ||
} | ||
} |