Esempio n. 1
0
 /**
  * @param $file
  * @return array
  */
 public function uploadScreenShot3($file)
 {
     $name = Str::random() . '.' . strtolower($file->ext);
     $image = new Image($file->image);
     $image->saveAs(PATH_PUBLIC . '/images/' . $name, 100);
     return array('UploadScreenShot3Result' => $image->getUrl());
 }
Esempio n. 2
0
 /**
  * Render empty role rows.
  *
  * @param array $roles
  * @return string
  */
 public function emptyRoleRows($roles = [])
 {
     $html = [];
     foreach ($roles as $role) {
         $html[] = $this->Html->tag('td', null, ['class' => 'aro-lb-' . Str::low($role)]);
     }
     return implode('', $html);
 }
Esempio n. 3
0
File: Html.php Progetto: JBZoo/Html
 /**
  * Pimple callback register render.
  *
  * @param $render
  * @param string $ns
  * @return \Closure
  */
 private static function _register($render, $ns)
 {
     return function () use($render, $ns) {
         $render = Str::clean($render);
         $render = implode('\\', array($ns, Html::RENDER_DIR, ucfirst($render)));
         return new $render();
     };
 }
Esempio n. 4
0
 /**
  * Create iframe.
  *
  * @param string $src
  * @param string $class
  * @param string $id
  * @param array $attrs
  * @return string
  */
 public function render($src, $class = '', $id = '', array $attrs = array())
 {
     $attrs = array_merge(array('frameborder' => 0, 'content' => null, 'tag' => 'iframe', 'src' => Str::trim($src)), $attrs);
     $attrs = $this->_cleanAttrs($attrs);
     $content = $attrs['content'];
     unset($attrs['content']);
     return Html::_('tag')->render($content, Str::trim($class), Str::trim($id), $attrs);
 }
Esempio n. 5
0
 /**
  * Reload default template.
  *
  * @param string $name
  * @param string $value
  * @param string $id
  * @param string $text
  * @param array $attrs
  * @return string
  */
 protected function _elementTpl($name, $value = '', $id = '', $text = '', array $attrs = array())
 {
     $alias = Str::slug($value, true);
     $inpClass = 'jb-val-' . $alias;
     $input = $this->input($name, $value, $id, $inpClass, $attrs);
     $text = '<span class="label-title">' . $text . '</span>';
     $html = $this->label($id, $alias, $input . $text);
     return '<div class="jb-input jb-checkbox">' . $html . '</div>';
 }
Esempio n. 6
0
 /**
  * @return string
  */
 protected function _getResultFile()
 {
     // Normalize relative path
     $relPath = Slug::filter($this->_hash, '_');
     $relPath = Str::low($relPath);
     // Gett full clean path
     $fullPath = FS::real($this->_options->get('cache_path')) . '/' . $relPath . '.css';
     $fullPath = FS::clean($fullPath);
     return $fullPath;
 }
Esempio n. 7
0
 /**
  * {@inheritdoc}
  */
 public function load(array $filters = [])
 {
     $source = Str::trim($this->_source, true);
     if (stripos($source, '<style') === 0) {
         if (preg_match('#<style.*?>(.*?)</style>#ius', $source, $matches)) {
             $source = $matches[1];
         }
     }
     return [$this->_type, $source];
 }
Esempio n. 8
0
 /**
  * Output content.
  *
  * @param string $name
  * @param array $attrs
  * @param int $checked
  * @param bool|true $isLblWrap
  * @return string
  */
 public function render($name, $checked = 0, array $attrs = array(), $isLblWrap = true)
 {
     $this->_type = Str::low($this->_type);
     if ($this->_type === 'radio') {
         $options = array(0 => $this->_translate('No'), 1 => $this->_translate('Yes'));
         return Html::_('radio')->render($options, $name, $checked, $attrs, $isLblWrap);
     } elseif ($this->_type === 'checkbox') {
         $options = array(1 => $this->_translate('Yes'));
         return Html::_('checkbox')->render($options, $name, $checked, $attrs, $isLblWrap);
     }
 }
Esempio n. 9
0
 /**
  * Clear string classes.
  *
  * @param string $classes
  * @return string
  */
 protected function _clearClasses($classes)
 {
     $newClasses = [];
     $details = explode(' ', $classes);
     foreach ($details as $class) {
         if (empty($class)) {
             continue;
         }
         $newClasses[] = Str::slug(Str::clean($class));
     }
     return implode(' ', $newClasses);
 }
