Esempio n. 1
0
 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
 {
     $names = StringTools::Delimit($input->getArgument('name'), ',');
     $user = $input->getArgument('user');
     $group = $input->getArgument('group');
     $parent = $input->getOption('parent');
     // TODO support
     if (!empty($parent)) {
         var_dump($parent);
     }
     foreach ($names as $website) {
         // adding website
         //$website = $name['text'];
         LogCLI::Message('Adding website: ' . $website, 0);
         LogCLI::MessageResult('Group and user: '******'/' . $user, 2, LogCLI::INFO);
         $path = Paths::$db . Paths::$separator . $group . Paths::$separator . $user . Paths::$separator;
         if (file_exists($path)) {
             if (!file_exists($path . $website . '.yml') && Paths::getFullPath($website) === false) {
                 FileOperation::CreateEmptyFile($path . $website . '.yml');
                 LogCLI::Result(LogCLI::OK);
             } else {
                 LogCLI::Fail('Website ' . $website . ', under ' . $group . '/' . $user . ' already exists!');
                 LogCLI::Result(LogCLI::FAIL);
             }
         } else {
             LogCLI::Fail('Group and/or user ' . $group . '/' . $user . ' does not exist!');
             LogCLI::Result(LogCLI::FAIL);
         }
     }
 }
Esempio n. 2
0
 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
 {
     $names = StringTools::TypeList($input->getArgument('name'), '@', ',');
     $userorgroup = $input->getArgument('userorgroup');
     //        $group = $input->getArgument('group');
     //        $group =
     //        $directories = $input->getArgument('directories');
     //        $files = array();
     //ApplicationsDB::LoadAll();
     foreach ($names as $name) {
         if ($name['exclamation'] !== false) {
             // adding user
             LogCLI::MessageResult('Exclamation: ' . $name['exclamation'], 2, LogCLI::INFO);
             $username = $name['text'];
             LogCLI::Message('Adding user: '******'Creating directory: ' . $structure, 2, LogCLI::INFO);
             if (@mkdir($structure, 0755, true)) {
                 LogCLI::Result(LogCLI::OK);
             } else {
                 LogCLI::Result(LogCLI::FAIL);
                 LogCLI::Fail('User ' . $username . ' already exists!');
                 //LogCLI::Fail($e->getMessage());
             }
         } else {
             // adding website
             $website = $name['text'];
             LogCLI::Message('Adding website: ' . $website, 0);
             $username = !empty($userorgroup) ? $userorgroup : Paths::$defaultUser;
             $group = Paths::$defaultGroup;
             LogCLI::MessageResult('User and group: ' . $username . '/' . $group, 2, LogCLI::INFO);
             $path = Paths::$db . Paths::$separator . $group . Paths::$separator . $username . Paths::$separator;
             if (file_exists($path)) {
                 if (!file_exists($path . $website . '.yml') && Paths::getFullPath($website) === false) {
                     FileOperation::CreateEmptyFile($path . $website . '.yml');
                     LogCLI::Result(LogCLI::OK);
                 } else {
                     LogCLI::Result(LogCLI::FAIL);
                     LogCLI::Fail('Website ' . $website . ', under ' . $group . '/' . $username . ' already exists!');
                 }
             } else {
                 LogCLI::Result(LogCLI::FAIL);
                 LogCLI::Fail('Group and/or user ' . $group . '/' . $username . ' does not exist!');
             }
         }
     }
 }
Esempio n. 3
0
 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
 {
     //var_dump($input->getArgument('name'));
     $names = StringTools::Delimit($input->getArgument('name'), ',');
     $group = $input->getArgument('group');
     foreach ($names as $username) {
         // adding user
         //LogCLI::MessageResult('Exclamation: '.$name['exclamation'], 2, LogCLI::INFO);
         //$username = $name['text'];
         LogCLI::Message('Adding user: '******'Creating directory: ' . $structure, 2, LogCLI::INFO);
         if (@mkdir($structure, 0755, true)) {
             LogCLI::Result(LogCLI::OK);
         } else {
             LogCLI::Fail('User ' . $username . ' already exists!');
             LogCLI::Result(LogCLI::FAIL);
         }
     }
 }
Esempio n. 4
0
 public function returnConfig()
 {
     $config = array('output' => null, 'scope' => $this->scope, 'level' => $this->level, 'append' => ';');
     $output = '';
     if ($this->isIterative === true) {
         foreach ($this->params as $element) {
             if (is_array($element)) {
                 foreach ($element as $param) {
                     if (is_array($param)) {
                         //var_dump($param);
                         $config['output'][] = rtrim(StringTools::sprintfn($this->scheme, StringTools::makeList($param)));
                     }
                 }
             }
         }
     } else {
         $config['output'] = rtrim(StringTools::sprintfn($this->scheme, StringTools::makeList($this->params)));
     }
     return $config;
 }
