Exemplo n.º 1
0
 /**
  * Validates whether the current user is authorized.
  *
  * @return true|WP_Error
  */
 public function authorized()
 {
     // if the rule is public, always authorized
     if ('public' === $this->options['rule']) {
         return true;
     }
     // enable passing in callback
     if ('callback' === $this->options['rule'] && is_callable($this->options['callback'])) {
         return call_user_func($this->options['callback']);
     }
     // map rule to method
     if (method_exists($this, $method = Str::camel($this->options['rule']))) {
         return $this->{$method}();
     }
     // disable in rule is misconfigused
     // @todo set up internal translations
     // @todo also, this error message kinda sucks
     return new WP_Error('500', __('Guard failure', 'jaxion'));
 }
Exemplo n.º 2
0
 /**
  * Sets the endpoint's prefix.
  *
  * @param string $prefix
  *
  * @return $this
  * @throws MalformedRouteException
  */
 public function set_prefix($prefix)
 {
     if (!Str::starts_with($prefix, '/') || Str::ends_with($prefix, '/')) {
         throw new MalformedRouteException();
     }
     $this->prefix = $prefix;
     return $this;
 }
Exemplo n.º 3
0
 /**
  * Checks whether the attribute has a map method.
  *
  * This is used to determine whether the attribute maps to a
  * property on the underlying WP_Post object. Returns the
  * method if one exists, returns false if it doesn't.
  *
  * @param string $name
  *
  * @return false|string
  */
 protected function hasMapMethod($name)
 {
     $method = 'map' . Str::studly($name);
     if (method_exists($this, $method)) {
         return $method;
     }
     return false;
 }