Example #1
0
 public static function init($run = true)
 {
     static $console;
     if (!$console) {
         // 实例化console
         $console = new self('Think Console', '0.1');
         // 读取指令集
         if (is_file(CONF_PATH . 'command' . EXT)) {
             $commands = (include CONF_PATH . 'command' . EXT);
             if (is_array($commands)) {
                 foreach ($commands as $command) {
                     if (class_exists($command) && is_subclass_of($command, "\\think\\console\\command\\Command")) {
                         // 注册指令
                         $console->add(new $command());
                     }
                 }
             }
         }
     }
     if ($run) {
         // 运行
         $console->run();
     } else {
         return $console;
     }
 }
Example #2
0
File: GitRepo.php Project: coyl/git
 /**
  * Create a new git repository
  *
  * Accepts a creation path, and, optionally, a source path
  *
  * @access public
  * @param string $repoPath repository path
  * @param string $source directory to source
  * @param bool $remoteSource reference path
  * @param string|null $reference
  * @throws \Exception
  * @return GitRepo
  */
 public static function create($repoPath, $source = null, $remoteSource = false, $reference = null, $commandString = "")
 {
     if (is_dir($repoPath) && file_exists($repoPath . "/.git") && is_dir($repoPath . "/.git")) {
         throw new GitException(sprintf('"%s" is already a git repository', $repoPath));
     } else {
         $repo = new self($repoPath, true, false);
         if (is_string($source)) {
             if ($remoteSource) {
                 if (!is_dir($reference) || !is_dir($reference . '/.git')) {
                     throw new GitException('"' . $reference . '" is not a git repository. Cannot use as reference.');
                 } else {
                     if (strlen($reference)) {
                         $reference = realpath($reference);
                         $reference = "--reference {$reference}";
                     }
                 }
                 $repo->cloneRemote($source, $reference);
             } else {
                 $repo->cloneFrom($source, $commandString);
             }
         } else {
             $repo->run('create');
         }
         return $repo;
     }
 }
Example #3
0
 public static final function exec($data)
 {
     $process = new self();
     $process->run($data);
     Log::info(' === ' . $process->getName() . ' ==== started === ');
     return $process;
 }
Example #4
0
 static function &create_new($repo_path, $gitdir = null, $source = null, $remote_source = false, $reference = null)
 {
     if ($gitdir && is_dir($gitdir) || is_dir($repo_path) && is_dir($repo_path . "/.git")) {
         throw new \Exception('"' . $repo_path . '" is already a git repository');
     } else {
         $repo = new self($repo_path, $gitdir, true, false);
         if (is_string($source)) {
             if ($remote_source) {
                 if (!is_dir($reference) || !is_dir($reference . '/.git')) {
                     throw new \Exception('"' . $reference . '" is not a git repository. Cannot use as reference.', 1);
                 } else {
                     if (strlen($reference)) {
                         $reference = realpath($reference);
                         $reference = "--reference {$reference}";
                     }
                 }
                 $repo->clone_remote($source, $reference);
             } else {
                 $repo->clone_from($source);
             }
         } else {
             $repo->run('init');
         }
         return $repo;
     }
 }
Example #5
0
 public function testNotExistingTestCase()
 {
     $suite = new self('notExistingMethod');
     $suite->run($this->result);
     $this->assertEquals(0, $this->result->errorCount());
     $this->assertEquals(1, $this->result->failureCount());
     $this->assertEquals(1, count($this->result));
 }
Example #6
0
 /**
  * Serves as entry point for this script.
  *
  * It runs several benchmark iteratios.
  *
  * @return void
  */
 public static function classConstructor()
 {
     $cases = array(array(10, 1), array(100, 1), array(1000, 1), array(10000, 1), array(10, 10), array(100, 10), array(1000, 10), array(10000, 10), array(100, 100), array(1000, 100), array(10000, 100), array(1000, 1000), array(10000, 1000), array(10000, 10000));
     foreach ($cases as $case) {
         $benchmark = new self($case[0], $case[1]);
         $benchmark->run();
         echo $benchmark;
     }
 }
