This repository has been archived by the owner on Jan 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move request classes from stubbles/input
- Loading branch information
mikey179
committed
Jun 11, 2016
1 parent
23ea530
commit d57bbd4
Showing
8 changed files
with
370 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?php | ||
/** | ||
* This file is part of stubbles. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package stubbles\console | ||
*/ | ||
namespace stubbles\console\input; | ||
use stubbles\input\AbstractRequest; | ||
use stubbles\input\Params; | ||
use stubbles\input\ValueReader; | ||
use stubbles\input\ValueValidator; | ||
/** | ||
* Request implementation for command line. | ||
* | ||
* @api | ||
* @since 2.0.0 | ||
*/ | ||
class BaseConsoleRequest extends AbstractRequest implements ConsoleRequest | ||
{ | ||
/** | ||
* list of environment variables | ||
* | ||
* @type \stubbles\input\Params | ||
*/ | ||
private $env; | ||
|
||
/** | ||
* constructor | ||
* | ||
* @param array $params | ||
* @param array $env | ||
*/ | ||
public function __construct(array $params, array $env) | ||
{ | ||
parent::__construct(new Params($params)); | ||
$this->env = new Params($env); | ||
} | ||
|
||
/** | ||
* creates an instance from raw data | ||
* | ||
* Will use $_SERVER['argv'] for params and $_SERVER for env. | ||
* | ||
* @api | ||
* @return \stubbles\input\console\ConsoleRequest | ||
*/ | ||
public static function fromRawSource() | ||
{ | ||
return new self($_SERVER['argv'], $_SERVER); | ||
} | ||
|
||
/** | ||
* returns the request method | ||
* | ||
* @return string | ||
*/ | ||
public function method() | ||
{ | ||
return 'cli'; | ||
} | ||
|
||
/** | ||
* return a list of all environment names registered in this request | ||
* | ||
* @return string[] | ||
*/ | ||
public function envNames() | ||
{ | ||
return $this->env->names(); | ||
} | ||
|
||
/** | ||
* returns list of errors for environment parameters | ||
* | ||
* @return \stubbles\input\ParamErrors | ||
*/ | ||
public function envErrors() | ||
{ | ||
return $this->env->errors(); | ||
} | ||
|
||
/** | ||
* checks whether a request param is set | ||
* | ||
* @param string $envName | ||
* @return bool | ||
*/ | ||
public function hasEnv($envName) | ||
{ | ||
return $this->env->contain($envName); | ||
} | ||
|
||
/** | ||
* checks whether a request value from parameters is valid or not | ||
* | ||
* @param string $envName name of environment value | ||
* @return \stubbles\input\ValueValidator | ||
*/ | ||
public function validateEnv($envName) | ||
{ | ||
return new ValueValidator($this->env->value($envName)); | ||
} | ||
|
||
/** | ||
* returns request value from params for validation | ||
* | ||
* @param string $envName name of environment value | ||
* @return \stubbles\input\ValueReader | ||
*/ | ||
public function readEnv($envName) | ||
{ | ||
return new ValueReader( | ||
$this->env->errors(), | ||
$this->env->get($envName) | ||
); | ||
} | ||
} |
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,57 @@ | ||
<?php | ||
/** | ||
* This file is part of stubbles. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package stubbles\console | ||
*/ | ||
namespace stubbles\console\input; | ||
use stubbles\input\Request; | ||
/** | ||
* Interface for command line requests. | ||
* | ||
* @api | ||
* @since 2.0.0 | ||
*/ | ||
interface ConsoleRequest extends Request | ||
{ | ||
/** | ||
* return a list of all environment names registered in this request | ||
* | ||
* @return string[] | ||
*/ | ||
public function envNames(); | ||
|
||
/** | ||
* returns list of errors for environment parameters | ||
* | ||
* @return \stubbles\input\errors\ParamErrors | ||
*/ | ||
public function envErrors(); | ||
|
||
/** | ||
* checks whether a request param is set | ||
* | ||
* @param string $envName | ||
* @return bool | ||
*/ | ||
public function hasEnv($envName); | ||
|
||
/** | ||
* checks whether a request value from parameters is valid or not | ||
* | ||
* @param string $envName name of environment value | ||
* @return \stubbles\input\ValueValidator | ||
*/ | ||
public function validateEnv($envName); | ||
|
||
/** | ||
* returns request value from params for validation | ||
* | ||
* @param string $envName name of environment value | ||
* @return \stubbles\input\ValueReader | ||
*/ | ||
public function readEnv($envName); | ||
} |
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
Oops, something went wrong.