Esempio n. 10
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 . '');
     }
 }
Esempio n. 11
0
 /**
  * Test radio list output.
  *
  * return void
  */
 public function testRadio()
 {
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     $html = $this->radio->render(array('val-1', 'val-2', 'val-3'), 'test', array(), array(), true);
     $expected = array(array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-0'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 0, 'class' => 'jb-val-0')), ' val-1', '/label', array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-1'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 1, 'class' => 'jb-val-1')), ' val-2', '/label', array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-2'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 2, 'class' => 'jb-val-2')), ' val-3', '/label');
     isHtml($expected, $html);
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     //  Test data and checked single option by array.
     $html = $this->radio->render(array('<p>tag</p>' => 'Tag', ' ' => 'Empty', '"Test label 3"' => 'Custom', 'значение' => 'Translate cyrillic value', 'common' => 'Common label'), 'test', array('common'), array(), true);
     $expected = array(array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-lt-p-gt-tag-lt-p-gt'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => '&lt;p&gt;tag&lt;/p&gt;', 'class' => 'jb-val-lt-p-gt-tag-lt-p-gt')), ' Tag', '/label', array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => ' ', 'class' => 'jb-val-')), ' Empty', '/label', array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-quot-test-label-3-quot'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => '&quot;Test label 3&quot;', 'class' => 'jb-val-quot-test-label-3-quot')), ' Custom', '/label', array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-znachenie'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'значение', 'class' => 'jb-val-znachenie')), ' Translate cyrillic value', '/label', array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-common'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'common', 'class' => 'jb-val-common', 'checked' => 'checked')), ' Common label', '/label');
     isHtml($expected, $html);
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     //  Test checked single option by string.
     $html = $this->radio->render(array('"Test label 3"' => 'Custom', 'значение' => 'Translate cyrillic value', 'common' => 'Common label'), 'test', 'common', array(), true);
     $expected = array(array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-quot-test-label-3-quot'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => '&quot;Test label 3&quot;', 'class' => 'jb-val-quot-test-label-3-quot')), ' Custom', '/label', array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-znachenie'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'значение', 'class' => 'jb-val-znachenie')), ' Translate cyrillic value', '/label', array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-common'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'common', 'class' => 'jb-val-common', 'checked' => 'checked')), ' Common label', '/label');
     isHtml($expected, $html);
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     $html = $this->radio->render(array('test-7' => 'Test label 7', 'test-8' => 'Test label 8'), 'test', array('common', 'test-8', 'test-2', 'test-4'));
     $expected = array(array('input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'no-exits', 'class' => 'jb-val-no-exits', 'checked' => 'checked')), array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-no-exits')), 'No exits', '/label', array('input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'test-7', 'class' => 'jb-val-test-7')), array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-test-7')), 'Test label 7', '/label', array('input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'test-8', 'class' => 'jb-val-test-8')), array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-test-8')), 'Test label 8', '/label');
     isHtml($expected, $html);
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     $html = $this->radio->render(array('test-7' => 'Test label 7', 'test-8' => 'Test label 8'), 'test', 'test');
     $expected = array(array('input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'no-exits', 'class' => 'jb-val-no-exits', 'checked' => 'checked')), array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-no-exits')), 'No exits', '/label', array('input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'test-7', 'class' => 'jb-val-test-7')), array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-test-7')), 'Test label 7', '/label', array('input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'test-8', 'class' => 'jb-val-test-8')), array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-test-8')), 'Test label 8', '/label');
     isHtml($expected, $html);
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     //  Test checked options by array.
     $html = $this->radio->render(array('test-1' => 'Test label 1', 'test-2' => 'Test label 2', 'test-3' => 'Test label 3', 'test-4' => 'Test label 4', 'test-6' => 'Test label 6', 'test-7' => 'Test label 7', 'test-8' => 'Test label 8', 'common' => 'Common label'), 'test', array('common', 'test-8', 'test-2', 'test-4'), array(), true);
     $expected = array(array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-test-1'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'test-1', 'class' => 'jb-val-test-1')), ' Test label 1', '/label', array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-test-2'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'test-2', 'class' => 'jb-val-test-2')), ' Test label 2', '/label', array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-test-3'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'test-3', 'class' => 'jb-val-test-3')), ' Test label 3', '/label', array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-test-4'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'test-4', 'class' => 'jb-val-test-4', 'checked' => 'checked')), ' Test label 4', '/label', array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-test-6'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'test-6', 'class' => 'jb-val-test-6')), ' Test label 6', '/label', array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-test-7'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'test-7', 'class' => 'jb-val-test-7')), ' Test label 7', '/label', array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-test-8'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'test-8', 'class' => 'jb-val-test-8')), ' Test label 8', '/label', array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-common'), 'input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'common', 'class' => 'jb-val-common')), ' Common label', '/label');
     isHtml($expected, $html);
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     //  Test setup callable template.
     $options = array('test-1' => 'Test label 1');
     $html = $this->radio->render($options, 'test', 0, array(), function ($list, $name, $value, $id, $text, $attrs) {
         $alias = Str::slug($value, true);
         $inpClass = 'jb-val-' . $alias;
         $input = $list->input($name, $value, $id, $inpClass, $attrs);
         $text = '<span class="label-title">' . $text . '</span>';
         $label = $list->label($id, $alias, $text);
         return implode(PHP_EOL, array($input, $label));
     });
     $expected = array(array('input' => array('id' => 'preg:/radio-[0-9]+/', 'name' => 'test', 'type' => 'radio', 'value' => 'test-1', 'class' => 'jb-val-test-1', 'checked' => 'checked')), array('label' => array('for' => 'preg:/radio-[0-9]+/', 'class' => 'jb-radio-lbl jb-label-test-1')), 'span' => array('class' => 'label-title'), 'Test label 1', '/span', '/label');
     isHtml($expected, $html);
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     $html = $this->radio->render($options, 'test', 0, array(), 'no-exits');
     isEmpty($html);
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     $inputReload = Html::_('checkbox', 'Custom\\Html');
     $html = $inputReload->render($options, 'test');
     $expected = array('div' => array('class' => 'jb-input jb-checkbox'), 'label' => array('for' => 'preg:/checkbox-[0-9]+/', 'class' => 'jb-checkbox-lbl jb-label-test-1'), array('input' => array('id' => 'preg:/checkbox-[0-9]+/', 'name' => 'test', 'type' => 'checkbox', 'value' => 'test-1', 'class' => 'jb-val-test-1')), 'span' => array('class' => 'label-title'), 'Test label 1', '/span', '/label', '/div');
     isHtml($expected, $html);
 }
