Skip to content

Commit

Permalink
CS
Browse files Browse the repository at this point in the history
  • Loading branch information
tbaddade committed Oct 28, 2018
1 parent ec61636 commit 6fe73dd
Show file tree
Hide file tree
Showing 33 changed files with 515 additions and 747 deletions.
1 change: 0 additions & 1 deletion boot.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*/

if (rex::isBackend() && rex::getUser()) {

$providers = \Watson\Foundation\Watson::loadProviders();

if (count($providers)) {
Expand Down
5 changes: 3 additions & 2 deletions lib/Cheatsheet/CheatsheetServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
* 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;
use Cheatsheet\Support\ServiceProvider;

class CheatsheetServiceProvider extends ServiceProvider
{

/**
* {@inheritdoc}
*/
public function i18n()
{
return __DIR__ . '/lang';
return __DIR__.'/lang';
}

/**
Expand All @@ -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);

Expand Down
13 changes: 4 additions & 9 deletions lib/Cheatsheet/pages/docs.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@
if (strpos($index, '/') !== false) {
$navAttributes['class'][] = 'is-plugin';
}
$nav[] = '<a' . rex_string::buildAttributes($navAttributes) . '>' . $label . '</a>';
$nav[] = '<a'.rex_string::buildAttributes($navAttributes).'>'.$label.'</a>';
}

$fragment = new rex_fragment();
$fragment->setVar('title', rex_i18n::msg('watson_cheatsheet_docs_title'));
$fragment->setVar('body', '<nav class="cheatsheet-docs-navigation"><ul><li>' . implode('</li><li>', $nav) . '</li></ul></nav>', false);
$fragment->setVar('body', '<nav class="cheatsheet-docs-navigation"><ul><li>'.implode('</li><li>', $nav).'</li></ul></nav>', false);
$sidebar = $fragment->parse('core/page/section.php');



if ($requestIndex == 'use') {
$body = '
<blockquote>
Expand Down Expand Up @@ -147,18 +145,15 @@
$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]);
$fragment->setVar('body', \rex_markdown::factory()->parse(\rex_file::get(\rex_path::addon('watson', 'README.md'))), false);
$content .= $fragment->parse('core/page/section.php');
}



echo '
<section class="cheatsheet-docs">
<div class="cheatsheet-docs-sidebar">' . $sidebar . '</div>
<div class="cheatsheet-docs-content">' . $content . '</div>
<div class="cheatsheet-docs-sidebar">'.$sidebar.'</div>
<div class="cheatsheet-docs-content">'.$content.'</div>
</section>';
80 changes: 18 additions & 62 deletions lib/Watson/Foundation/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Watson\Foundation;

class Command
{
private $command;
private $command_parts;
private $input;
private $arguments = array();
private $options = array();

private $arguments = [];
private $options = [];

public function __construct($input)
{
Expand All @@ -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);
Expand All @@ -218,6 +176,4 @@ protected function split($string)

return $result;
}


}
Loading

0 comments on commit 6fe73dd

Please sign in to comment.