Permalink
Browse files

[Translator] fix metadata

- fix '0' problem
- only access metadata when implementing interface
- refactor code
- clarify phpdoc
  • Loading branch information...
1 parent 3e75d51 commit f10ed77f34e7899e755f5b6ac310efe49df0fced @Tobion Tobion committed Feb 14, 2013
Showing with 33 additions and 22 deletions.
  1. +16 −14 MessageCatalogue.php
  2. +17 −8 MetadataAwareInterface.php
View
@@ -176,8 +176,10 @@ public function addCatalogue(MessageCatalogueInterface $catalogue)
$this->addResource($resource);
}
- $metadata = $catalogue->getMetadata('', '');
- $this->addMetadata($metadata);
+ if ($catalogue instanceof MetadataAwareInterface) {
+ $metadata = $catalogue->getMetadata('', '');
+ $this->addMetadata($metadata);
+ }
}
/**
@@ -238,19 +240,21 @@ public function addResource(ResourceInterface $resource)
*/
public function getMetadata($key = '', $domain = 'messages')
{
- if (empty($domain)) {
+ if ('' == $domain) {
return $this->metadata;
}
if (isset($this->metadata[$domain])) {
- if (!empty($key)) {
- if (isset($this->metadata[$domain][$key])) {
- return $this->metadata[$domain][$key];
- }
- } else {
+ if ('' == $key) {
return $this->metadata[$domain];
}
+
+ if (isset($this->metadata[$domain][$key])) {
+ return $this->metadata[$domain][$key];
+ }
}
+
+ return null;
}
/**
@@ -266,15 +270,13 @@ public function setMetadata($key, $value, $domain = 'messages')
*/
public function deleteMetadata($key = '', $domain = 'messages')
{
- if (empty($domain)) {
+ if ('' == $domain) {
$this->metadata = array();
- }
-
- if (empty($key)) {
+ } elseif ('' == $key) {
unset($this->metadata[$domain]);
+ } else {
+ unset($this->metadata[$domain][$key]);
}
-
- unset($this->metadata[$domain][$key]);
}
/**
View
@@ -19,27 +19,36 @@
interface MetadataAwareInterface
{
/**
- * Gets meta data for given domain and key.
+ * Gets metadata for the given domain and key.
+ *
+ * Passing an empty domain will return an array with all metadata indexed by
+ * domain and then by key. Passing an empty key will return an array with all
+ * metadata for the given domain.
*
* @param string $domain The domain name
- * @param string $key Key
+ * @param string $key The key
+ *
+ * @return mixed The value that was set or an array with the domains/keys or null
*/
public function getMetadata($key = '', $domain = 'messages');
/**
- * Adds meta data to a message domain.
+ * Adds metadata to a message domain.
*
- * @param string $key Key
- * @param string|array $value Value
- * @param string $domain The domain name
+ * @param string $key The key
+ * @param mixed $value The value
+ * @param string $domain The domain name
*/
public function setMetadata($key, $value, $domain = 'messages');
/**
- * Deletes meta data for given key and domain.
+ * Deletes metadata for the given key and domain.
+ *
+ * Passing an empty domain will delete all metadata. Passing an empty key will
+ * delete all metadata for the given domain.
*
* @param string $domain The domain name
- * @param string $key Key
+ * @param string $key The key
*/
public function deleteMetadata($key = '', $domain = 'messages');
}

0 comments on commit f10ed77

Please sign in to comment.