diff --git a/boot.php b/boot.php index b655626..cb1032a 100644 --- a/boot.php +++ b/boot.php @@ -10,7 +10,6 @@ */ if (rex::isBackend() && rex::getUser()) { - $providers = \Watson\Foundation\Watson::loadProviders(); if (count($providers)) { diff --git a/lib/Cheatsheet/CheatsheetServiceProvider.php b/lib/Cheatsheet/CheatsheetServiceProvider.php index 7d5b432..8514cf5 100644 --- a/lib/Cheatsheet/CheatsheetServiceProvider.php +++ b/lib/Cheatsheet/CheatsheetServiceProvider.php @@ -8,6 +8,7 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ + namespace Watson\Cheatsheet; use Cheatsheet\Page; @@ -15,13 +16,12 @@ class CheatsheetServiceProvider extends ServiceProvider { - /** * {@inheritdoc} */ public function i18n() { - return __DIR__ . '/lang'; + return __DIR__.'/lang'; } /** @@ -37,6 +37,7 @@ public function page() $subpage = new \rex_be_page('watson', \rex_i18n::msg('watson_cheatsheet_docs_title')); $subpage->setHref(['page' => 'cheatsheet/addoff/watson']); + $subpage->setIcon('watson-icon-logo'); $subpage->setSubPath(\rex_path::addon('watson', 'lib/Cheatsheet/pages/docs.php')); $page->addSubpage($subpage); diff --git a/lib/Cheatsheet/pages/docs.php b/lib/Cheatsheet/pages/docs.php index 5954f87..01967e9 100644 --- a/lib/Cheatsheet/pages/docs.php +++ b/lib/Cheatsheet/pages/docs.php @@ -21,16 +21,14 @@ if (strpos($index, '/') !== false) { $navAttributes['class'][] = 'is-plugin'; } - $nav[] = '' . $label . ''; + $nav[] = ''.$label.''; } $fragment = new rex_fragment(); $fragment->setVar('title', rex_i18n::msg('watson_cheatsheet_docs_title')); -$fragment->setVar('body', '', false); +$fragment->setVar('body', '', false); $sidebar = $fragment->parse('core/page/section.php'); - - if ($requestIndex == 'use') { $body = '
@@ -147,7 +145,6 @@ $fragment->setVar('title', $navigation[$requestIndex]); $fragment->setVar('body', $body, false); $content .= $fragment->parse('core/page/section.php'); - } else { $fragment = new rex_fragment(); $fragment->setVar('title', $navigation[$requestIndex]); @@ -155,10 +152,8 @@ $content .= $fragment->parse('core/page/section.php'); } - - echo '- '; diff --git a/lib/Watson/Foundation/Command.php b/lib/Watson/Foundation/Command.php index d01d84d..f85144b 100644 --- a/lib/Watson/Foundation/Command.php +++ b/lib/Watson/Foundation/Command.php @@ -8,6 +8,7 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ + namespace Watson\Foundation; class Command @@ -15,9 +16,8 @@ class Command private $command; private $command_parts; private $input; - private $arguments = array(); - private $options = array(); - + private $arguments = []; + private $options = []; public function __construct($input) { @@ -27,178 +27,136 @@ public function __construct($input) $this->parseInput(); } - public function parseInput() { $command_parts = $this->command_parts; if (isset($command_parts['0'])) { - $this->command = $command_parts['0']; unset($command_parts[0]); - } - foreach ($command_parts as $name => $value) { - if (0 === strpos($name, '--')) { // Check for an option notation. // Notation: --option="my option" - + $name = substr($name, 2); - - if (empty($name)) { + if (empty($name)) { throw new \Exception('An option name cannot be empty.'); - } $this->options[$name] = $value; - unset($command_parts['--' . $name]); - + unset($command_parts['--'.$name]); } elseif (is_numeric($name) && 0 === strpos($value, '--')) { - // Check for an option notation. // Notation: --option $value = substr($value, 2); - - if (empty($value)) { + if (empty($value)) { throw new \Exception('An option name cannot be empty.'); - } $this->options[$value] = 1; unset($command_parts[$name]); - } } $this->arguments = $command_parts; - } - public function getCommand() { return $this->command; } - - public function getInput() { return $this->input; } - - public function getCommandParts() { return $this->command_parts; } - - public function getCommandPartsAsString() { return implode(' ', $this->getCommandParts()); } - - public function deleteCommandFromCommandParts() { foreach ($this->command_parts as $key => $command_part) { - if ($this->command == $command_part) { - unset($this->command_parts[$key]); - } } } - - public function getArgument($position) { return isset($this->arguments[$position]) ? $this->arguments[$position] : null; } - - public function getArguments() { return $this->arguments; } - - public function getOption($option) { return isset($this->options[$option]) ? $this->options[$option] : null; } - - public function getOptions() { return $this->options; } - - public function getSqlWhere($fields) { - $where = array(); + $where = []; foreach ($fields as $field) { - - $w = array(); + $w = []; foreach ($this->getCommandParts() as $command_part) { - - $w[] = $field . ' LIKE "%' . $command_part . '%"'; - + $w[] = $field.' LIKE "%'.$command_part.'%"'; } - $where[] = '(' . implode(' AND ', $w) . ')'; + $where[] = '('.implode(' AND ', $w).')'; } return implode(' OR ', $where); } - - - - - /** * Splits a string by spaces - * (Strings with quotes will be regarded) + * (Strings with quotes will be regarded). * * Examples: * "a b 'c d'" -> array('a', 'b', 'c d') * "a=1 b='c d'" -> array('a' => 1, 'b' => 'c d') * * @param string $string + * * @return array */ protected function split($string) { $string = trim($string); if (empty($string)) { - return array(); + return []; } - $result = array(); + $result = []; $spacer = '@@@WATSON@@@'; - $quoted = array(); + $quoted = []; - $pattern = '@(["\'])((?:.*[^\\\\])?(?:\\\\\\\\)*)\\1@Us'; + $pattern = '@(["\'])((?:.*[^\\\\])?(?:\\\\\\\\)*)\\1@Us'; $callback = function ($match) use ($spacer, &$quoted) { - $quoted[] = str_replace(array('\\' . $match[1], '\\\\'), array($match[1], '\\'), $match[2]); + $quoted[] = str_replace(['\\'.$match[1], '\\\\'], [$match[1], '\\'], $match[2]); return $spacer; }; $string = preg_replace_callback($pattern, $callback, $string); @@ -218,6 +176,4 @@ protected function split($string) return $result; } - - } diff --git a/lib/Watson/Foundation/Documentation.php b/lib/Watson/Foundation/Documentation.php index dd74f9e..cca32e8 100644 --- a/lib/Watson/Foundation/Documentation.php +++ b/lib/Watson/Foundation/Documentation.php @@ -8,128 +8,83 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -namespace Watson\Foundation; +namespace Watson\Foundation; class Documentation { - private $command; private $examples; private $description; private $options; private $usage; - - - public function __construct($command) { - $this->setCommand($command); - } - - public function setCommand($value) { - $this->command = $value; - } public function getCommand() { - return $this->command; - } - public function setExample($example) { - $this->examples[] = $example; - } - public function setExamples(array $examples) { - foreach ($examples as $example) { - $this->setExample($example); - } - } public function getExamples() { - return $this->examples; - } - - public function setDescription($value) { - $this->description = $value; - } public function getDescription() { - return $this->description; - } - public function setOption($option, $description) { - - $this->options[] = array('option' => $option, 'description' => $description); - + $this->options[] = ['option' => $option, 'description' => $description]; } - public function setOptions(array $options) { - foreach ($options as $option => $option) { - $this->setOption($option, $description); - } - } public function getOptions() { - return $this->options; - } - - public function setUsage($value) { - $this->usage = $value; - } public function getUsage() { - return $this->usage; - } - } diff --git a/lib/Watson/Foundation/Extension.php b/lib/Watson/Foundation/Extension.php index 699ed63..d6a2081 100644 --- a/lib/Watson/Foundation/Extension.php +++ b/lib/Watson/Foundation/Extension.php @@ -11,9 +11,6 @@ namespace Watson\Foundation; -use Watson\Foundation\Command; -use Watson\Foundation\Watson; - class Extension { public static function head(\rex_extension_point $ep) @@ -25,18 +22,18 @@ public static function head(\rex_extension_point $ep) 'quicklookHotkey' => Watson::getQuicklookHotkey(), 'backend' => true, 'backendUrl' => \rex_url::backendPage('watson', [], false), - 'backendRemoteUrl' => \rex_url::backendPage('watson', ['watson_query' => ''], false) . '%QUERY', + 'backendRemoteUrl' => \rex_url::backendPage('watson', ['watson_query' => ''], false).'%QUERY', 'wildcard' => '%QUERY', ] ); if ($js_properties) { - $ep->setSubject($ep->getSubject() . "\n" . ' + $ep->setSubject($ep->getSubject()."\n".' ' @@ -62,12 +59,12 @@ public static function agent(\rex_extension_point $ep) - + '; $panel .= ''; - $ep->setSubject(str_replace(' -' . $content . '+ +'.$content.'