예제 #1
0
파일: Set.php 프로젝트: asherwunk/primus2
try {
    $testBuild = Types\Set::build(array(1, 2, 3, 4, 5));
} catch (\Exception $e) {
    $success = false;
}
if ($success) {
    echo "Success!\n";
} else {
    echo "Failure...\n";
}
echo "\nSet Internals -- \n";
var_dump($testSet->getArray());
echo "\nAdd Operation (3) -> ";
$success = true;
try {
    $testSet->add(3);
} catch (\Exception $e) {
    $success = false;
}
if ($success) {
    echo "Success!\n";
} else {
    echo "Failure...\n";
}
echo "\nSet Internals -- \n";
var_dump($testSet->getArray());
echo "\nAdd Operation (2) -> ";
$fail = true;
try {
    $testSet->add(2);
    $fail = false;
예제 #2
0
 /**
  * Add a value to the set
  * 
  * Runs the value by the restrictions, only triggering if set is strict
  * otherwise doing nothing and exiting the function
  * 
  * @param mixed $value Value to add to the set, must be of allowed type
  * 
  * @return string|false The identifier for the entry, false otherwise
  * 
  * @throws Exception\InvalidArgumentException if 'strict' option is set
  *             and type is not in Restrictions
  * 
  */
 public function add($value)
 {
     try {
         $valid = Restrictions::checkElements(array($value), $this->restrictions, $this->conf->strict);
     } catch (Exception\InvalidArgumentException $e) {
         if ($this->conf->strict) {
             throw new Exception\InvalidArgumentException('RestrictedSet->add: Restricted Value');
         } else {
             return false;
         }
     }
     // Passes restrictions, but safety check
     if ($valid) {
         return parent::add($value);
     }
 }