コード例 #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
ファイル: FormHelper.php プロジェクト: francoisfaubert/strata
 /**
  * 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);
 }
コード例 #3
0
 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
ファイル: Controller.php プロジェクト: francoisfaubert/strata
 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
ファイル: View.php プロジェクト: francoisfaubert/strata
 /**
  * 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);
 }
コード例 #8
0
 /**
  * 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
ファイル: error.php プロジェクト: francoisfaubert/strata
    ?>
            </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();
         }
     }
 }