Example #7
0
 public static function spawn($cb)
 {
     if (!$cb instanceof \Generator) {
         return;
     }
     $instance = new self($cb);
     $instance->run();
     return $instance;
 }
 public static function main($cwd, array $argv = array())
 {
     try {
         $generator = new self($cwd, $argv);
         return $generator->run();
     } catch (Exception $e) {
         $generator->echoLine($e->getMessage());
         return $e->getCode();
     }
 }
Example #9
0
 /**
  * Shorthand method for inline validation.
  *
  * @param array $data       The data to be validated
  * @param array $validators The GUMP validators
  *
  * @return mixed True(boolean) or the array of error messages
  */
 public static function is_valid(array $data, array $validators)
 {
     $gump = new self();
     $gump->validation_rules($validators);
     if ($gump->run($data) === false) {
         return $gump->get_readable_errors(false);
     } else {
         return true;
     }
 }
Example #10
0
 public static function main()
 {
     if ($cwd = getenv('CURRENT_WORKING_DIRECTORY')) {
         if (!file_exists($cwd)) {
             exit('Invalid CURRENT_WORKING_DIRECTORY');
         }
         chdir($cwd);
     }
     $cliRunner = new self();
     $cliRunner->run();
 }
 /**
  * Shorthand method for inline validation
  *
  * @param array $data The data to be validated
  * @param array $validators The GUMP validators
  * @return mixed True(boolean) or the array of error messages
  */
 public static function is_valid(array $data, array $validators)
 {
     $formBuilder = new self();
     // GumpFormBuilder();
     $formBuilder->form_rules($validators);
     if ($formBuilder->run($data) === false) {
         return $formBuilder->get_readable_errors(false);
     } else {
         return true;
     }
 }
Example #12
0
 public static function main($args)
 {
     if (!$args) {
         throw new Exception('Hippo must be run from command line interface.');
     }
     $environment = new Environment();
     $fileSystem = new FileSystem();
     $configReader = new YAMLConfigReader($fileSystem);
     $checkRepository = new CheckRepository($fileSystem);
     $pathToSelf = array_shift($args);
     $context = new HippoTextUIContext($fileSystem, $args);
     $hippoTextUi = new self($environment, $fileSystem, $checkRepository, $configReader, $pathToSelf, $context);
     $hippoTextUi->run();
 }
Example #13
0
 /**
  * Start
  *
  * @access public
  */
 public static function start()
 {
     if (self::is_running()) {
         throw new \Exception('Transaction daemon is already running');
     }
     $pid = pcntl_fork();
     if ($pid == -1) {
         throw new \Exception('Error while forking');
     } elseif ($pid) {
         file_put_contents(Config::$pid_file, $pid);
         return $pid;
     } else {
         // Child
         $daemon = new self();
         $daemon->run();
     }
 }
Example #14
0
 public static function start($template)
 {
     $ctx = $template->context;
     $loop = $ctx->get('loop');
     $box_id = $ctx->get('box_id');
     if (!$loop) {
         $box = new self($ctx, $box_id);
     } else {
         $obj_var = 'box_obj_' . $box_id;
         if (isset($loop[$obj_var])) {
             $box = $loop[$obj_var];
         } else {
             $box = new self($ctx, $box_id, $loop);
             $loop[$obj_var] = $box;
         }
     }
     $box->run($template);
     return $box;
 }
 public static function main($exit = true)
 {
     $command = new self();
     if (wfIsWindows()) {
         # Windows does not come anymore with ANSI.SYS loaded by default
         # PHPUnit uses the suite.xml parameters to enable/disable colors
         # which can be then forced to be enabled with --colors.
         # The below code inject a parameter just like if the user called
         # phpunit with a --no-color option (which does not exist). It
         # overrides the suite.xml setting.
         # Probably fix bug 29226
         $command->arguments['colors'] = false;
     }
     # Makes MediaWiki PHPUnit directory includable so the PHPUnit will
     # be able to resolve relative files inclusion such as suites/*
     # PHPUnit uses stream_resolve_include_path() internally
     # See bug 32022
     set_include_path(__DIR__ . PATH_SEPARATOR . get_include_path());
     $command->run($_SERVER['argv'], $exit);
 }
