Permalink
Browse files

move taxonomy from taxonomy library

  • Loading branch information...
1 parent d9cbdf7 commit 6de51d78edb05a87ff5694ae627e8abfd8f5d1ed @iampersistent iampersistent committed Nov 18, 2012
@@ -0,0 +1,117 @@
+<?php
+/**
+ * (c) Vespolina Project http://www.vespolina-project.org
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace Vespolina\Entity\Taxonomy;
+
+use Vespolina\Entity\Taxonomy\TaxonomyInterface;
+
+/**
+ * @author Daniel Kucharski <daniel@xerias.be>
+ */
+class Taxonomy implements TaxonomyInterface
+{
+ protected $isHierarchical;
+ protected $name;
+ protected $terms;
+ protected $type;
+
+ public function __construct($isHierarchical = false)
+ {
+ $this->isHierarchical = $isHierarchical;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function addTerm(TermInterface $term)
+ {
+ $this->terms[] = $term;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function addTerms(array $terms)
+ {
+ $this->terms = array_merge($this->terms, $terms);
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function clearTerms()
+ {
+ $this->terms = array();
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function getTerms()
+ {
+ return $this->terms;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function removeTerm(TermInterface $term)
+ {
+ foreach ($this->terms as $key => $termToCompare) {
+ if ($termToCompare == $term) {
+ unset($this->terms[$key]);
+ break;
+ }
+ }
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function setTerms(array $terms)
+ {
+ $this->terms = $terms;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function setName($name)
+ {
+ $this->name = $name;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function getType()
+ {
+ return $this->type;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function setType($type)
+ {
+ $this->type = $type;
+ }
+
+ protected function slugify($text)
+ {
+ return preg_replace('/[^a-z0-9_\s-]/', '', preg_replace("/[\s_]/", "-", preg_replace('!\s+!', ' ', strtolower(trim($text)))));
+ }
+}
@@ -0,0 +1,82 @@
+<?php
+/**
+ * (c) Vespolina Project http://www.vespolina-project.org
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+namespace Vespolina\Entity\Taxonomy;
+
+use Vespolina\Entity\Taxonomy\TermInterface;
+
+
+/**
+ * @author Daniel Kucharski <daniel@xerias.be>
+ */
+interface TaxonomyInterface
+{
+ /**
+ * Add a term to the collection
+ *
+ * @param TermInterface $term
+ */
+ function addTerm(TermInterface $term);
+
+ /**
+ * Add a collection of terms
+ *
+ * @param array $terms
+ */
+ function addTerms(array $terms);
+
+ /**
+ * Remove all terms from the collection
+ */
+ function clearTerms();
+
+ /**
+ * Return a collection of terms
+ *
+ * @return array of terms
+ */
+ function getTerms();
+
+ /**
+ * Remove a term from the collection
+ *
+ * @param TermInterface $term
+ */
+ function removeTerm(TermInterface $term);
+
+ /**
+ * Set a collection of terms
+ *
+ * @param array $terms
+ */
+ function setTerms(array $terms);
+
+ /**
+ * Get the taxonomy name
+ * eg. Taxonomy_hierarchy
+ *
+ * @abstract
+ * @return string
+ */
+ function getName();
+
+ /**
+ * Retrieve the taxonomy type
+ *
+ * Possible options are:
+ * - hierarchical
+ * - tags
+ *
+ * @abstract
+ *
+ */
+ function getType();
+
+ function setName($name);
+
+ function setType($type);
+}
Oops, something went wrong.

0 comments on commit 6de51d7

Please sign in to comment.