sub() public static method

Get part of string
public static sub ( string $string, integer $start, integer $length ) : string
$string string
$start integer
$length integer
return string
Ejemplo n.º 1
0
 public function migrate()
 {
     try {
         $this->isOk();
         if (isset($this->params['auto'])) {
             print "Auto mode selected." . PHP_EOL;
             $params = new OdaPrepareReqSql();
             $params->sql = "SELECT `param_value`\n                    FROM `" . self::$config->BD_ENGINE->prefixTable . "api_tab_parametres`\n                    WHERE 1=1\n                    AND `param_name` = 'install_date'\n                ";
             $params->typeSQL = OdaLibBd::SQL_GET_ONE;
             $retour = $this->BD_ENGINE->reqODASQL($params);
             if ($retour->data) {
                 $installDate = $retour->data->param_value;
                 $compressInstallDate = Filter::int(Str::sub($installDate, 2, 2) . Str::sub($installDate, 5, 2) . Str::sub($installDate, 8, 2));
                 print "Install date is: " . $installDate . PHP_EOL;
                 $objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator('.' . DIRECTORY_SEPARATOR, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST);
                 foreach ($objects as $folderPath => $object) {
                     if ($object->isDir()) {
                         $filePath = $folderPath . DIRECTORY_SEPARATOR . 'do.sql';
                         if (file_exists($filePath)) {
                             $banned_words = "-install -reworkModel -matrixRangApi";
                             if (!preg_match('~\\b(' . str_replace(' ', '|', $banned_words) . ')\\b~', $filePath) && preg_match('/[0-9]{2}(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])/', $filePath)) {
                                 $patchDate = Filter::int(Str::sub($filePath, 6, 6));
                                 if ($patchDate > $compressInstallDate) {
                                     $this->exe($filePath);
                                 }
                             }
                         }
                     }
                 }
             } else {
                 print "No install_date retrieve." . PHP_EOL;
             }
         } else {
             print "Target mode selected." . PHP_EOL;
             if ($this->params['partial'] !== "all") {
                 $this->exe('.' . DIRECTORY_SEPARATOR . $this->params['target'] . DIRECTORY_SEPARATOR . $this->params['partial'] . DIRECTORY_SEPARATOR . $this->params['option'] . '.sql');
             } else {
                 $objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator('.' . DIRECTORY_SEPARATOR . $this->params['target'], \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST);
                 foreach ($objects as $name => $object) {
                     if ($object->isDir()) {
                         $this->exe($name . DIRECTORY_SEPARATOR . $this->params['option'] . '.sql');
                     }
                 }
             }
         }
         echo 'Success' . PHP_EOL;
         return $this;
     } catch (Exception $ex) {
         die($ex . '');
     }
 }
Ejemplo n.º 2
0
 public function testMBString()
 {
     isSame(Str::isMBString(), function_exists('mb_strtoupper'));
     isSame(Str::isOverload(), (int) ini_get('mbstring.func_overload') & MB_OVERLOAD_STRING);
     is(5, Str::len('Денис'));
     isSame(1, Str::pos('Денис', 'е'));
     isSame(false, Str::pos('Денис', 'Е'));
     isSame(3, Str::rpos('Денис', 'и'));
     isSame(1, Str::ipos('Денис', 'Е'));
     isSame(1, Str::ipos('Денис', 'Е'));
     isSame('енис', Str::strstr('Денис', 'е'));
     isSame('енис', Str::istr('Денис', 'Е'));
     isSame('ис', Str::rchr('Денис', 'и'));
     isSame('нис', Str::sub('Денис', 2));
     isSame('ени', Str::sub('Денис', 1, 3));
     isSame('денис', Str::low('ДЕНИС'));
     isSame('ДЕНИС', Str::up('денис'));
     isSame(2, Str::subCount('денис ДеНИС', 'е'));
     isSame(1, Str::subCount('денис ДеНИС', 'И'));
     isTrue(Str::isStart('денис', 'ден', true));
     isTrue(Str::isStart('денис', 'ДЕН', false));
     isFalse(Str::isStart('денис', 'ДЕН', true));
     isTrue(Str::isEnd('денис', 'нис', true));
     isTrue(Str::isEnd('денис', 'НИС', false));
     isFalse(Str::isEnd('денис', 'ДЕНИС', true));
 }