-
Notifications
You must be signed in to change notification settings - Fork 39
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 #6 from formapro/pvm-class-map
Intr schema, enchance object builder. fix doc.
- Loading branch information
Showing
16 changed files
with
102 additions
and
51 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
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
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
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,33 @@ | ||
<?php | ||
namespace Formapro\Pvm; | ||
|
||
use function Makasim\Values\register_global_hook; | ||
|
||
class ObjectBuilderHook | ||
{ | ||
/** | ||
* @var PvmClassMap | ||
*/ | ||
private $classMap; | ||
|
||
/** | ||
* @param string[] $classMap | ||
*/ | ||
public function __construct(array $classMap = []) | ||
{ | ||
$this->classMap = new PvmClassMap($classMap); | ||
} | ||
|
||
public function register() | ||
{ | ||
register_global_hook('get_object_class', function(array $values) { | ||
if (isset($values['schema'])) { | ||
if (false == array_key_exists($values['schema'], $this->classMap->get())) { | ||
throw new \LogicException(sprintf('An object has class set "%s" but there is no class for it', $values['class'])); | ||
} | ||
|
||
return $this->classMap[$values['schema']]; | ||
} | ||
}); | ||
} | ||
} |
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,28 @@ | ||
<?php | ||
namespace Formapro\Pvm; | ||
|
||
class PvmClassMap | ||
{ | ||
/** | ||
* @var string[] | ||
*/ | ||
private $classMap; | ||
|
||
/** | ||
* @param string[] $classMap | ||
*/ | ||
public function __construct(array $classMap = []) | ||
{ | ||
$this->classMap = array_replace([ | ||
Process::SCHEMA => Process::class, | ||
Node::SCHEMA => Node::class, | ||
Token::SCHEMA => Token::class, | ||
Transition::SCHEMA => Transition::class, | ||
], $classMap); | ||
} | ||
|
||
public function get(): array | ||
{ | ||
return $this->classMap; | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.