Beispiel #1
0
<?php

use Pie\Pie;
use Pie\Modules\Http\Http;
return call_user_func(function () {
    $app = Pie::module('Http');
    $app->service('http', new Http());
    return $app;
});
Beispiel #2
0
 protected function _find($path, $object = null)
 {
     $obj = $object === null ? $this->values : $object;
     return Pie::find($path, $obj);
 }
Beispiel #3
0
<?php

use Pie\Crust\Controller;
use Pie\Crust\Event;
use Pie\Pie;
use Pie\Modules\Route\Route;
use Pie\Modules\Route\RouteParams;
return call_user_func(function () {
    $app = Pie::module('Route');
    $route = new Route();
    $routeParams = new RouteParams();
    $app->service('route', $route);
    $app->service('routeParams', $routeParams);
    $app->method = strtolower(filter_input(INPUT_SERVER, 'REQUEST_METHOD'));
    $app->path = $route->pathToArray(rtrim(filter_input(INPUT_SERVER, 'REQUEST_URI'), '/'));
    $app->query = $route->queryString(filter_input(INPUT_SERVER, 'REQUEST_URI'));
    parse_str($app->query, $_GET);
    $app->listen('cleanup', function ($parent) use($route, $app) {
        $controller = $route->findRoute($app);
        if (isset($controller['settings']['modules'])) {
            $parent->addDepndencies($controller['settings']['modules']);
        }
        if ($controller !== null) {
            $parent->exec($controller);
        }
        $app->broadcast('routeComplete', [$controller, $parent]);
    });
    $app->listen('routeComplete', function ($controller, $parent) use($route) {
        if (isset($route->getAlways()['displayAs']) || isset($controller['settings']['displayAs']) || isset($controller['settings']['controller'])) {
            if (isset($controller['settings']['controller']) && is_string($controller['settings']['controller']) && $this->controllerExists($controller['settings']['controller'], $contrl)) {
                $name = $controller['settings']['controller'];
 protected function _test(&$errors)
 {
     foreach ($this->validations as $key => $val) {
         $map = array_map('trim', explode('|', $val));
         $search = Pie::find($key);
         foreach ($map as $req) {
             $req = strtolower($req);
             // Value is required
             if ($req == 'required' && $search == '') {
                 $errors[] = ['key' => $req, 'value' => $search, 'item' => $key, 'msg' => 'Item is missing'];
             }
             // Value min and max and len
             if (preg_match('/^(min|max|len):\\d+/i', $req, $matches)) {
                 $length = (int) explode(':', $req)[1];
                 $action = strtolower($matches[1]);
                 if ($action == 'min' && strlen($search) < $length) {
                     $errors[] = ['key' => $req, 'value' => $search, 'item' => $key, 'msg' => 'Item length is too short'];
                 } elseif ($action == 'max' && strlen($search) > $length) {
                     $errors[] = ['key' => $req, 'value' => $search, 'item' => $key, 'msg' => 'Item length is too long'];
                 } elseif ($action == 'len' && strlen($search) != $length) {
                     $errors[] = ['key' => $req, 'value' => $search, 'item' => $key, 'msg' => 'Item does not equal the length'];
                 }
             }
             if (preg_match('/^between:(\\d+),(\\d+)/i', $req, $matches)) {
                 $min = $matches[1];
                 $max = $matches[2];
                 $this->minMax($req, $key, $search, $min, $max, $errors);
             }
             // Search within a list of items
             if (preg_match('/^(notin|in):(.+)/i', $req, $matches)) {
                 $action = strtolower($matches[1]);
                 $items = array_map('trim', explode(',', $matches[2]));
                 if ($action == 'in' && !in_array($search, $items)) {
                     $errors[] = ['key' => $req, 'value' => $search, 'item' => $key, 'msg' => 'Item is not in the list'];
                 } elseif ($action == 'notin' && in_array($search, $items)) {
                     $errors[] = ['key' => $req, 'value' => $search, 'item' => $key, 'msg' => 'Item is in the list'];
                 }
             }
             // Match an item against a regular expression
             if (preg_match('/match:(.+)/i', $req, $matches)) {
                 if (!preg_match($matches[1], $search)) {
                     $errors[] = ['key' => $req, 'value' => $search, 'item' => $key, 'msg' => 'Item does not match'];
                 }
             }
             // Validate an ip address
             if ($req == 'ip' && !filter_var($search, FILTER_VALIDATE_IP)) {
                 $errors[] = ['key' => $req, 'value' => $search, 'item' => $key, 'msg' => 'Item is not an ip address'];
             }
             // Validate an email address
             if ($req == 'email' && !filter_var($search, FILTER_VALIDATE_EMAIL)) {
                 $errors[] = ['key' => $req, 'value' => $search, 'item' => $key, 'msg' => 'Item is not an email address'];
             }
             // Validate a url
             if ($req == 'url' && !filter_var($search, FILTER_VALIDATE_URL)) {
                 $errors[] = ['key' => $req, 'value' => $search, 'item' => $key, 'msg' => 'Item is not a url'];
             }
             // Validate a type of data
             if (preg_match('/typeof:(.+)/i', $req, $matches)) {
                 $types = array_map('trim', explode(',', $matches[1]));
                 if (!in_array(gettype($search), $types)) {
                     $errors[] = ['key' => $req, 'value' => $search, 'item' => $key, 'msg' => 'Item is not of type'];
                 }
             }
             if ($req == 'json') {
                 json_decode($search);
                 if (json_last_error() != JSON_ERROR_NONE) {
                     $errors[] = ['key' => $req, 'value' => $search, 'item' => $key, 'msg' => 'Item is not valid json'];
                 }
             }
             // Request key and value must be different
             if ($req == 'different' && preg_replace('/^\\$.+?\\./', '', $key) == $search) {
                 $errors[] = ['key' => $req, 'value' => $search, 'item' => $key, 'msg' => 'Item key must be different from its value'];
             }
             // Request key and value must be the same
             if ($req == 'same' && preg_replace('/^\\$.+?\\./', '', $key) != $search) {
                 $errors[] = ['key' => $req, 'value' => $search, 'item' => $key, 'msg' => 'Item key must be different from its value'];
             }
             // Require a numeric value
             if ($req == 'numeric' && !is_numeric($search)) {
                 $errors[] = ['key' => $req, 'value' => $search, 'item' => $key, 'msg' => 'Item must be numeric'];
             }
             // Require a value of numbers only 0 or larger
             if ($req == 'integer' && !ctype_digit($search)) {
                 $errors[] = ['key' => $req, 'value' => $search, 'item' => $key, 'msg' => 'Item must be an integer'];
             }
             // Require an alpha value
             if ($req == 'alpha' && !ctype_alpha($search)) {
                 $errors[] = ['key' => $req, 'value' => $search, 'item' => $key, 'msg' => 'Item must be alpha'];
             }
         }
     }
     if (count($errors) > 0) {
         return false;
     }
     return true;
 }
Beispiel #5
0
 public static function findRecursive($find, $scope)
 {
     $value = Pie::find($find, $scope);
     if ($value === '') {
         $cscope = $scope->getParentScope();
         do {
             if ($cscope === null) {
                 break;
             }
             $value = Pie::find($find, $cscope);
             if ($value !== null) {
                 break;
             }
             $cscope = $cscope->getParentScope();
         } while (true);
     }
     return $value;
 }
Beispiel #6
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;
 }
Beispiel #7
0
<?php

use Pie\Pie;
use Pie\Modules\Database\Db;
return call_user_func(function () {
    $app = Pie::module('Database');
    $app->service('db', new Db());
    return $app;
});
Beispiel #8
0
 public function functions($value, $operations, Scope $scope)
 {
     $operations = array_map('trim', $operations);
     foreach ($operations as $index => $op) {
         $items = explode(":", $op);
         $func = array_shift($items);
         array_unshift($items, $value);
         $filter = $this->findFilter($func);
         if ($filter) {
             $func = $filter;
         } else {
             if (!is_callable($func)) {
                 $call = Pie::find($func, $scope);
                 if (!$call) {
                     $cscope = $scope->getParentScope();
                     do {
                         if ($cscope === null) {
                             break;
                         }
                         $func = Pie::find($op, $cscope);
                         if ($func !== null) {
                             break;
                         }
                         $cscope = $cscope->getParentScope();
                     } while (true);
                 } else {
                     $func = $call;
                 }
             }
             if (!$call) {
                 $func = Pie::find($func, Pie::$rootScope);
             }
         }
         if ($func instanceof Closure) {
             $value = call_user_func_array($func, $items);
         }
     }
     return $value;
 }
Beispiel #9
0
<?php

use Pie\Modules\Session\Session;
use Pie\Pie;
return call_user_func(function () {
    $app = Pie::module('Session', []);
    $app->service('session', new Session());
    return $app;
});
Beispiel #10
0
<?php

use Pie\Pie;
use Pie\Modules\Media\Media;
return call_user_func(function () {
    $app = Pie::module('Media', []);
    $app->service('media', new Media());
    return $app;
});
Beispiel #11
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);
                 }
             }