Hoa central
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Hoa\Praspel\Model\Variable\Borrowing Class Reference
Inheritance diagram for Hoa\Praspel\Model\Variable\Borrowing:

Public Member Functions

 __construct ($name, $local, Praspel\Model\Clause $clause=null)
 
 getType ()
 
 getBorrowedVariable ()
 
 __set ($name, $value)
 
 predicate ($q=null)
 
 sample (Math\Sampler $sampler=null)
 
 reset ()
 
 key ($scalar)
 
 contains ($scalar)
 
 is ()
 
 domainof ($variable)
 
getDomains ()
 
getHeld ()
 
 isLocal ()
 
 getConstraints ()
 
- Public Member Functions inherited from Hoa\Praspel\Model\Variable\Variable
 __construct ($name, $local, Praspel\Model\Clause $clause=null)
 
 setValue ($value)
 
getValue ()
 
 __set ($name, $value)
 
 predicate ($q=null)
 
 sample (Math\Sampler $sampler=null)
 
 reset ()
 
 key ($scalar)
 
 contains ($scalar)
 
 is ()
 
 domainof ($variable)
 
getDomains ()
 
getHeld ()
 
 getName ()
 
 isLocal ()
 
 getConstraints ()
 
 getAlias ()
 
 getClause ()
 
 accept (Visitor\Visit $visitor, &$handle=null, $eldnah=null)
 
- Public Member Functions inherited from Hoa\Visitor\Element
 accept (Visit $visitor, &$handle=null, $eldnah=null)
 

Public Attributes

const TYPE_OLD = 0
 
const TYPE_EXTERNAL = 1
 

Protected Member Functions

 determineType ()
 
 computeOld ($name)
 
 computeDynamicResolution ($name)
 

Protected Attributes

 $_type = null
 
 $_variable = null
 
- Protected Attributes inherited from Hoa\Praspel\Model\Variable\Variable
 $_name = null
 
 $_local = false
 
 $_clause = null
 
 $_value = null
 
 $_domains = null
 
 $_refDomains = null
 
 $_alias = null
 
 $_constraints = []
 
 $_tmpConstraintsType = null
 
 $_tmpConstraintsIndex = null
 

Detailed Description

Class .

Represent a borrowing variable.

Definition at line 50 of file Borrowing.php.

Constructor & Destructor Documentation

Hoa\Praspel\Model\Variable\Borrowing::__construct (   $name,
  $local,
Praspel\Model\Clause  $clause = null 
)

Build a variable.

Parameters
string$nameName.
bool$localLocal.
\Hoa\Praspel\Model\Clause$clauseClause.
Returns
void
Exceptions

Definition at line 91 of file Borrowing.php.

95  {
96  parent::__construct($name, $local, $clause);
97  $this->determineType();
98 
99  return;
100  }

Here is the call graph for this function:

Member Function Documentation

Hoa\Praspel\Model\Variable\Borrowing::__set (   $name,
  $value 
)

Allow to write $variable->in = … to define domains (if $name is not equal to "in", then it is a normal behavior).

Parameters
string$nameName.
mixed$valueValue.
Returns
void
Exceptions

Definition at line 266 of file Borrowing.php.

267  {
268  return $this->getBorrowedVariable()->__set($name, $value);
269  }

Here is the call graph for this function:

Hoa\Praspel\Model\Variable\Borrowing::computeDynamicResolution (   $name)
protected

Compute dynamic resolution.

Parameters
string$nameName.
Returns
void
Exceptions

Definition at line 175 of file Borrowing.php.

176  {
177  $this->_type = static::TYPE_EXTERNAL;
178 
179  $clause = $this->getClause();
180  $parts = explode('->', $name);
181  $head = array_shift($parts);
182 
183  if ('this' !== $head) {
184  throw new Praspel\Exception\Model('Not yet implemented!');
185  }
186 
187  $registry = Praspel::getRegistry();
188  $root = $clause->getRoot();
189  $bindedClass = $root->getBindedClass();
190 
191  if (null === $bindedClass) {
192  throw new Praspel\Exception\Model(
193  'Cannot resolve the dynamic identifier %s; ' .
194  '%s::getBindedClass returned null.',
195  3,
196  [$name, get_class($root)]
197  );
198  }
199 
200  $attribute = array_shift($parts);
201  $id = $bindedClass . '::$' . $attribute;
202 
203  if (!isset($registry[$id])) {
204  throw new Praspel\Exception\Model(
205  'The contract identifier %s does not exist in the registry.',
206  4,
207  $name
208  );
209  }
210 
211  $entry = $registry[$id];
212 
213  if (false === $entry->clauseExists('invariant')) {
214  throw new Praspel\Exception\Model(
215  '%s is not declared with an @invariant clause.',
216  5,
217  $id
218  );
219  }
220 
221  $targetedClause = $entry->getClause('invariant');
222 
223  if (!isset($targetedClause[$attribute])) {
224  throw new Praspel\Exception\Model(
225  'The identifier %s does not exist.',
226  6,
227  $attribute
228  );
229  }
230 
231  $variable = $targetedClause[$attribute];
232  $this->_variable = $variable;
233 
234  return;
235  }
static getRegistry()
Definition: Praspel.php:121

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Praspel\Model\Variable\Borrowing::computeOld (   $name)
protected

Compute (…).

Parameters
string$nameName.
Returns
void
Exceptions

Definition at line 135 of file Borrowing.php.

