/**
  * Dispatch a nested URL
  *
  * @param $uri
  *
  * @return string
  */
 protected function _dispatchNestedUrl($uri)
 {
     // if url path is empty, return unchanged
     if (empty($uri[1])) {
         return $uri[0];
     }
     $prefix = '';
     list($path, $append) = Strings::explode('?', $uri[1], [$uri[1], null], 2);
     //Take a root link as it comes
     if (!Strings::startsWith($path, '/')) {
         $relPath = $this->_assetManager->getRelativePath();
         if (Strings::startsWith($path, '../')) {
             $max = count($relPath);
             $depth = substr_count($path, '../');
             $path = substr($path, $depth * 3);
             if ($depth > 0 && $depth < $max) {
                 $rel = array_slice($relPath, 0, $depth);
                 $prefix = implode('/', $rel);
             }
         } else {
             $prefix = implode('/', $relPath);
         }
     }
     $path = ltrim($path, '/');
     $url = $this->_assetManager->getResourceUri(Path::buildUnix($prefix, $path));
     if (empty($url)) {
         return $uri[0];
     }
     if (!empty($append)) {
         return "url('{$url}?{$append}')";
     }
     return "url('{$url}')";
 }
Esempio n. 2
0
 /**
  * @param PdoException $e
  *
  * @return bool
  */
 private function _isRecoverableException(PdoException $e)
 {
     $code = $e->getPrevious()->getCode();
     if ($code === 0 || Strings::startsWith($code, 42)) {
         return false;
     }
     return true;
 }
Esempio n. 3
0
 /**
  * Check a string starts with a specific string
  *
  * @param      $haystack
  * @param      $needle
  * @param bool $case
  *
  * @return bool
  *
  * @deprecated
  */
 function starts_with($haystack, $needle, $case = true)
 {
     return \Packaged\Helpers\Strings::startsWith($haystack, $needle, $case);
 }
Esempio n. 4
0
 /**
  * Prepare the form
  */
 protected function _boot()
 {
     $formDoc = DocBlockParser::fromObject($this->getDataObject());
     $labelPosition = FormElement::LABEL_BEFORE;
     $defaultTags = [];
     foreach ($formDoc->getTags() as $tag => $values) {
         foreach ($values as $value) {
             if (Strings::startsWith($tag, 'element', false)) {
                 $defaultTags[substr($tag, 7)] = $value;
             }
         }
     }
     foreach ($this->_processPublicProperties() as $property) {
         if (isset($this->_elements[$property])) {
             continue;
         }
         static::$_propDocBlocks[$this->_calledClass][$property] = $docblock = DocBlockParser::fromProperty($this->getDataObject(), $property);
         //Setup the type
         $type = $docblock->getTagFailover(["inputType", "type", "input"]);
         if ($type === null) {
             $type = FormElement::calculateType($property);
         }
         //Setup the label
         $label = $docblock->getTag("label");
         if ($label === null) {
             $label = Strings::humanize($property);
         }
         $element = new FormElement($this, $property, $type, $label, $labelPosition);
         foreach ($defaultTags as $tag => $value) {
             $element->processDocBlockTag($tag, $value);
         }
         $element->setDataObject($this->getDataObject(), $property);
         $this->_aliases[$element->getName()] = $property;
         foreach ($docblock->getTags() as $tag => $values) {
             foreach ($values as $value) {
                 $element->processDocBlockTag($tag, $value);
             }
         }
         $this->_elements[$property] = $element;
     }
     if ($this->_enableCsrf) {
         $this->_buildCsrf();
     } else {
         $this->getElement($this->_csrfField)->setRenderer(new FormElementRenderer(''));
     }
 }
Esempio n. 5
0
 /**
  * Is Dispatch responsible for the incoming request
  *
  * @param Request $request
  *
  * @return bool
  */
 public function isDispatchRequest(Request $request)
 {
     $runOn = $this->_config->getItem('run_on', 'path');
     switch ($runOn) {
         case 'path':
             $match = $this->_config->getItem('run_match', 'res');
             return Strings::startsWith($request->getPathInfo() . '/', "/{$match}/");
         case 'subdomain':
             $matchCfg = $this->_config->getItem('run_match', 'static.,assets.');
             $subDomains = ValueAs::arr($matchCfg, ['static.']);
             return Strings::startsWithAny($request->getHost(), $subDomains);
         case 'domain':
             $matchCfg = $this->_config->getItem('run_match', null);
             $domains = ValueAs::arr($matchCfg, []);
             return Strings::endsWithAny($request->getHttpHost(), $domains, false);
     }
     return false;
 }
