-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Schema validation and error detail settings by get params #150
Changes from all commits
73fe945
03aa814
3c7a25f
d6d78bf
3ac7645
2733bd5
fe6f74f
e567c17
003fdc0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tomaj\NetteApi\Output\Configurator; | ||
|
||
use Nette\Application\Request; | ||
|
||
interface ConfiguratorInterface | ||
{ | ||
public function validateSchema(?Request $request = null): bool; | ||
|
||
public function showErrorDetail(?Request $request = null): bool; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tomaj\NetteApi\Output\Configurator; | ||
|
||
use Nette\Application\Request; | ||
use Tracy\Debugger; | ||
|
||
class DebuggerConfigurator implements ConfiguratorInterface | ||
{ | ||
public function validateSchema(?Request $request = null): bool | ||
{ | ||
return !Debugger::$productionMode; | ||
} | ||
|
||
public function showErrorDetail(?Request $request = null): bool | ||
{ | ||
return !Debugger::$productionMode; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tomaj\NetteApi\Output\Configurator; | ||
|
||
use Nette\Application\Request; | ||
|
||
class EnvConfigurator implements ConfiguratorInterface | ||
{ | ||
private $envVariable = 'APP_ENV'; | ||
private $productionValue = 'production'; | ||
|
||
/** | ||
* @param string $envVariable Which environment variable to check for production value | ||
* @param string $productionValue Value that indicates production environment eg. 'production' or 'prod'... | ||
*/ | ||
public function __construct(string $envVariable = 'APP_ENV', string $productionValue = 'production') | ||
{ | ||
$this->envVariable = $envVariable; | ||
$this->productionValue = $productionValue; | ||
} | ||
|
||
public function validateSchema(?Request $request = null): bool | ||
{ | ||
$appEnv = getenv($this->envVariable); | ||
if ($appEnv === $this->productionValue) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
public function showErrorDetail(?Request $request = null): bool | ||
{ | ||
$appEnv = getenv($this->envVariable); | ||
if ($appEnv === $this->productionValue) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tomaj\NetteApi\Output\Configurator; | ||
|
||
use Nette\Application\Request; | ||
|
||
class QueryConfigurator implements ConfiguratorInterface | ||
{ | ||
private $noSchemaValidateParam = 'no_schema_validate'; | ||
private $errorDetailParam = 'error_detail'; | ||
|
||
/** | ||
* @param string $noSchemaValidateParam Name of get parameter to disable schema validation | ||
* @param string $errorDetailParam Name of get parameter to show additional info in error response | ||
*/ | ||
public function __construct(string $noSchemaValidateParam = 'no_schema_validate', string $errorDetailParam = 'error_detail') | ||
{ | ||
$this->noSchemaValidateParam = $noSchemaValidateParam; | ||
$this->errorDetailParam = $errorDetailParam; | ||
} | ||
|
||
public function validateSchema(?Request $request = null): bool | ||
{ | ||
if ($request === null) { | ||
return false; | ||
} | ||
$getParams = $request->getParameters(); | ||
return !isset($getParams[$this->noSchemaValidateParam]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. takze ?no_schema_validate=1 bude to iste ako ? no_schema_validate=0 hej? je to tak chcene? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Skor som to chcel tak ze ?no_schema_validate&.... tiez vypne. Ale hej tympadom aj 0. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok sak ked si to tak chcel tak bude :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. az teraz som si uvedomil ze to chceme asi naopak skor - defaultne vypnute a s debugom zapnut - rovnako ako je to pri tom DebuggerConfiguratore |
||
} | ||
|
||
public function showErrorDetail(?Request $request = null): bool | ||
{ | ||
if ($request === null) { | ||
return false; | ||
} | ||
$getParams = $request->getParameters(); | ||
return isset($getParams[$this->errorDetailParam]); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ten request je v interface-y len kvoli tomu QueryConfiguratoru? nebolo by lepsie dat Http\Request do konstruktoru QueryConfiguratoru a ostatne implementacie nechat bez parametrov?