示例#1
0
 /**
  * Evaluates Pie expressions<br>
  * <b>Warning:<b> Do not Evaluate user input!
  * @param string $eval The string to be evaluated
  * @param Scope $scope The scope to test evaluations
  */
 public function evaluate($eval, Scope $scope = null, $repeater = '')
 {
     $toEval = preg_replace_callback("/(?<=').+?(?=')/s", function ($matches) use($scope, $repeater) {
         $find = preg_replace('/^' . $repeater . '\\./', '', $matches[0]);
         $find = Pie::findRecursive($find, $scope);
         return $find !== '' ? $find : $matches[0];
     }, $eval);
     if (empty($toEval)) {
         return false;
     }
     $isValid = false;
     eval("\$isValid = ({$toEval});");
     return (bool) $isValid;
 }
示例#2
0
         }
     }];
 });
 /**
  * Creates a select field based on an array
  * @element select The select element to populate
  * @attr items A reference to the item array
  *
  * Example array:
  * ['value' => 'text', 'default' => ['selected' => 'default']]
  */
 $app->directive('select', function () {
     return ['restrict' => 'E', 'link' => function (Scope $scope, Element $element, TplAttr $tpl) {
         $items = $element->node->getAttribute('items');
         if ($items) {
             $val = Pie::findRecursive($items, $scope);
             if (is_array($val)) {
                 foreach ($val as $index => $value) {
                     $option = $element->node->ownerDocument->createElement('option');
                     $useVal = $value;
                     if (is_array($value) && isset($value['selected'])) {
                         $option->setAttribute('selected', 'selected');
                         $useVal = $value['selected'];
                     } elseif (is_array($value)) {
                         $useVal = array_shift($value);
                     }
                     $option->setAttribute('value', $index);
                     $option->nodeValue = $useVal;
                     $element->node->appendChild($option);
                 }
             }