Esempio n. 5
0
 public static function parseStringWithReplacementList($toFormat, array $replacementList, $open = '[', $close = ']', $pattern = '/%\\(([a-zA-Z_]\\w*)\\)/', $ifNoMatchReturnFalse = true)
 {
     $formatArray = SuperStack::StackUp($toFormat, $open, $close);
     $parsed = self::parseArray($formatArray, $replacementList, $pattern, $ifNoMatchReturnFalse);
     return StringTools::rimplode(null, $parsed);
 }
Esempio n. 6
0
 private function parseWithConfig($configuration, $result)
 {
     $output = null;
     foreach ($this->options as $option) {
         /*
          * if there are multiple paths for one setting
          */
         if (is_array($option->path)) {
             foreach ($option->path as $config => $path) {
                 //($setting = ArrayTools::accessArrayElementByPath($configuration, $path)) !== null ?: $setting = $option->default[$config];
                 $setting = ArrayTools::accessArrayElementByPath($configuration, $path);
                 if ($setting === null) {
                     if ($option->default[$config] !== null) {
                         LogCLI::MessageResult('Setting ' . $config . ' not set, defaulting to: ' . $option->default[$config], 7, LogCLI::OK);
                     }
                     $setting = $option->default[$config];
                 }
                 $values[$config] = $setting;
             }
             $this->_dispatchAction($option, $values, $result);
         } else {
             //($setting = ArrayTools::accessArrayElementByPath($configuration, $option->path)) !== null ?: $setting = $option->default;
             $setting = ArrayTools::accessArrayElementByPath($configuration, $option->path);
             if ($setting === null) {
                 $option->setDefaults();
                 if ($option->default !== null) {
                     LogCLI::MessageResult('Setting ' . $option->name . ' not set, defaulting to: ' . $option->default, 7, LogCLI::OK);
                 }
                 $setting = $option->default;
             }
             //var_dump($setting);
             /*
              *  If we got an array, how do we divide it?
              *  By default by ' ' (space), but sometimes we want eg. PHP_EOL, or comma.
              */
             $value = StringTools::makeList($setting, $option->divideBy);
             $this->_dispatchAction($option, $value, $result);
         }
     }
     //foreach(preg_split("/(\r?\n)/", $this->template) as $line)
     foreach (explode(PHP_EOL, $this->template) as $line) {
         //$parsedline = ParseTools::sprintfn($line, $result->options);
         $parsedline = ParseTools::parseStringWithReplacementList($line, $result->options);
         // if all we got is whitespace, don't add it
         if (strlen(rtrim($parsedline)) < 1) {
             continue;
         }
         // if we got a multiline responds we have to indent it
         // TODO: maybe explode "\n" or PHP_EOL would be better?
         //            if(count($lines = preg_split("/(\r?\n)/", $parsedline)) > 1)
         if (count($lines = explode(PHP_EOL, $parsedline)) > 1) {
             $indentedlines = array_shift($lines) . PHP_EOL;
             foreach ($lines as &$multiline) {
                 $indentedlines .= StringTools::indentLinesToMatchOther(trim($line), $line, $multiline) . PHP_EOL;
             }
             $parsedline = rtrim($indentedlines);
         }
         $output .= $parsedline . PHP_EOL;
     }
     return $output;
 }
Esempio n. 7
0
 public static function doParse($toFormat)
 {
     $toFormat = StringTools::removeNewLines($toFormat, true, false);
     return SuperStack::StackUp($toFormat, '{', '}');
 }
Esempio n. 8
0
 public static function Add($arguments)
 {
     foreach (StringTools::TypeList($arguments['name'], '@') as $argument) {
         $name = $argument['text'];
         if ($argument['exclamation'] !== false) {
             LogCLI::MessageResult('Exclamation: ' . $argument['exclamation'], 2, LogCLI::INFO);
             $username = $name;
             LogCLI::Message('Adding user: '******'name2']) ? $arguments['name2'] : Paths::$defaultGroup;
             $structure = Paths::$db . Paths::$separator . $group . Paths::$separator . $username;
             LogCLI::MessageResult('Creating directory: ' . $structure, 2, LogCLI::INFO);
             if (@mkdir($structure, 0755, true)) {
                 LogCLI::Result(LogCLI::OK);
             } else {
                 LogCLI::Result(LogCLI::FAIL);
                 LogCLI::Fail('User ' . $username . ' already exists!');
                 //LogCLI::Fail($e->getMessage());
             }
         } else {
             // adding website
             $website = $name;
             LogCLI::Message('Adding website: ' . $website, 0);
             $username = isset($arguments['name2']) ? $arguments['name2'] : Paths::$defaultUser;
             $group = Paths::$defaultGroup;
             LogCLI::MessageResult('Username and group: ' . $username . '/' . $group, 2, LogCLI::INFO);
             $path = Paths::$db . Paths::$separator . $group . Paths::$separator . $username . Paths::$separator;
             if (file_exists($path)) {
                 if (!file_exists($path . $website . '.yml') && Paths::getFullPath($website) === false) {
                     FileOperation::CreateEmptyFile($path . $website . '.yml');
                     LogCLI::Result(LogCLI::OK);
                 } else {
                     LogCLI::Result(LogCLI::FAIL);
                     LogCLI::Fail('Website ' . $website . ', under ' . $group . '/' . $username . ' already exists!');
                 }
             } else {
                 LogCLI::Result(LogCLI::FAIL);
                 LogCLI::Fail('Group and/or user ' . $group . '/' . $username . ' does not exist!');
             }
         }
     }
 }
