Пример #1
0
 /**
  * Should one of the conditions be missing, the validator
  * will return a successful test.
  */
 public function test($value, $context)
 {
     if ($this->hasConfig("if") && !is_null($this->getConfig("if"))) {
         $request = Strata::router()->getCurrentController()->request;
         foreach ($this->getConfig("if") as $key => $expectedValue) {
             $comparedValue = $request->isPost() ? $request->post($key) : $request->get($key);
             if ($comparedValue !== $expectedValue) {
                 // ignore the rest of the validations, $expectedValue is not met
                 // therefore it's not a case when we need to validate the actual value.
                 return true;
             }
         }
     }
     if (is_string($value)) {
         $trimmed = trim($value);
         return !empty($trimmed);
     }
     // Array are expected to be lists on which we are
     // validating integer values, not string values.
     if (is_array($value)) {
         foreach ($value as $key => $currentValue) {
             if ((int) $currentValue > 0) {
                 return true;
             }
         }
         return false;
     }
 }
Пример #2
0
 /**
  * Opens up a form tag
  * @param  mixed   ModelEntity or null
  * @param  array  $options
  * @return string
  */
 public function create($mixed = null, $options = array())
 {
     $this->request = Strata::router()->getCurrentController()->request;
     if (!is_null($mixed) && !in_array('Strata\\Model\\CustomPostType\\ModelEntity', class_parents($mixed))) {
         throw new Exception("A form can only be linked to either an object inheriting ModelEntity or nothing at all.");
     }
     if (is_object($mixed)) {
         $this->associatedEntity = $mixed;
     }
     $this->configuration = $this->parseFormConfiguration($options);
     $formAttributes = $this->configuration;
     unset($formAttributes['hasSteps']);
     unset($formAttributes['type']);
     unset($formAttributes['nonce']);
     if (!is_null($this->associatedEntity) && $this->associatedEntity->hasValidationErrors()) {
         if (array_key_exists('class', $formAttributes)) {
             $formAttributes['class'] .= " has-errors ";
         } else {
             $formAttributes['class'] = "has-errors";
         }
     }
     $htmlAttributes = $this->arrayToHtmlAttributes($formAttributes);
     $salt = $this->getNonceSalt();
     $nonceTag = $this->generateNonceTag($salt);
     $nonceHidden = $this->generateHidden(array("name" => "auth_id"), wp_create_nonce($salt));
     return sprintf("<form %s>\n%s\n%s\n", $htmlAttributes, $nonceHidden, $nonceTag);
 }
 private function saveRules()
 {
     if (count($this->collectedRewrites)) {
         $rewriter = Strata::rewriter();
         foreach ($this->collectedRewrites as $rewrite) {
             $rewriter->addRule($rewrite[0], $rewrite[1]);
         }
     }
     if (count($this->collectedRoutes)) {
         $router = Strata::router();
         $router->addModelRoutes($this->collectedRoutes);
     }
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 public function test($value, $context)
 {
     $confiiguration = $this->getconfiguration();
     if (!isset($confiiguration['as'])) {
         throw new Exception("SameValidator is missing the required 'as' configuration key.");
     }
     $request = Strata::router()->getCurrentController()->request;
     $as = $this->getConfig('as');
     if ($request->isPost($as)) {
         $comparedWith = $request->post($as);
     } elseif ($request->isGet($as)) {
         $comparedWith = $request->get($as);
     } else {
         return false;
     }
     // When the value compared is null (instead of empty string), it means
     // it was not posted. Imply that if the post value is null, then we do not have to compare
     // values.
     return is_null($comparedWith) || $value === $comparedWith;
 }
Пример #5
0
 public function redirect($controllerName, $action = "index", $arguments = array())
 {
     $router = Strata::router();
     if (is_null($router)) {
         return;
     }
     $router->abandonCurrent();
     $route = new UrlRoute();
     $route->action = $action;
     $route->arguments = $arguments;
     if ($controllerName !== $this->getShortName()) {
         $route->controller = Controller::factory($controllerName);
         $route->controller->request = $this->request;
         $route->controller->view = $this->view;
     } else {
         $route->controller = $this;
         $route->setDirectExecution();
     }
     return $route->attemptCompletion();
 }
Пример #6
0
 /**
  * Renders on the page and end the process. Useful for simple HTML returns or data in another format like JSON.
  * @param  array $options An associative array of rendering options
  * @return string          The rendered content.
  */
 public function render($options = array())
 {
     $this->configure($options + $this->getDefaultConfiguration());
     $content = $this->parseCurrentContent();
     if ((bool) $this->getConfig('end')) {
         // Only play with headers when we know we will
         // kill the process.
         $this->applyHeaders();
         echo $content;
         Strata::router()->route->end();
         exit;
     }
     echo $content;
 }
Пример #7
0
 /**
  * Adds a new resource route to the router attached to the current
  * app.
  * @param Taxonomy $taxonomy
  */
 private function addResourceRoute(Taxonomy $taxonomy)
 {
     Strata::router()->addResource($taxonomy);
 }
 /**
  * Adds a new resource route to the router attached to the current
  * app.
  * @param CustomPostType $customPostType
  */
 private function addResourceRoute(CustomPostType $customPostType)
 {
     Strata::router()->addResource($customPostType);
 }
Пример #9
0
    ?>
            </div>
        <?php 
}
?>
    </div>

    <div class="context">
        <?php 
if (method_exists("\\Strata\\Strata", "app")) {
    ?>
            <?php 
    $app = Strata::app();
    ?>
            <?php 
    $router = Strata::router();
    ?>
            <h3>Context</h3>
            <?php 
    $controller = null;
    $method = strtoupper($_SERVER['REQUEST_METHOD']);
    if (isset($router)) {
        $controller = $router->getCurrentController();
        $action = $router->getCurrentAction();
    }
    ?>
            <p>[<?php 
    echo $method;
    ?>
] <?php 
    echo WP_HOME . $_SERVER['REQUEST_URI'];
Пример #10
0
 private function raiseDebuggerTakeover()
 {
     $this->hasError = true;
     $this->clearBuffer();
     $router = Strata::router();
     if ($router) {
         $controller = Strata::router()->getCurrentController();
         if (!is_null($controller)) {
             $controller->serverError();
         }
     }
 }