Esempio n. 12
0
File: Image.php Progetto: JBZoo/Html
 /**
  * Create img tag.
  *
  * @param string $src
  * @param string|array $class
  * @param string $id
  * @param array $attrs
  * @return string
  */
 public function render($src, $class = '', $id = '', array $attrs = array())
 {
     $attrs['class'] = false;
     $attrs = array_merge(array('fullUrl' => true), $attrs);
     $attrs['id'] = $id;
     $attrs = $this->_normalizeClassAttr($attrs, $this->_jbSrt('image'));
     if ($class !== '') {
         $attrs = $this->_normalizeClassAttr($attrs, $class);
     }
     $attrs['class'] = Str::clean($attrs['class']);
     $isFull = $attrs['fullUrl'];
     unset($attrs['fullUrl']);
     $src = FS::clean($src, '/');
     $attrs['src'] = $isFull ? Url::root() . '/' . $src : $src;
     return '<img ' . $this->buildAttrs($attrs) . ' />';
 }
Esempio n. 13
0
 /**
  * Find theme path.
  *
  * @param string $name
  * @return null|string
  */
 protected static function _find($name)
 {
     $paths = App::path('Plugin');
     foreach ($paths as $path) {
         $path = FS::clean($path . '/', DS);
         $details = explode(DS, rtrim($path, DS));
         $folder = Str::trim(array_pop($details));
         $themeFolder = $path . $name;
         if (Arr::in($folder, self::$_skipFolder) || !FS::isDir($themeFolder)) {
             $themeFolder .= self::POSTFIX;
         }
         if (FS::isDir($themeFolder)) {
             return $themeFolder;
         }
     }
     return null;
 }
Esempio n. 14
0
 public function testSlugCache()
 {
     $_this = $this;
     runBench(array('Str::slug(2, false)' => function () use($_this) {
         return Str::slug($_this->getRandomString(2), false);
     }, 'Str::slug(2, true)' => function () use($_this) {
         return Str::slug($_this->getRandomString(2), true);
     }, 'Slug::filter(2)' => function () use($_this) {
         return Slug::filter($_this->getRandomString(2));
     }, 'Str::slug(3, false)' => function () use($_this) {
         return Str::slug($_this->getRandomString(3), false);
     }, 'Str::slug(3, true)' => function () use($_this) {
         return Str::slug($_this->getRandomString(3), true);
     }, 'Slug::filter(3)' => function () use($_this) {
         return Slug::filter($_this->getRandomString(3));
     }, 'Str::slug(4, false)' => function () use($_this) {
         return Str::slug($_this->getRandomString(4), false);
     }, 'Str::slug(4, true)' => function () use($_this) {
         return Str::slug($_this->getRandomString(4), true);
     }, 'Slug::filter(4)' => function () use($_this) {
         return Slug::filter($_this->getRandomString(4));
     }), array('count' => 1000, 'name' => 'Random slug'));
 }