Esempio n. 9
0
 public static function findPathForSetting(&$settings, $settingPath, $basicScope = false)
 {
     $searchResults = ArrayTools::TraverseTreeWithPath($settings, $settingPath);
     if (empty($searchResults)) {
         LogCLI::MessageResult(LogCLI::YELLOW . 'Sorry, no settings found for: ' . LogCLI::BLUE . $settingPath . LogCLI::RESET, 0, LogCLI::INFO);
         return false;
     } else {
         if (count($searchResults['all']) > 1) {
             LogCLI::MessageResult(LogCLI::YELLOW . 'Multiple settings found for: ' . LogCLI::BLUE . $settingPath . LogCLI::RESET, 4, LogCLI::INFO);
         }
         LogCLI::MessageResult(LogCLI::GREEN . 'Best match: ' . LogCLI::BLUE . $searchResults['best'] . LogCLI::RESET, 0, LogCLI::INFO);
         $path = $searchResults['best'];
         if ($basicScope !== false) {
             if (($pos = strpos($path, $basicScope)) !== false && $pos === 0) {
                 $path = StringTools::DropLastBit($path, -1);
             }
         }
         $parent = ArrayTools::accessArrayElementByPath($settings, StringTools::DropLastBit($searchResults['best']));
         if (isset($parent['iterative'])) {
             $path = StringTools::DropLastBit($path, -1);
         }
         LogCLI::MessageResult('Fixed path: ' . LogCLI::YELLOW . $searchResults['best'] . ' => ' . LogCLI::BLUE . $path . LogCLI::RESET, 6, LogCLI::INFO);
         return $path;
     }
 }
Esempio n. 10
0
 public function insertScope($child, $parent, $pattern = null, $overrideIndentationTemplate = false)
 {
     if (!isset($pattern)) {
         $pattern =& $this->patterns[$child];
     }
     LogCLI::MessageResult("Inserting: " . LogCLI::BLUE . $child . LogCLI::RESET . " => " . LogCLI::GREEN . $parent . LogCLI::RESET . " (will replace " . LogCLI::YELLOW . $pattern . LogCLI::RESET . ")", 3);
     //TODO: make sure this two IF's never get executed
     if (!isset($this->results[$parent])) {
         LogCLI::MessageResult("Notice: " . LogCLI::YELLOW . 'No such parent' . LogCLI::RESET . " - " . LogCLI::GREEN . $parent, 2);
         $proper_parent = explode('/', $parent);
         //$proper_parent = (isset($proper_parent[2])) ? $proper_parent[2] : $proper_parent[0];
         $proper_parent = end($proper_parent);
         //!is_numeric(end($proper_parent)) ?
         $this->results[$parent] = $this->templates[$proper_parent];
     }
     if (!isset($this->results[$child])) {
         LogCLI::MessageResult("Notice: " . LogCLI::YELLOW . 'No such child' . LogCLI::RESET . " - " . LogCLI::GREEN . $child, 2);
         $proper_child = explode('/', $child);
         //echo "PROPER CHILD: \n";
         //var_dump($proper_child);
         $proper_child = isset($proper_child[2]) ? $proper_child[2] : $proper_child[0];
         $this->results[$child] = $this->templates[$proper_child];
     }
     //var_dump($this->results[$child]);
     if ($overrideIndentationTemplate !== false) {
         return preg_replace(StringTools::regexpify($pattern), trim(StringTools::indentLinesToMatchOther($pattern, $overrideIndentationTemplate, $this->results[$child], 0)), $this->results[$parent]) . PHP_EOL;
     } else {
         return preg_replace(StringTools::regexpify($pattern), trim(StringTools::indentLinesToMatchOther($pattern, $this->templates[$parent], $this->results[$child], 0)), $this->results[$parent]) . PHP_EOL;
     }
 }
Esempio n. 11
0
<?php

/**
 * User: NIXin
 * Date: 24.09.2011
 * Time: 13:02
 */
use Tools\StringTools;
include '../autoload.php';
var_dump(StringTools::TypeList('mambo,@jambo,+camper', array('@')));
Esempio n. 12
0
 public static function doWeReplaceHelper(array $chain)
 {
     $testType = end(StringTools::TypeList(reset($chain), '+', false));
     if ($testType['exclamation'] !== false) {
         return true;
     } else {
         return false;
     }
 }