Example #16
0
 /**
  * Compress a HTML content
  *
  * @param string $content
  * @param array $tags [optional]
  * @return string
  */
 public static function compress($content, array $tags = null)
 {
     $minifier = new self($content, $tags);
     return $minifier->run();
 }
Example #17
0
 /**
  * Create a new git repository
  *
  * Accepts a creation path, and, optionally, a source path
  *
  * @access  public
  * @param   string  repository path
  * @param   string  directory to source
  * @return  GitRepo
  */
 public static function &create_new($repo_path, $source = null)
 {
     if (is_dir($repo_path) && file_exists($repo_path . "/.git") && is_dir($repo_path . "/.git")) {
         throw new Exception('"' . $repo_path . '" is already a git repository');
     } else {
         $repo = new self($repo_path, true, false);
         if (is_string($source)) {
             $repo->clone_from($source);
         } else {
             $repo->run('init');
         }
         return $repo;
     }
 }
Example #18
0
 /**
  * main()
  *
  * @return void
  */
 public static function main()
 {
     $zf = new self();
     $zf->bootstrap();
     $zf->run();
 }
Example #19
0
 /**
  * @param bool $exit
  * @return int
  */
 public static function main($exit = true)
 {
     $command = new self();
     return $command->run($_SERVER['argv'], $exit);
 }
 /**
  * This function creates a job for to run the SugarJobUpdateOpportunities class
  * @param integer $perJob
  * @returns array|string An array of the jobs that were created, unless there
  * is one, then just that job's id
  */
 public static function updateOpportunitiesForForecasting($perJob = 100)
 {
     $sq = new SugarQuery();
     $sq->select(array('id'));
     $sq->from(BeanFactory::getBean('Opportunities'));
     $sq->orderBy('date_closed');
     $rows = $sq->execute();
     if (empty($rows)) {
         return false;
     }
     $chunks = array_chunk($rows, $perJob);
     $jobs = array();
     // process the first job now
     $job = static::createJob($chunks[0], true);
     $jobs[] = $job->id;
     // run the first job
     $self = new self();
     $self->setJob($job);
     $self->sendNotifications = false;
     $self->run($job->data);
     $job_group = md5(microtime());
     for ($i = 1; $i < count($chunks); $i++) {
         $jobs[] = static::createJob($chunks[$i], false, $job_group);
     }
     // if only one job was created, just return that id
     if (count($jobs) == 1) {
         return array_shift($jobs);
     }
     return $jobs;
 }
Example #21
0
 /**
  * Gets the version of the GnuPG binary
  *
  * @return string a version number string containing the version of GnuPG
  *                being used. This value is suitable to use with PHP's
  *                version_compare() function.
  *
  * @throws Crypt_GPG_Exception if an unknown or unexpected error occurs.
  *         Use the <kbd>debug</kbd> option and file a bug report if these
  *         exceptions occur.
  *
  * @throws Crypt_GPG_UnsupportedException if the provided binary is not
  *         GnuPG or if the GnuPG version is less than 1.0.2.
  */
 public function getVersion()
 {
     if ($this->_version == '') {
         $options = array('homedir' => $this->_homedir, 'binary' => $this->_binary, 'debug' => $this->_debug, 'agent' => $this->_agent);
         $engine = new self($options);
         $info = '';
         // Set a garbage version so we do not end up looking up the version
         // recursively.
         $engine->_version = '1.0.0';
         $engine->reset();
         $engine->setOutput($info);
         $engine->setOperation('--version');
         $engine->run();
         $matches = array();
         $expression = '#gpg \\(GnuPG[A-Za-z0-9/]*?\\) (\\S+)#';
         if (preg_match($expression, $info, $matches) === 1) {
             $this->_version = $matches[1];
         } else {
             throw new Crypt_GPG_Exception('No GnuPG version information provided by the binary "' . $this->_binary . '". Are you sure it is GnuPG?');
         }
         if (version_compare($this->_version, self::MIN_VERSION, 'lt')) {
             throw new Crypt_GPG_Exception('The version of GnuPG being used (' . $this->_version . ') is not supported by Crypt_GPG. The minimum version ' . 'required by Crypt_GPG is ' . self::MIN_VERSION);
         }
     }
     return $this->_version;
 }
Example #22
0
 public static function widget($config = [])
 {
     $class = new self($config);
     return $class->run();
 }
Example #23
0
 /**
  * Minify a string of CSS
  * @param string $css input code
  * @param array $options unused at this point
  * @return string
  */
 public static function _minify($css)
 {
     $obj = new self();
     return $obj->run($css);
 }
 /**
  * Shortcut method
  *
  * @return integer
  */
 public static function autorun()
 {
     $class = new self();
     return $class->run();
 }
Example #25
0
 public static function create(Event $event)
 {
     $creator = new self($event);
     return $creator->run();
 }
Example #26
0
 /**
  * Entry point method. Receives the following arguments from web.php:
  * <ol>
  *   <li>The web root</li>
  *   <li>The configuration directory</li>
  *   <li>The server profile</li>
  *   <li>The script URL</li>
  * </ol>
  *
  * @param   string[] args
  */
 public static function main(array $args)
 {
     $r = new self($args[0], $args[2]);
     $r->configure(new \util\Properties($args[1] . DIRECTORY_SEPARATOR . 'web.ini'));
     $r->run($args[3]);
 }
Example #27
0
 /**
  * @param $dir
  *
  * @return string
  */
 public static function getSize($dir)
 {
     $du = new self($dir);
     $du->setOption('sh');
     return $du->run();
 }
Example #28
0
 /**
  * @param $jobid
  */
 public static function start_cli($jobid)
 {
     if (php_sapi_name() != 'cli') {
         return;
     }
     //define DOING_CRON to prevent caching
     if (!defined('DOING_CRON')) {
         define('DOING_CRON', true);
     }
     //load text domain
     $log_level = get_site_option('backwpup_cfg_loglevel', 'normal_translated');
     if (strstr($log_level, 'translated')) {
         BackWPup::load_text_domain();
     } else {
         add_filter('override_load_textdomain', '__return_true');
         $GLOBALS['l10n'] = array();
     }
     $jobid = absint($jobid);
     //Logs Folder
     $log_folder = get_site_option('backwpup_cfg_logfolder');
     $log_folder = BackWPup_File::get_absolute_path($log_folder);
     //check job id exists
     $jobids = BackWPup_Option::get_job_ids();
     if (!in_array($jobid, $jobids, true)) {
         die(__('Wrong BackWPup JobID', 'backwpup'));
     }
     //check folders
     $log_folder_message = BackWPup_File::check_folder($log_folder);
     if (!empty($log_folder_message)) {
         die($log_folder_message);
     }
     $log_folder_message = BackWPup_File::check_folder(BackWPup::get_plugin_data('TEMP'), true);
     if (!empty($log_folder_message)) {
         die($log_folder_message);
     }
     //check running job
     if (file_exists(BackWPup::get_plugin_data('running_file'))) {
         die(__('A BackWPup job is already running', 'backwpup'));
     }
     //start class
     $backwpup_job_object = new self();
     $backwpup_job_object->create('runcli', (int) $jobid);
     $backwpup_job_object->run();
 }
Example #29
0
 /**
  * Create a new git repository
  *
  * @param   string  $repository_path The repository path
  * @param   string  $source The directory to source
  * @return  mixed
  * @throws  \Exception if the path already exists
  * @throws  \Exception if the path is already a GIT repository
  * @throws  \Exception if the directory can't be created
  */
 public static function createNew($repository_path, $source = null)
 {
     if (file_exists($repository_path) && is_dir($repository_path)) {
         throw new \Exception(sprintf('"%s" already exists!', $repository_path));
     } elseif (file_exists($repository_path) && is_dir($repository_path) && file_exists($repository_path . "/.git") && is_dir($repository_path . "/.git")) {
         throw new \Exception(sprintf('"%s" is already a git repository!', $repository_path));
     } else {
         if (!mkdir($repository_path)) {
             throw new \Exception(sprintf('Can not create directory "%s"!', $repository_path));
         }
         $repo = new self($repository_path, true, false);
         if (is_string($source)) {
             $repo->cloneFrom($source);
         } else {
             $repo->run('init');
         }
         return $repo;
     }
 }
Example #30
0
 public static function runWithDefaults($callback = NULL, $arguments = NULL)
 {
     $runner = new self();
     return $runner->run($callback, $arguments);
 }