aboutsummaryrefslogtreecommitdiffstats
path: root/Model/Behavior.php
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2013-06-10 14:17:22 +0200
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2013-06-10 14:20:55 +0200
commit95d8e9a76566f980fb7e08fb7c27b6b884d53f57 (patch)
tree10f88f78936fb40395f7d9c5fbc77ee9071a2744 /Model/Behavior.php
parent824e66a0399b20931678e1fdea2ce5fa018f6319 (diff)
downloadPraspel-95d8e9a76566f980fb7e08fb7c27b6b884d53f57.zip
Praspel-95d8e9a76566f980fb7e08fb7c27b6b884d53f57.tar.gz
Praspel-95d8e9a76566f980fb7e08fb7c27b6b884d53f57.tar.bz2
Add the allowedClauses attributes.
It helps to simplify the code.
Diffstat (limited to 'Model/Behavior.php')
-rw-r--r--Model/Behavior.php57
1 files changed, 52 insertions, 5 deletions
diff --git a/Model/Behavior.php b/Model/Behavior.php
index 852d1a7..6279cbc 100644
--- a/Model/Behavior.php
+++ b/Model/Behavior.php
@@ -49,6 +49,11 @@ from('Hoa')
-> import('Praspel.Model.Clause')
/**
+ * \Hoa\Praspel\Model\Is
+ */
+-> import('Praspel.Model.Is')
+
+/**
* \Hoa\Praspel\Model\Requires
*/
-> import('Praspel.Model.Requires')
@@ -71,7 +76,12 @@ from('Hoa')
/**
* \Hoa\Praspel\Model\Collection
*/
--> import('Praspel.Model.Collection');
+-> import('Praspel.Model.Collection')
+
+/**
+ * \Hoa\Praspel\Model\Description
+ */
+-> import('Praspel.Model.Description');
}
@@ -97,18 +107,31 @@ class Behavior extends Clause {
const NAME = 'behavior';
/**
+ * Allowed clauses.
+ *
+ * @var \Hoa\Praspel\Model\Behavior array
+ */
+ protected static $_allowedClauses = array(
+ 'requires',
+ 'ensures',
+ 'throwable',
+ 'invariant',
+ 'behavior'
+ );
+
+ /**
* Clauses.
*
* @var \Hoa\Praspel\Model\Behavior array
*/
- protected $_clauses = array();
+ protected $_clauses = array();
/**
* Identifier (@behavior <identifier> { … }).
*
* @var \Hoa\Praspel\Model\Behavior string
*/
- protected $_identifier = null;
+ protected $_identifier = null;
@@ -127,8 +150,17 @@ class Behavior extends Clause {
$handle = null;
+ if(false === in_array($clause, static::getAllowedClauses()))
+ throw new \Hoa\Praspel\Exception\Model(
+ 'Clause @%s is not allowed in @%s.',
+ 1, array($clause, $this->getId()));
+
switch($clause) {
+ case 'is':
+ $handle = new Is($this);
+ break;
+
case 'requires':
$handle = new Requires($this);
break;
@@ -157,10 +189,14 @@ class Behavior extends Clause {
);
break;
+ case 'description':
+ $handle = new Description($this);
+ break;
+
default:
throw new \Hoa\Praspel\Exception\Model(
- 'Clause @%s is unknown or not allowed in %s.',
- 0, array($clause, $this->getName()));
+ 'Clause @%s is unknown.',
+ 1, array($clause, $this->getName()));
}
return $this->_clauses[$clause] = $handle;
@@ -179,6 +215,17 @@ class Behavior extends Clause {
}
/**
+ * Get allowed clauses.
+ *
+ * @access public
+ * @return array
+ */
+ public static function getAllowedClauses ( ) {
+
+ return static::$_allowedClauses;
+ }
+
+ /**
* Set identifier.
*
* @access public