Esempio n. 6
0
 public function __call($method, $params)
 {
     if (Strings::startsWith($method, 'get')) {
         return $this->_getProperty(substr($method, 3), Arrays::first($params));
     } else {
         throw new \Exception("Method {$method} is not supported");
     }
 }
 public function checkValue($value)
 {
     switch ($this->comparator) {
         case AdvancedFilterComparator::EQUAL:
             $return = $value == $this->value;
             break;
         case AdvancedFilterComparator::NOT_EQUAL:
             $return = $value != $this->value;
             break;
         case AdvancedFilterComparator::EQUAL_INSENSITIVE:
             $return = strcasecmp($value, $this->value) === 0;
             break;
         case AdvancedFilterComparator::NOT_EQUAL_INSENSITIVE:
             $return = strcasecmp($value, $this->value) !== 0;
             break;
         case AdvancedFilterComparator::GREATER_THAN:
             $return = $value > $this->value;
             break;
         case AdvancedFilterComparator::GREATER_THAN_EQUAL:
             $return = $value >= $this->value;
             break;
         case AdvancedFilterComparator::LESS_THAN:
             $return = $value < $this->value;
             break;
         case AdvancedFilterComparator::LESS_THAN_EQUAL:
             $return = $value <= $this->value;
             break;
         case AdvancedFilterComparator::BETWEEN:
             list($min, $max) = explode(',', $this->value);
             $return = $value >= $min && $value <= $max;
             break;
         case AdvancedFilterComparator::NOT_BETWEEN:
             list($min, $max) = explode(',', $this->value);
             $return = !($value >= $min && $value <= $max);
             break;
         case AdvancedFilterComparator::IN:
             $return = Arrays::contains(ValueAs::arr($this->value), $value);
             break;
         case AdvancedFilterComparator::NOT_IN:
             $return = !Arrays::contains(ValueAs::arr($this->value), $value);
             break;
         case AdvancedFilterComparator::LIKE:
             $return = Strings::contains($value, $this->value);
             break;
         case AdvancedFilterComparator::NOT_LIKE:
             $return = !Strings::contains($value, $this->value);
             break;
         case AdvancedFilterComparator::STARTS_WITH:
             $return = Strings::startsWith($value, $this->value);
             break;
         case AdvancedFilterComparator::NOT_STARTS_WITH:
             $return = !Strings::startsWith($value, $this->value);
             break;
         case AdvancedFilterComparator::ENDS_WITH:
             $return = Strings::endsWith($value, $this->value);
             break;
         case AdvancedFilterComparator::NOT_ENDS_WITH:
             $return = !Strings::endsWith($value, $this->value);
             break;
         default:
             throw new \RuntimeException("Comparator " . AdvancedFilterComparator::getDisplayValue($this->comparator) . ' is not currently supported with checkValue');
     }
     return $return;
 }
 protected function _configure()
 {
     $this->_sanetizers['validators']['lower'] = [function ($value) {
         if (strtolower($value) === $value) {
             return true;
         }
         throw new \Exception("Not a lower case string");
     }, function ($value) {
         if (Strings::startsWith($value, 'lower')) {
             return true;
         }
         throw new \Exception("String must start with text 'lower'");
     }];
     $this->_sanetizers['validators']['upper'] = [function ($value) {
         if (Strings::startsWith($value, 'UPPER')) {
             return true;
         }
         throw new \Exception("String must start with text 'UPPER'");
     }];
 }
Esempio n. 9
0
 /**
  * @param CqlException $e
  *
  * @return bool
  */
 private function _isRecoverableException(CqlException $e)
 {
     if ($e->getPrevious() instanceof TTransportException || Strings::startsWith($e->getMessage(), 'TSocketPool: All hosts in pool are down.')) {
         $this->_removeCurrentHost();
         return true;
     }
     if ($e->getPrevious() instanceof InvalidRequestException && Strings::startsWith($e->getMessage(), 'Prepared query with ID')) {
         return true;
     }
     if ($this->_strictRecoverable || $e->getPrevious() instanceof NotFoundException || $e->getPrevious() instanceof InvalidRequestException) {
         return false;
     }
     error_log('Exception As Recoverable: (' . $e->getCode() . ') ' . $e->getMessage());
     return true;
 }
Esempio n. 10
0
 public function assemblePredicateClause(AbstractPredicateClause $clause)
 {
     if (!$clause->hasPredicates()) {
         return '';
     }
     if (count($clause->getPredicates()) === 1 && Arrays::first($clause->getPredicates()) instanceof PredicateSet) {
         $assembled = $this->getAssembler()->assembleSegment(Arrays::first($clause->getPredicates()));
         if (Strings::startsWith($assembled, '(') && Strings::endsWith($assembled, ')')) {
             $assembled = substr($assembled, 1, -1);
         }
         return $clause->getAction() . ' ' . $assembled;
     } else {
         return $clause->getAction() . ' ' . implode($clause->getGlue(), $this->assembleSegments($clause->getPredicates()));
     }
 }
Esempio n. 11
0
 public function testStartsWith()
 {
     $this->assertTrue(Strings::startsWith("abcdef", "ab", true));
     $this->assertTrue(Strings::startsWith("aBcdef", "aB", true));
     $this->assertTrue(Strings::startsWith("abcdef", "aB", false));
     $this->assertTrue(Strings::startsWith("aBcdef", ["cd", 'aB'], true));
     $this->assertFalse(Strings::startsWith("aBcdef", "ab", true));
     $this->assertFalse(Strings::startsWith("aBcdef", "cd", false));
     $this->assertFalse(Strings::startsWith("aBcdef", "cd", true));
 }