Esempio n. 15
0
 /**
  * Get select options.
  *
  * @param array $options
  * @param array $selected
  * @param bool|false $isMultiple
  * @return string
  */
 protected function _getOptions(array $options, array $selected = array(), $isMultiple = false)
 {
     $output = array();
     list($options, $_selected) = $this->_checkNoSelected($options, $selected, $isMultiple);
     foreach ($options as $key => $data) {
         $label = $data;
         $value = $key;
         $classes = implode(' ', array($this->_jbSrt('option'), $this->_jbSrt('option-' . Str::slug($value, true))));
         $isSelected = $this->_isSelected($value, $_selected);
         if (is_array($data)) {
             $output[] = $this->_createGroup($key, $data, $_selected, $options);
         } else {
             $output[] = $this->_option($value, $isSelected, $classes, $label);
         }
     }
     return implode(PHP_EOL, $output);
 }
Esempio n. 16
0
 /**
  * CSS compressing.
  *
  * @param string $code
  * @param string $cacheId
  * @return string
  */
 protected function _minify($code, $cacheId)
 {
     $code = (string) $code;
     // remove comments
     $code = preg_replace('#/\\*[^*]*\\*+([^/][^*]*\\*+)*/#ius', '', $code);
     $code = str_replace(["\r\n", "\r", "\n", "\t", '  ', '    ', ' {', '{ ', ' }', '; ', ';;', ';;;', ';;;;', ';}'], ['', '', '', '', '', '', '{', '{', '}', ';', ';', ';', ';', '}'], $code);
     // remove tabs, spaces, newlines, etc.
     // remove spaces after and before colons
     $code = preg_replace('#([a-z\\-])(:\\s*|\\s*:\\s*|\\s*:)#ius', '$1:', $code);
     // spaces before "!important"
     $code = preg_replace('#(\\s*\\!important)#ius', '!important', $code);
     $code = Str::trim($code);
     return implode('', [$cacheId, $code]);
 }
 /**
  * @param string $input
  * @return mixed|string
  */
 protected function camelCase2Human($input)
 {
     return Str::testName2Human($input);
 }
Esempio n. 18
0
 /**
  * Create buttons.
  *
  * @param string $type
  * @param string $title
  * @param array $options
  * @return $this
  */
 protected function _createBtn($type, $title, array $options = [])
 {
     $jsQuery = Str::low($this->_controller) . '.' . Str::low($type);
     $options['onclick'] = "\$(this).UnionToolBarSubmit('" . $jsQuery . "');";
     if ($this->_checkBtn($type)) {
         $this->_tools[$type] = $this->Button->{$type}($title, $options);
     }
     return $this;
 }