136  {
137  $clause = $this->getClause();
138  $this->_type = static::TYPE_OLD;
139  $parent = $clause->getParent();
140 
141  while (
142  false === $parent->clauseExists('requires') &&
143  null !== $parent = $parent->getParent()
144  );
145 
146  if (null === $parent ||
147  false === $parent->clauseExists('requires')) {
148  throw new Praspel\Exception\Model('No parent or no requires.', 1);
149  }
150 
151  $requires = $parent->getClause('requires');
152  $inScopeVariables = $requires->getInScopeVariables();
153 
154  if (!isset($inScopeVariables[$name])) {
155  throw new Praspel\Exception\Model(
156  'Variable %s does not exist, cannot get its old value ' .
157  '(in @%s).',
158  2,
159  [$name, $clause->getName()]
160  );
161  }
162 
163  $this->_variable = &$inScopeVariables[$name];
164 
165  return;
166  }

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Praspel\Model\Variable\Borrowing::contains (   $scalar)

Define a “contains” constraint.

Parameters
mixed$scalarValue.
Returns

Definition at line 322 of file Borrowing.php.

323  {
324  return $this->getBorrowedVariable()->contains($scalar);
325  }

Here is the call graph for this function:

Hoa\Praspel\Model\Variable\Borrowing::determineType ( )
protected

Determine type of the variable.

Returns
void
Exceptions

Definition at line 108 of file Borrowing.php.

109  {
110  $name = $this->getName();
111 
112  if ('\old(' === substr($name, 0, 5)) {
113  $this->computeOld(substr($name, 5, -1));
114  } elseif (false !== strpos($name, '>', 2)) {
115  $this->computeDynamicResolution($name);
116  } else {
117  throw new Praspel\Exception\Model(
118  'Variable %s would be a borrowing one, but its type cannot ' .
119  'be determined.',
120  0,
121  $name
122  );
123  }
124 
125  return;
126  }

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Praspel\Model\Variable\Borrowing::domainof (   $variable)

Declare a “domainof” (alias).

Parameters
\Hoa\Praspel\Model\Variable$variableVariable.
Returns
Exceptions

Definition at line 345 of file Borrowing.php.

346  {
347  return $this->getBorrowedVariable()->domainof($variable);
348  }

Here is the call graph for this function:

Hoa\Praspel\Model\Variable\Borrowing::getBorrowedVariable ( )

Get the borrowed variable.

Returns

Definition at line 252 of file Borrowing.php.

253  {
254  return $this->_variable;
255  }

Here is the caller graph for this function:

Hoa\Praspel\Model\Variable\Borrowing::getConstraints ( )

Get constraints.

Returns
array

Definition at line 385 of file Borrowing.php.

386  {
387  return $this->getBorrowedVariable()->getConstraints();
388  }

Here is the call graph for this function:

& Hoa\Praspel\Model\Variable\Borrowing::getDomains ( )

Get domains.

Returns

Definition at line 355 of file Borrowing.php.

356  {
357  return $this->getBorrowedVariable()->getDomains();
358  }

Here is the call graph for this function:

& Hoa\Praspel\Model\Variable\Borrowing::getHeld ( )

Get held realdoms.

Returns

Implements Hoa\Realdom\IRealdom\Holder.

Definition at line 365 of file Borrowing.php.

366  {
367  return $this->getBorrowedVariable()->getHeld();
368  }

Here is the call graph for this function:

Hoa\Praspel\Model\Variable\Borrowing::getType ( )

Get type.

Returns
int

Definition at line 242 of file Borrowing.php.

243  {
244  return $this->_type;
245  }
Hoa\Praspel\Model\Variable\Borrowing::is ( )

Add an “is” constraint.

Parameters
string... Keywords.
Returns

Definition at line 333 of file Borrowing.php.

334  {
335  throw new Praspel\Exception\Model('TODO');
336  }
Hoa\Praspel\Model\Variable\Borrowing::isLocal ( )

Check if the variable is local (let) or not.

Returns
bool

Definition at line 375 of file Borrowing.php.

376  {
377  return $this->getBorrowedVariable()->isLocal();
378  }

Here is the call graph for this function:

Hoa\Praspel\Model\Variable\Borrowing::key (   $scalar)

Define a “key” constraint. Use $variable->key(…)->in = …;

Parameters
mixed$scalarValue.
Returns

Definition at line 311 of file Borrowing.php.

312  {
313  return $this->getBorrowedVariable()->key($scalar);
314  }

Here is the call graph for this function:

Hoa\Praspel\Model\Variable\Borrowing::predicate (   $q = null)

Definition at line 278 of file Borrowing.php.

279  {
280  return $this->getBorrowedVariable()->predicate($q);
281  }

Here is the call graph for this function:

Hoa\Praspel\Model\Variable\Borrowing::reset ( )

Call the reset() method on realistic domains.

Returns
void

Definition at line 300 of file Borrowing.php.

301  {
302  return $this->getBorrowedVariable()->reset();
303  }

Here is the call graph for this function:

Hoa\Praspel\Model\Variable\Borrowing::sample ( Math\Sampler  $sampler = null)

Call the sample() method on realistic domains.

Parameters
\Hoa\Math\Sampler$samplerSampler.
Returns
mixed
Exceptions

Definition at line 290 of file Borrowing.php.

291  {
292  return $this->getBorrowedVariable()->sample($sampler);
293  }

Here is the call graph for this function:

Member Data Documentation

Hoa\Praspel\Model\Variable\Borrowing::$_type = null
protected

Definition at line 71 of file Borrowing.php.

Hoa\Praspel\Model\Variable\Borrowing::$_variable = null
protected

Definition at line 78 of file Borrowing.php.

const Hoa\Praspel\Model\Variable\Borrowing::TYPE_EXTERNAL = 1

Type: external (e.g. this->foo->bar).

int

Definition at line 64 of file Borrowing.php.

const Hoa\Praspel\Model\Variable\Borrowing::TYPE_OLD = 0

Type: (e).

int

Definition at line 57 of file Borrowing.php.


The documentation for this class was generated from the following file: