This repository has been archived by the owner on Mar 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from pinepain/new-features
Bug fixes and new features
- Loading branch information
Showing
36 changed files
with
1,950 additions
and
260 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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the pinepain/js-sandbox PHP library. | ||
* | ||
* Copyright (c) 2016-2017 Bogdan Padalko <[email protected]> | ||
* | ||
* Licensed under the MIT license: http://opensource.org/licenses/MIT | ||
* | ||
* For the full copyright and license information, please view the | ||
* LICENSE file that was distributed with this source or visit | ||
* http://opensource.org/licenses/MIT | ||
*/ | ||
|
||
|
||
namespace Pinepain\JsSandbox\Decorators; | ||
|
||
|
||
class DecoratorSpec implements DecoratorSpecInterface | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $name; | ||
/** | ||
* @var array | ||
*/ | ||
private $arguments; | ||
|
||
/** | ||
* @param string $name | ||
* @param array $arguments | ||
*/ | ||
public function __construct(string $name, array $arguments = []) | ||
{ | ||
$this->name = $name; | ||
$this->arguments = $arguments; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getArguments(): array | ||
{ | ||
return $this->arguments; | ||
} | ||
} |
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,110 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the pinepain/js-sandbox PHP library. | ||
* | ||
* Copyright (c) 2016-2017 Bogdan Padalko <[email protected]> | ||
* | ||
* Licensed under the MIT license: http://opensource.org/licenses/MIT | ||
* | ||
* For the full copyright and license information, please view the | ||
* LICENSE file that was distributed with this source or visit | ||
* http://opensource.org/licenses/MIT | ||
*/ | ||
|
||
|
||
namespace Pinepain\JsSandbox\Decorators; | ||
|
||
|
||
use Pinepain\JsSandbox\Specs\Builder\ArgumentValueBuilderInterface; | ||
use Pinepain\JsSandbox\Specs\Builder\Exceptions\ArgumentValueBuilderException; | ||
|
||
|
||
class DecoratorSpecBuilder implements DecoratorSpecBuilderInterface | ||
{ | ||
private $regexp = '/ | ||
^ | ||
\@(?<name>[a-z_]+(?:[\w-]*\w)?) | ||
\s* | ||
(?: | ||
\( | ||
\s* | ||
(?<params> | ||
( | ||
(?:[^\'\"\(\)\,\s]+) # literal | ||
| | ||
(?:[+-]?[0-9]+\.?[0-9]*) # numbers (no exponential notation) | ||
| | ||
(?:\'[^\']*\') # single-quoted string | ||
| | ||
(?:\"[^\"]*\") # double-quoted string | ||
| | ||
(?:\[\s*\]) # empty array | ||
| | ||
(?:\{\s*\}) # empty object | ||
| | ||
true | false | null | ||
)(?:\s*\,\s*((?-3))*)* | ||
)? | ||
\s* | ||
\) | ||
)? | ||
\s* | ||
$ | ||
/xi'; | ||
/** | ||
* @var ArgumentValueBuilderInterface | ||
*/ | ||
private $argument; | ||
|
||
/** | ||
* @param ArgumentValueBuilderInterface $argument | ||
*/ | ||
public function __construct(ArgumentValueBuilderInterface $argument) | ||
{ | ||
$this->argument = $argument; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function build(string $definition): DecoratorSpecInterface | ||
{ | ||
$definition = trim($definition); | ||
|
||
if (!$definition) { | ||
throw new DecoratorSpecBuilderException('Definition must be non-empty string'); | ||
} | ||
|
||
try { | ||
if (preg_match($this->regexp, $definition, $matches)) { | ||
|
||
$params = array_slice($matches, 5); | ||
$decorator = $this->buildDecorator($matches['name'], $params); | ||
|
||
return $decorator; | ||
} | ||
} catch (ArgumentValueBuilderException $e) { | ||
// We don't care about what specific issue we hit inside, | ||
// for API user it means that the definition is invalid | ||
} | ||
|
||
throw new DecoratorSpecBuilderException("Unable to parse definition: '{$definition}'"); | ||
} | ||
|
||
/** | ||
* @param string $name | ||
* @param array $raw_args | ||
* | ||
* @return DecoratorSpecInterface | ||
*/ | ||
protected function buildDecorator(string $name, array $raw_args): DecoratorSpecInterface | ||
{ | ||
$arguments = []; | ||
foreach ($raw_args as $raw_arg) { | ||
$arguments[] = $this->argument->build($raw_arg, true); | ||
} | ||
|
||
return new DecoratorSpec($name, $arguments); | ||
} | ||
} |
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,24 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the pinepain/js-sandbox PHP library. | ||
* | ||
* Copyright (c) 2016-2017 Bogdan Padalko <[email protected]> | ||
* | ||
* Licensed under the MIT license: http://opensource.org/licenses/MIT | ||
* | ||
* For the full copyright and license information, please view the | ||
* LICENSE file that was distributed with this source or visit | ||
* http://opensource.org/licenses/MIT | ||
*/ | ||
|
||
|
||
namespace Pinepain\JsSandbox\Decorators; | ||
|
||
|
||
use Pinepain\JsSandbox\Specs\Builder\Exceptions\SpecBuilderException; | ||
|
||
|
||
class DecoratorSpecBuilderException extends SpecBuilderException | ||
{ | ||
} |
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,28 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the pinepain/js-sandbox PHP library. | ||
* | ||
* Copyright (c) 2016-2017 Bogdan Padalko <[email protected]> | ||
* | ||
* Licensed under the MIT license: http://opensource.org/licenses/MIT | ||
* | ||
* For the full copyright and license information, please view the | ||
* LICENSE file that was distributed with this source or visit | ||
* http://opensource.org/licenses/MIT | ||
*/ | ||
|
||
|
||
namespace Pinepain\JsSandbox\Decorators; | ||
|
||
|
||
interface DecoratorSpecBuilderInterface | ||
{ | ||
/** | ||
* @param string $definition | ||
* | ||
* @return DecoratorSpecInterface | ||
* @throws DecoratorSpecBuilderException | ||
*/ | ||
public function build(string $definition): DecoratorSpecInterface; | ||
} |
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 declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the pinepain/js-sandbox PHP library. | ||
* | ||
* Copyright (c) 2016-2017 Bogdan Padalko <[email protected]> | ||
* | ||
* Licensed under the MIT license: http://opensource.org/licenses/MIT | ||
* | ||
* For the full copyright and license information, please view the | ||
* LICENSE file that was distributed with this source or visit | ||
* http://opensource.org/licenses/MIT | ||
*/ | ||
|
||
namespace Pinepain\JsSandbox\Decorators; | ||
|
||
|
||
interface DecoratorSpecInterface | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
public function getName(): string; | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getArguments(): array; | ||
} |
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,50 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the pinepain/js-sandbox PHP library. | ||
* | ||
* Copyright (c) 2016-2017 Bogdan Padalko <[email protected]> | ||
* | ||
* Licensed under the MIT license: http://opensource.org/licenses/MIT | ||
* | ||
* For the full copyright and license information, please view the | ||
* LICENSE file that was distributed with this source or visit | ||
* http://opensource.org/licenses/MIT | ||
*/ | ||
|
||
|
||
namespace Pinepain\JsSandbox\Decorators; | ||
|
||
|
||
use OutOfBoundsException; | ||
use OverflowException; | ||
use Pinepain\JsSandbox\Decorators\Definitions\DecoratorInterface; | ||
|
||
|
||
class DecoratorsCollection implements DecoratorsCollectionInterface | ||
{ | ||
protected $decorators = []; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function get(string $name): DecoratorInterface | ||
{ | ||
if (!isset($this->decorators[$name])) { | ||
throw new OutOfBoundsException("Decorator '{$name}' not found"); | ||
} | ||
|
||
return $this->decorators[$name]; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function put(string $name, DecoratorInterface $extractor) | ||
{ | ||
if (isset($this->decorators[$name])) { | ||
throw new OverflowException("Decorator with the same name ('{$name}') already exists"); | ||
} | ||
$this->decorators[$name] = $extractor; | ||
} | ||
} |
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,42 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the pinepain/js-sandbox PHP library. | ||
* | ||
* Copyright (c) 2016-2017 Bogdan Padalko <[email protected]> | ||
* | ||
* Licensed under the MIT license: http://opensource.org/licenses/MIT | ||
* | ||
* For the full copyright and license information, please view the | ||
* LICENSE file that was distributed with this source or visit | ||
* http://opensource.org/licenses/MIT | ||
*/ | ||
|
||
|
||
namespace Pinepain\JsSandbox\Decorators; | ||
|
||
|
||
use OutOfBoundsException; | ||
use OverflowException; | ||
use Pinepain\JsSandbox\Decorators\Definitions\DecoratorInterface; | ||
|
||
|
||
interface DecoratorsCollectionInterface | ||
{ | ||
/** | ||
* @param string $name | ||
* | ||
* @return DecoratorInterface | ||
* @throws OutOfBoundsException | ||
*/ | ||
public function get(string $name): DecoratorInterface; | ||
|
||
/** | ||
* @param string $name | ||
* @param DecoratorInterface $extractor | ||
* | ||
* @return mixed | ||
* @throws OverflowException | ||
*/ | ||
public function put(string $name, DecoratorInterface $extractor); | ||
} |
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,25 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the pinepain/js-sandbox PHP library. | ||
* | ||
* Copyright (c) 2016-2017 Bogdan Padalko <[email protected]> | ||
* | ||
* Licensed under the MIT license: http://opensource.org/licenses/MIT | ||
* | ||
* For the full copyright and license information, please view the | ||
* LICENSE file that was distributed with this source or visit | ||
* http://opensource.org/licenses/MIT | ||
*/ | ||
|
||
|
||
namespace Pinepain\JsSandbox\Decorators\Definitions; | ||
|
||
|
||
use Pinepain\JsSandbox\Wrappers\FunctionComponents\Runtime\ExecutionContextInterface; | ||
|
||
|
||
interface DecoratorInterface | ||
{ | ||
public function decorate(callable $callback, ExecutionContextInterface $exec): callable; | ||
} |
Oops, something went wrong.