Example #1
0
 public static function startWith($haystack, $needle)
 {
     if (!\UString::isStartWith($haystack, $needle)) {
         $haystack = $needle . $haystack;
     }
     return $haystack;
 }
Example #2
0
 protected function initialize()
 {
     parent::initialize();
     if (\UString::isStartWith($this->title, '(')) {
         \UString::doSubstrAfter($this->title, '(');
         $this->preTitle = \UString::substrBefore($this->title, ')');
         \UString::doSubstrAfter($this->title, ')');
     }
 }
Example #3
0
 public function is_redirection($url)
 {
     foreach (headers_list() as $header) {
         if (\UString::isStartWith($header, 'Location: ' . $url)) {
             return TRUE;
         }
     }
     return FALSE;
 }
Example #4
0
 public function execute($arguments = array())
 {
     if (empty($this->request)) {
         throw new \Stack\Exception\Database('The SQL request is empty.');
     }
     $result = [];
     try {
         // Prepare the request
         $this->connect();
         $statement = $this->PDObject->prepare($this->request);
         foreach ($arguments as $parameter => $value) {
             $statement->bindValue($parameter, $value);
         }
         $result = $statement->execute();
         // Execute the request
         if (!$result) {
             throw new \Stack\Exception\Database('Error with the SQL request : ' . $this->request, $statement->errorInfo());
         }
         if (\UString::isStartWith($this->request, ['SELECT', 'SHOW', 'DESCRIBE', 'EXPLAIN'])) {
             $result = $statement->fetchAll(\PDO::FETCH_ASSOC);
         } else {
             if (\UString::isStartWith($this->request, "INSERT")) {
                 $result = TRUE;
                 $id = $this->PDObject->lastInsertId();
                 if ($id == '0') {
                     // Error Case or a table without autoincrementation
                     $id = FALSE;
                     $result = FALSE;
                 }
                 $this->lastInsertId = $id;
             }
         }
     } catch (PDOException $exception) {
         throw new \Stack\Exception\Database($exception->getMessage());
     }
     $this->disconnect();
     return $result;
 }
Example #5
0
 public function bySetting($controller, $action, $setting)
 {
     if (!\UString::isStartWith($action, 'action')) {
         $action = 'action' . ucfirst($action);
     }
     $callable = [$controller, $action];
     if (!is_callable($callable)) {
         $message = get_class($controller) . '::' . $action . ' is not callable';
         throw new \Stack\Exception\NoCallable($message);
     }
     $uri = NULL;
     $exceptions = [];
     $aliases = [];
     if (is_array($setting)) {
         $uri = isset($setting['uri']) ? $setting['uri'] : $uri;
         $exceptions = isset($setting['exceptions']) ? $setting['exceptions'] : $exceptions;
         $aliases = isset($setting['aliases']) ? $setting['aliases'] : $aliases;
     } else {
         if (is_string($setting)) {
             $uri = $setting;
         }
     }
     return new $this($callable, $uri, $exceptions, $aliases);
 }
Example #6
0
 protected function findExtensionPath($namespace)
 {
     foreach ($this->namespaces as $baseNamespace => $basePathList) {
         if (\UString::isStartWith($namespace, $baseNamespace)) {
             \UArray::doConvertToArray($basePathList);
             foreach ($basePathList as $basePath) {
                 \UString::doEndWith($basePath, DIRECTORY_SEPARATOR);
                 \UString::doNotStartWith($namespace, $baseNamespace);
                 \UString::doNotStartWith($namespace, '\\');
                 $path = str_replace('\\', DIRECTORY_SEPARATOR, $namespace);
                 $path = $basePath . $path;
                 if (is_dir($path)) {
                     return $path;
                 }
             }
         }
     }
 }
Example #7
0
 public function test_is_start_with__multiple_no_match()
 {
     $test = \UString::isStartWith('Ubiq is so cool', array('Java', '.NET'));
     $this->assertFalse($test);
 }
Example #8
0
 public function match($url)
 {
     return (is_null($this->host) || $this->host === $url->host) && (is_null($this->port) || $this->port === $url->port) && (is_null($this->uri) || \UString::isStartWith($url->uri, $this->uri));
 }
Example #9
0
 protected function rewriteJsonValues(&$values)
 {
     if (is_array($values)) {
         foreach ($values as $key => &$value) {
             if (!is_array($value) && \UString::isStartWith($value, array('[', '{'))) {
                 $json = preg_replace(array('/([\\[\\]\\{\\}:,])\\s*(\\w)/', '/(\\w)\\s*([\\[\\]\\{\\}:,])/'), '\\1"\\2', $value);
                 $array = json_decode($json, TRUE);
                 if ($array !== FALSE) {
                     $value = $array;
                 }
             }
             $this->rewriteJsonValues($value);
         }
     }
 }
Example #10
0
 public static function getAbsoluteUrl($url)
 {
     if (\UString::isStartWith($url, '/')) {
         $url = 'http://' . $_SERVER['HTTP_HOST'] . $url;
     }
     return $url;
 }