Esempio n. 19
0
 public function test()
 {
     $queries = Str::splitSql('SELECT * FROM #__foo;SELECT * FROM #__bar;');
     isSame(array('SELECT * FROM #__foo;', 'SELECT * FROM #__bar;'), $queries);
     $queries = Str::splitSql('
         ALTER TABLE `#__redirect_links` DROP INDEX `idx_link_old`;
         -- Some comment
         ALTER TABLE `#__redirect_links` MODIFY `old_url` VARCHAR(2048) NOT NULL;
         -- Some comment
         -- Some comment --
         ALTER TABLE `#__redirect_links` MODIFY `new_url` VARCHAR(2048) NOT NULL;
         -- Some comment
         ALTER TABLE `#__redirect_links` MODIFY `referer` VARCHAR(2048) NOT NULL;
         
         ALTER TABLE `#__redirect_links` ADD INDEX `idx_old_url` (`old_url`(100));
     ');
     isSame(array('ALTER TABLE `#__redirect_links` DROP INDEX `idx_link_old`;', 'ALTER TABLE `#__redirect_links` MODIFY `old_url` VARCHAR(2048) NOT NULL;', 'ALTER TABLE `#__redirect_links` MODIFY `new_url` VARCHAR(2048) NOT NULL;', 'ALTER TABLE `#__redirect_links` MODIFY `referer` VARCHAR(2048) NOT NULL;', 'ALTER TABLE `#__redirect_links` ADD INDEX `idx_old_url` (`old_url`(100));'), $queries);
 }
Esempio n. 20
0
 /**
  * Parse lines to assoc list
  *
  * @param $input
  * @return string
  */
 public static function parseLines($input)
 {
     if (is_array($input)) {
         $input = implode(PHP_EOL, $input);
     }
     return Str::parseLines($input, true);
 }
Esempio n. 21
0
 /**
  * @param null|string $testName
  * @return string
  */
 protected function _getPrefix($testName = null)
 {
     if (null === $testName) {
         $objects = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT);
         foreach ($objects as $object) {
             if (isset($object['object']) && $object['object'] instanceof \PHPUnit_Framework_TestCase) {
                 $testName = $object['class'] . '_' . $object['function'];
                 break;
             }
         }
     }
     $testName = str_replace(__NAMESPACE__ . '\\', '', $testName);
     $testName = Str::splitCamelCase($testName, '_', true);
     $testName = preg_replace('/^test_/', '', $testName);
     $testName = preg_replace('/_test$/', '', $testName);
     $testName = str_replace('_test_test_', '_', $testName);
     $testName = str_replace(array('/', '\\', '_', '-'), '', $testName);
     $testName = strtolower($testName);
     if (!$testName) {
         $testName = uniqid('', true);
         $testName = str_replace('.', '', $testName);
     }
     return $testName;
 }
Esempio n. 22
0
 /**
  * Single element template output.
  *
  * @param string $name
  * @param string $value
  * @param string $id
  * @param string $text
  * @param array $attrs
  * @return mixed|null|string
  */
 protected function _elementTpl($name, $value = '', $id = '', $text = '', array $attrs = array())
 {
     $alias = Str::slug($value, true);
     $inpClass = $this->_jbSrt('val-' . $alias);
     $input = $this->input($name, $value, $id, $inpClass, $attrs);
     if ($this->_tpl === 'default') {
         return $input . $this->label($id, $alias, $text);
     } elseif ($this->_tpl === 'wrap') {
         return $this->label($id, $alias, $input . ' ' . $text);
     }
     if (is_callable($this->_tpl)) {
         return call_user_func($this->_tpl, $this, $name, $value, $id, $text, $attrs);
     }
     return null;
 }
Esempio n. 23
0
 /**
  * Get plugin name by alias.
  *
  * @param $plugin
  * @return string
  */
 public static function getNameByAlias($plugin)
 {
     $plugin = Str::trim((string) Inflector::camelize($plugin));
     if (strpos($plugin, '-')) {
         $_details = [];
         $details = explode('-', $plugin);
         foreach ($details as $detail) {
             $_details[] = (string) Inflector::camelize($detail);
         }
         $plugin = implode('/', $_details);
     }
     if (strpos($plugin, '_')) {
         return Inflector::camelize($plugin);
     }
     return $plugin;
 }
Esempio n. 24
0
 /**
  * Get request by classes.
  *
  * @param string|array $classes
  * @return string
  */
 public function requestClasses($classes = [])
 {
     $request = $this->request;
     $class = ['view-' . Str::low($request->param('controller')), 'action-' . Str::low($request->param('action'))];
     if ($plugin = $request->param('plugin')) {
         $plugin = Inflector::slug($plugin);
         $class[] = 'plg-' . Str::low($plugin);
     }
     return implode(' ', array_merge($class, (array) $classes));
 }
Esempio n. 25
0
 /**
  * @return string
  */
 protected function _getItemsAppCategory()
 {
     $app = Str::trim($this->_config->find('params.application', 1));
     $cat = Str::trim($this->_config->find('params.category', '-1'));
     return $app . ':' . $cat;
 }
Esempio n. 26
0
 /**
  * Clean and validate HTTP-method type
  *
  * @param string $method
  * @return string
  * @throws Exception
  */
 protected function _getMethod($method)
 {
     $method = trim(Str::up($method));
     $validList = array(self::METHOD_GET, self::METHOD_POST, self::METHOD_HEAD, self::METHOD_PUT, self::METHOD_DELETE, self::METHOD_OPTIONS, self::METHOD_PATCH);
     if (Arr::in($method, $validList)) {
         return $method;
     } else {
         throw new Exception('Unsupported Request Method: ' . $method);
     }
 }