Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Yaml conf file support Increase speed execution
- Loading branch information
1 parent
ba61e3b
commit fef1511
Showing
27 changed files
with
613 additions
and
39 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
32 changes: 32 additions & 0 deletions
32
src/Fakerino/Configuration/ConfigurationFile/YamlConfigurationFile.php
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,32 @@ | ||
<?php | ||
/** | ||
* This file is part of the Fakerino package. | ||
* | ||
* (c) Nicola Pietroluongo <niklongstone@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Fakerino\Configuration\ConfigurationFile; | ||
|
||
use Fakerino\Configuration\AbstractConfigurationFile; | ||
use Symfony\Component\Yaml\Parser; | ||
|
||
/** | ||
* Class YamlConfigurationFile | ||
* | ||
* @author Nicola Pietroluongo <nik.longstone@gmail.com> | ||
*/ | ||
class YamlConfigurationFile extends AbstractConfigurationFile | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function toArray() | ||
{ | ||
$yaml = new Parser(); | ||
|
||
return $yaml->parse(file_get_contents($this->getConfFilePath(), true)); | ||
} | ||
} |
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,62 @@ | ||
<?php | ||
/** | ||
* This file is part of the Fakerino package. | ||
* | ||
* (c) Nicola Pietroluongo <nik.longstone@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Fakerino\Core\FakeHandler; | ||
|
||
use Fakerino\Core\RegEx\RegExGeneratorInterface; | ||
|
||
/** | ||
* Class RegExFakerClass, | ||
* processes the request of a regular expression. | ||
* | ||
* @author Nicola Pietroluongo <nik.longstone@gmail.com> | ||
*/ | ||
class RegExFakerClass extends Handler | ||
{ | ||
private $regexGenerator; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param RegExGeneratorInterface $regexGenerator | ||
*/ | ||
public function __construct(RegExGeneratorInterface $regexGenerator) | ||
{ | ||
$this->regexGenerator = $regexGenerator; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function process($data) | ||
{ | ||
$elementName = $data->getName(); | ||
$options = $data->getOptions(); | ||
$expr = null; | ||
if ($elementName[0] == '/') { | ||
$expr = $elementName; | ||
} | ||
if ($options !== null && is_string($options)) { | ||
if ($options[0] == '/') { | ||
$expr = $options; | ||
} | ||
} | ||
if ($expr !== null) { | ||
$options = array( | ||
'regexgenerator' => $this->regexGenerator, | ||
'expression' => $expr | ||
); | ||
|
||
return $this->getOutput('Fakerino\\FakeData\\Core\\RegExFake', $options); | ||
} | ||
|
||
return; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/Fakerino/Core/RegEx/Exception/InvalidRegexException.php
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,30 @@ | ||
<?php | ||
/** | ||
* This file is part of the Fakerino package. | ||
* | ||
* (c) Nicola Pietroluongo <nik.longstone@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Fakerino\Core\RegEx\Exception; | ||
|
||
/** | ||
* Class InvalidRegexException, | ||
* appears when the format of the regular expression is not valid. | ||
* | ||
* @author Nicola Pietroluongo <nik.longstone@gmail.com> | ||
*/ | ||
class InvalidRegexException extends \RuntimeException | ||
{ | ||
/** | ||
* Construct | ||
* | ||
* @param string $expr | ||
*/ | ||
public function __construct($expr) | ||
{ | ||
parent::__construct(sprintf('The format of the regular expression "%s" is invalid', $expr)); | ||
} | ||
} |
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,29 @@ | ||
<?php | ||
/** | ||
* This file is part of the Fakerino package. | ||
* | ||
* (c) Nicola Pietroluongo <nik.longstone@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Fakerino\Core\RegEx; | ||
|
||
/** | ||
* Interface RegExInterface, | ||
* provides an interface for a regular expression generator. | ||
* | ||
* @package Fakerino\Core\RegEx | ||
*/ | ||
interface RegExGeneratorInterface | ||
{ | ||
/** | ||
* Generates a string from the provided $regex | ||
* | ||
* @param string $regex | ||
* | ||
* @return string | ||
*/ | ||
public function generate($regex); | ||
} |
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,41 @@ | ||
<?php | ||
/** | ||
* This file is part of the Fakerino package. | ||
* | ||
* (c) Nicola Pietroluongo <nik.longstone@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Fakerino\Core\RegEx; | ||
|
||
use Fakerino\Core\RegEx\Exception\InvalidRegexException; | ||
use RegRev\RegRev; | ||
|
||
/** | ||
* Interface RegExGenerator, | ||
* provides an interface for the RegRev regular expression generator. | ||
* | ||
* @package Fakerino\Core\RegEx | ||
*/ | ||
class RegRevGenerator implements RegExGeneratorInterface | ||
{ | ||
/** | ||
* @param string $regex | ||
* | ||
* @return string | ||
* @throws InvalidRegexException | ||
*/ | ||
public function generate($regex) | ||
{ | ||
$expr = substr($regex, 1, -1); | ||
$result = RegRev::generate($expr); | ||
if ($result !== null) { | ||
|
||
return $result; | ||
} else { | ||
throw new InvalidRegexException($expr); | ||
} | ||
} | ||
} |
Oops, something went wrong.