import axiom without dependency on symfony console
Some checks failed
abc-api/abcParser/pipeline/head There was a failure building this commit
Some checks failed
abc-api/abcParser/pipeline/head There was a failure building this commit
This commit is contained in:
13
axiom_src/Atoms/AtomInterface.php
Normal file
13
axiom_src/Atoms/AtomInterface.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Enzyme\Axiom\Atoms;
|
||||
|
||||
interface AtomInterface
|
||||
{
|
||||
/**
|
||||
* Get the underlying value associated with this atom.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getValue();
|
||||
}
|
||||
29
axiom_src/Atoms/IntegerAtom.php
Normal file
29
axiom_src/Atoms/IntegerAtom.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Enzyme\Axiom\Atoms;
|
||||
|
||||
use Enzyme\Axiom\Exceptions\AtomException;
|
||||
|
||||
class IntegerAtom implements AtomInterface
|
||||
{
|
||||
protected $value;
|
||||
|
||||
public function __construct($value)
|
||||
{
|
||||
if ($this->isInvalidOrFloat($value)) {
|
||||
throw new AtomException(get_class($this), $value);
|
||||
}
|
||||
|
||||
$this->value = (int)$value;
|
||||
}
|
||||
|
||||
protected function isInvalidOrFloat($value)
|
||||
{
|
||||
return is_numeric($value) === false || is_float($value) === true;
|
||||
}
|
||||
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
}
|
||||
24
axiom_src/Atoms/StringAtom.php
Normal file
24
axiom_src/Atoms/StringAtom.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Enzyme\Axiom\Atoms;
|
||||
|
||||
use Enzyme\Axiom\Exceptions\AtomException;
|
||||
|
||||
class StringAtom implements AtomInterface
|
||||
{
|
||||
protected $value;
|
||||
|
||||
public function __construct($value)
|
||||
{
|
||||
if (is_string($value) === false) {
|
||||
throw new AtomException(get_class($this), $value);
|
||||
}
|
||||
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
}
|
||||
33
axiom_src/Bags/ArrayBag.php
Normal file
33
axiom_src/Bags/ArrayBag.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Enzyme\Axiom\Bags;
|
||||
|
||||
class ArrayBag implements BagInterface
|
||||
{
|
||||
protected $store;
|
||||
|
||||
public function __construct(array $store)
|
||||
{
|
||||
$this->store = $store;
|
||||
}
|
||||
|
||||
public function get($key)
|
||||
{
|
||||
if ($this->has($key)) {
|
||||
return $this->store[$key];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function has($key)
|
||||
{
|
||||
return isset($this->store[$key])
|
||||
&& array_key_exists($key, $this->store);
|
||||
}
|
||||
|
||||
public function getAll()
|
||||
{
|
||||
return $this->store;
|
||||
}
|
||||
}
|
||||
32
axiom_src/Bags/BagInterface.php
Normal file
32
axiom_src/Bags/BagInterface.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Enzyme\Axiom\Bags;
|
||||
|
||||
interface BagInterface
|
||||
{
|
||||
/**
|
||||
* Get the value associated with the given key. If the key does not
|
||||
* exist, return null instead.
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key);
|
||||
|
||||
/**
|
||||
* Get all the key/value pairs for this bag.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAll();
|
||||
|
||||
/**
|
||||
* Check whether there is a value associated with the given key.
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function has($key);
|
||||
}
|
||||
13
axiom_src/Exceptions/AtomException.php
Normal file
13
axiom_src/Exceptions/AtomException.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Enzyme\Axiom\Exceptions;
|
||||
|
||||
class AtomException extends AxiomException
|
||||
{
|
||||
public function __construct($class, $value)
|
||||
{
|
||||
parent::__construct(
|
||||
"The atom [{$class}] could not process the value [{$value}]."
|
||||
);
|
||||
}
|
||||
}
|
||||
10
axiom_src/Exceptions/AxiomException.php
Normal file
10
axiom_src/Exceptions/AxiomException.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Enzyme\Axiom\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class AxiomException extends Exception
|
||||
{
|
||||
//
|
||||
}
|
||||
28
axiom_src/Factories/FactoryInterface.php
Normal file
28
axiom_src/Factories/FactoryInterface.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Enzyme\Axiom\Factories;
|
||||
|
||||
use Enzyme\Axiom\Bags\BagInterface;
|
||||
use Enzyme\Axiom\Models\ModelInterface;
|
||||
|
||||
interface FactoryInterface
|
||||
{
|
||||
/**
|
||||
* Make a new model given the data provided.
|
||||
*
|
||||
* @param BagInterface $data
|
||||
*
|
||||
* @return \Enzyme\Axiom\Models\ModelInterface
|
||||
*/
|
||||
public function make(BagInterface $data);
|
||||
|
||||
/**
|
||||
* Update the model provided with the given data.
|
||||
*
|
||||
* @param ModelInterface $model
|
||||
* @param BagInterface $data
|
||||
*
|
||||
* @return \Enzyme\Axiom\Models\ModelInterface
|
||||
*/
|
||||
public function update(ModelInterface $model, BagInterface $data);
|
||||
}
|
||||
38
axiom_src/Models/ModelInterface.php
Normal file
38
axiom_src/Models/ModelInterface.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Enzyme\Axiom\Models;
|
||||
|
||||
interface ModelInterface
|
||||
{
|
||||
/**
|
||||
* Get the unique identity for this mode.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function identity();
|
||||
|
||||
/**
|
||||
* Checks whether this model has the given attribute set.
|
||||
*
|
||||
* @param string $attribute
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function has($attribute);
|
||||
|
||||
/**
|
||||
* Get the value associated with the given attribute.
|
||||
*
|
||||
* @param string $attribute
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($attribute);
|
||||
|
||||
/**
|
||||
* Get all the attributes associated with this model.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAll();
|
||||
}
|
||||
27
axiom_src/Recipients/OnCreateRecipientInterface.php
Normal file
27
axiom_src/Recipients/OnCreateRecipientInterface.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Enzyme\Axiom\Recipients;
|
||||
|
||||
use Enzyme\Axiom\Models\ModelInterface;
|
||||
use Enzyme\Axiom\Reports\ReportInterface;
|
||||
|
||||
interface OnCreateRecipientInterface
|
||||
{
|
||||
/**
|
||||
* Called when the creation of a model was a success.
|
||||
*
|
||||
* @param ModelInterface $model The newly created model.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function onCreateSuccess(ModelInterface $model);
|
||||
|
||||
/**
|
||||
* Called when the creation of a model was a failure.
|
||||
*
|
||||
* @param ReportInterface $report The failure report.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function onCreateFailure(ReportInterface $report);
|
||||
}
|
||||
27
axiom_src/Recipients/OnDeleteRecipientInterface.php
Normal file
27
axiom_src/Recipients/OnDeleteRecipientInterface.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Enzyme\Axiom\Recipients;
|
||||
|
||||
use Enzyme\Axiom\Models\ModelInterface;
|
||||
use Enzyme\Axiom\Reports\ReportInterface;
|
||||
|
||||
interface OnDeleteRecipientInterface
|
||||
{
|
||||
/**
|
||||
* Called when the deletion of a model was a success.
|
||||
*
|
||||
* @param ModelInterface $model A shell copy of the deleted model.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function onDeleteSuccess(ModelInterface $model);
|
||||
|
||||
/**
|
||||
* Called when the deletion of a model was a failure.
|
||||
*
|
||||
* @param ReportInterface $report The failure report.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function onDeleteFailure(ReportInterface $report);
|
||||
}
|
||||
27
axiom_src/Recipients/OnUpdateRecipientInterface.php
Normal file
27
axiom_src/Recipients/OnUpdateRecipientInterface.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Enzyme\Axiom\Recipients;
|
||||
|
||||
use Enzyme\Axiom\Models\ModelInterface;
|
||||
use Enzyme\Axiom\Reports\ReportInterface;
|
||||
|
||||
interface OnUpdateRecipientInterface
|
||||
{
|
||||
/**
|
||||
* Called when the modification of a model was a success.
|
||||
*
|
||||
* @param ModelInterface $model The updated model.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function onUpdateSuccess(ModelInterface $model);
|
||||
|
||||
/**
|
||||
* Called when the modification of a model was a failure.
|
||||
*
|
||||
* @param ReportInterface $report The failure report.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function onUpdateFailure(ReportInterface $report);
|
||||
}
|
||||
8
axiom_src/Reports/FailureReport.php
Normal file
8
axiom_src/Reports/FailureReport.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Enzyme\Axiom\Reports;
|
||||
|
||||
class FailureReport extends SimpleReport
|
||||
{
|
||||
//
|
||||
}
|
||||
27
axiom_src/Reports/ReportInterface.php
Normal file
27
axiom_src/Reports/ReportInterface.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Enzyme\Axiom\Reports;
|
||||
|
||||
interface ReportInterface
|
||||
{
|
||||
/**
|
||||
* Get the human readable message associated with this report.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMessage();
|
||||
|
||||
/**
|
||||
* Whether this report has additional details.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasDetails();
|
||||
|
||||
/**
|
||||
* Get the additional details associated with this report.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDetails();
|
||||
}
|
||||
30
axiom_src/Reports/SimpleReport.php
Normal file
30
axiom_src/Reports/SimpleReport.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Enzyme\Axiom\Reports;
|
||||
|
||||
class SimpleReport implements ReportInterface
|
||||
{
|
||||
protected $message;
|
||||
protected $details;
|
||||
|
||||
public function __construct($message, $details = [])
|
||||
{
|
||||
$this->message = $message;
|
||||
$this->details = $details;
|
||||
}
|
||||
|
||||
public function getMessage()
|
||||
{
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
public function hasDetails()
|
||||
{
|
||||
return count($this->details) > 0;
|
||||
}
|
||||
|
||||
public function getDetails()
|
||||
{
|
||||
return $this->details;
|
||||
}
|
||||
}
|
||||
56
axiom_src/Repositories/InMemoryRepository.php
Normal file
56
axiom_src/Repositories/InMemoryRepository.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Enzyme\Axiom\Repositories;
|
||||
|
||||
use Enzyme\Axiom\Atoms\AtomInterface;
|
||||
use Enzyme\Axiom\Bags\BagInterface;
|
||||
use Enzyme\Axiom\Factories\FactoryInterface;
|
||||
use Enzyme\Axiom\Models\ModelInterface;
|
||||
|
||||
class InMemoryRepository implements RepositoryInterface
|
||||
{
|
||||
protected $factory;
|
||||
protected $store;
|
||||
|
||||
public function __construct(FactoryInterface $factory)
|
||||
{
|
||||
$this->factory = $factory;
|
||||
$this->store = [];
|
||||
}
|
||||
|
||||
public function add(ModelInterface $model)
|
||||
{
|
||||
$this->store[$model->identity()] = $model;
|
||||
}
|
||||
|
||||
public function removeById(AtomInterface $id)
|
||||
{
|
||||
if ($this->has($id)) {
|
||||
unset($this->store[$id->getValue()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function has(AtomInterface $id)
|
||||
{
|
||||
return isset($this->store[$id->getValue()])
|
||||
&& array_key_exists($id->getValue(), $this->store);
|
||||
}
|
||||
|
||||
public function update(ModelInterface $model, BagInterface $data)
|
||||
{
|
||||
$updated_model = $this->factory->update($model, $data);
|
||||
$this->store[$model->identity()] = $updated_model;
|
||||
}
|
||||
|
||||
public function getById(AtomInterface $id)
|
||||
{
|
||||
return $this->has($id)
|
||||
? $this->store[$id->getValue()]
|
||||
: null;
|
||||
}
|
||||
|
||||
public function getAll()
|
||||
{
|
||||
return $this->store;
|
||||
}
|
||||
}
|
||||
61
axiom_src/Repositories/RepositoryInterface.php
Normal file
61
axiom_src/Repositories/RepositoryInterface.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Enzyme\Axiom\Repositories;
|
||||
|
||||
use Enzyme\Axiom\Atoms\AtomInterface;
|
||||
use Enzyme\Axiom\Bags\BagInterface;
|
||||
use Enzyme\Axiom\Models\ModelInterface;
|
||||
|
||||
interface RepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Add the given model to the repository.
|
||||
*
|
||||
* @param ModelInterface $model
|
||||
*/
|
||||
public function add(ModelInterface $model);
|
||||
|
||||
/**
|
||||
* Remove the model with the given ID from the repository.
|
||||
*
|
||||
* @param AtomInterface $id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function removeById(AtomInterface $id);
|
||||
|
||||
/**
|
||||
* Update the given model with the supplied data.
|
||||
*
|
||||
* @param ModelInterface $model
|
||||
* @param BagInterface $data
|
||||
*
|
||||
* @return \Enzyme\Axiom\Models\ModelInterface
|
||||
*/
|
||||
public function update(ModelInterface $model, BagInterface $data);
|
||||
|
||||
/**
|
||||
* Get the model associated with the given ID.
|
||||
*
|
||||
* @param AtomInterface $id
|
||||
*
|
||||
* @return \Enzyme\Axiom\Models\ModelInterface
|
||||
*/
|
||||
public function getById(AtomInterface $id);
|
||||
|
||||
/**
|
||||
* Get all models from this repository.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAll();
|
||||
|
||||
/**
|
||||
* Check whether this repository has a model associated with the given ID.
|
||||
*
|
||||
* @param AtomInterface $id
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function has(AtomInterface $id);
|
||||
}
|
||||
Reference in New Issue
Block a user