-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow extending parsers and dynamic parsers
- Loading branch information
Showing
17 changed files
with
413 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
.* export-ignore | ||
README.md export-ignore | ||
/test/ export-ignore | ||
/phpunit.xml export-ignore | ||
/README.md export-ignore | ||
/.* export-ignore |
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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
/.settings/ | ||
/vendor/ | ||
/.buildpath | ||
/.project | ||
/.phpunit.result.cache | ||
/composer.lock |
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,20 @@ | ||
<phpunit | ||
bootstrap="./test/bootstrap.php" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
> | ||
<testsuites> | ||
<testsuite name="Tests"> | ||
<directory>./test/tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist processUncoveredFilesFromWhitelist="true"> | ||
<directory suffix=".php">./src</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
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,68 @@ | ||
<?php | ||
|
||
namespace C5TL; | ||
|
||
/** | ||
* A class that provides parsers. | ||
*/ | ||
class ParserFactory | ||
{ | ||
/** | ||
* @var \C5TL\Parser[] | ||
*/ | ||
private $parsers = array(); | ||
|
||
public function __construct() | ||
{ | ||
foreach ($this->getDefaultParsers() as $parser) { | ||
$this->registerParser($parser); | ||
} | ||
} | ||
/** | ||
* * @return \C5TL\Parser[] | ||
*/ | ||
public function getParsers() | ||
{ | ||
return array_values($this->parsers); | ||
} | ||
|
||
/** | ||
* @param string|mixed $handle | ||
* | ||
* @return \C5TL\Parser|null | ||
*/ | ||
public function getParserByHandle($handle) | ||
{ | ||
return is_string($handle) && isset($this->parsers[$handle]) ? $this->parsers[$handle] : null; | ||
} | ||
|
||
/** | ||
* @return $this | ||
*/ | ||
public function registerParser(Parser $parser) | ||
{ | ||
$this->parsers[$parser->getParserHandle()] = $parser; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return \C5TL\Parser[] | ||
*/ | ||
private function getDefaultParsers() | ||
{ | ||
$result = array(); | ||
$dir = __DIR__ . '/Parser'; | ||
if (is_dir($dir) && is_readable($dir)) { | ||
$matches = null; | ||
foreach (scandir($dir) as $item) { | ||
if (($item[0] !== '.') && preg_match('/^(.+)\.php$/i', $item, $matches)) { | ||
$fqClassName = '\\' . __NAMESPACE__ . '\\Parser\\' . $matches[1]; | ||
$result[] = new $fqClassName(); | ||
} | ||
} | ||
} | ||
|
||
return $result; | ||
} | ||
} |
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,11 @@ | ||
<?php | ||
|
||
require_once __DIR__ . '/../vendor/autoload.php'; | ||
|
||
if (class_exists('PHPUnit\\Runner\\Version') && version_compare(PHPUnit\Runner\Version::id(), '8') >= 0) { | ||
class_alias('C5TL\\Test\\TestCase8', 'C5TL\\Test\\TestCase'); | ||
} elseif (class_exists('PHPUnit\\Runner\\Version') && version_compare(PHPUnit\Runner\Version::id(), '6') >= 0) { | ||
class_alias('C5TL\\Test\\TestCase6', 'C5TL\\Test\\TestCase'); | ||
} else { | ||
class_alias('C5TL\\Test\\TestCase4', 'C5TL\\Test\\TestCase'); | ||
} |
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,16 @@ | ||
<?php | ||
|
||
namespace C5TL\Test; | ||
|
||
abstract class TestCase4 extends TestCaseBase | ||
{ | ||
final public static function setupBeforeClass() | ||
{ | ||
static::doSetUpBeforeClass(); | ||
} | ||
|
||
final public function setUp() | ||
{ | ||
static::doSetUp(); | ||
} | ||
} |
Oops, something went wrong.