diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ccef056 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/vendor/ +.idea \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..941452f --- /dev/null +++ b/composer.json @@ -0,0 +1,10 @@ +{ + "name": "panda-league/error-catalog", + "type": "library", + "autoload": { + "psr-4": { + "PandaLeague\\ErrorCatalog\\": "src/" + } + }, + "require": {} +} diff --git a/src/ErrorCatalog.php b/src/ErrorCatalog.php index 2fdef65..7936c61 100644 --- a/src/ErrorCatalog.php +++ b/src/ErrorCatalog.php @@ -4,22 +4,54 @@ class ErrorCatalog { + /** + * @var string + */ protected $namespace; - protected $defaultLanguage; + + /** + * @var string + */ + protected $language; + + /** + * @var array|ErrorCatalogItem[] + */ protected $catalog = []; - public function __construct($namespace) + /** + * ErrorCatalog constructor. + * @param string $namespace + * @param string $language + */ + public function __construct($namespace, $language = 'en-US') { $this->namespace = $namespace; + $this->language = $language; } - public function addItem($language, ErrorCatalogItem $error) + /** + * @param ErrorCatalogItem $error + * @return $this + */ + public function addItem(ErrorCatalogItem $error) { - if (!isset($this->catalog[$language])) { - $this->catalog[$language] = []; + $this->catalog[] = $error; + return $this; + } + + /** + * @param $name + * @return ErrorCatalogItem|null + */ + public function getItem($name) + { + foreach ($this->catalog as $error) { + if ($name == $error->getName()) { + return $error; + } } - $this->catalog[$language][] = $error; - return $this; + return null; } -} \ No newline at end of file +} diff --git a/src/ErrorCatalogItem.php b/src/ErrorCatalogItem.php index 6fb8f32..ea39383 100644 --- a/src/ErrorCatalogItem.php +++ b/src/ErrorCatalogItem.php @@ -43,4 +43,37 @@ public function addIssue(ErrorSpecIssue $issue) return $this; } -} \ No newline at end of file + public function getName() + { + return $this->name; + } + + public function getMessage() + { + return $this->message; + } + + public function getIssueById($id) + { + $return = []; + foreach ($this->issues as $issue) { + if ($issue->getId() == $id) { + $return[] = $issue; + } + } + + return $return; + } + + public function getIssueByReference($reference) + { + $return = []; + foreach ($this->issues as $issue) { + if ($issue->getReference() == $reference) { + $return[] = $issue; + } + } + + return $return; + } +} diff --git a/src/ErrorSpecIssue.php b/src/ErrorSpecIssue.php index 707d831..ff1b3b4 100644 --- a/src/ErrorSpecIssue.php +++ b/src/ErrorSpecIssue.php @@ -8,14 +8,51 @@ class ErrorSpecIssue * @var string $id The ID for the issue. */ protected $id; + + /** + * @var string A reference to identify the issue by. Can be used to retrieve the issue but normally not shown in the catalog + */ + protected $reference; + /** * @var string $issue Use String Formatter syntax to format the issue as a parameterized string. Localize the string. */ protected $issue; - public function __construct($id, $issue) + /** + * ErrorSpecIssue constructor. + * @param string $id + * @param string $reference + * @param string $issue + */ + public function __construct($id, $reference, $issue) { $this->id = $id; + $this->reference = $reference; $this->issue = $issue; } -} \ No newline at end of file + + /** + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * @return string + */ + public function getReference() + { + return $this->reference; + } + + /** + * @return string + */ + public function getIssue() + { + return $this->issue; + } +}