Skip to content

Commit

Permalink
Merge pull request #1 from shauno/taurus-implementation
Browse files Browse the repository at this point in the history
Make it a composer project so it can, you know, work...
  • Loading branch information
Ed-leRoux authored Apr 3, 2018
2 parents 80161f6 + cc5e4b3 commit eea86d2
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/vendor/
.idea
10 changes: 10 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "panda-league/error-catalog",
"type": "library",
"autoload": {
"psr-4": {
"PandaLeague\\ErrorCatalog\\": "src/"
}
},
"require": {}
}
48 changes: 40 additions & 8 deletions src/ErrorCatalog.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
35 changes: 34 additions & 1 deletion src/ErrorCatalogItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,37 @@ public function addIssue(ErrorSpecIssue $issue)
return $this;
}

}
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;
}
}
41 changes: 39 additions & 2 deletions src/ErrorSpecIssue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

/**
* @return string
*/
public function getId()
{
return $this->id;
}

/**
* @return string
*/
public function getReference()
{
return $this->reference;
}

/**
* @return string
*/
public function getIssue()
{
return $this->issue;
}
}

0 comments on commit eea86d2

Please sign in to comment.