Permalink
Browse files

Removed console tool

- Obsolete, as all modules now use ZF2 console tooling
  • Loading branch information...
1 parent 8d121b5 commit e82667998cba8d69d61d8033b9c16cb624d91796 @weierophinney committed Sep 26, 2012
Showing with 0 additions and 169 deletions.
  1. +0 −26 README
  2. +0 −143 console
View
@@ -3,29 +3,3 @@ PURPOSE
This is the code behind mwop.net. One part of its purpose is to demonstrate
the capabilities of Zend Framework 2.
-
-In order to run this code, you will need:
-
- * mongo running on your server or elsewhere
- * ext/mongo for PHP
- * A Google search API key
- * A ReCaptcha API key
- * A registered Disqus site
- * Some way to send mail, and the configuration necessary to do so
-
-To configure the application, copy modules/Local/configs/module.config.php.dist
-to modules/Local/configs/module.config.php, and edit it to supply the
-configuration values and/or DI substitutions you desire.
-
-To post entries to the blog, you will need to setup an API key. This is simply a
-file containing a string; you indicate its location in the Local configuration
-file. Once configured, you will need to ensure this key is also available from
-any machine that will post to it. To create a post, you will need a
-configuration file that defines two values, "apikey" (the value of the API key
-on the server to which you are posting) and "url" (the URL to the server and
-blog resource). Then, follow the instructions in modules/Blog/bin/post.php, and
-invoke that script using:
-
- ./console Blog:post -c "path/to/config/file" -p "path/to/post/file"
-
-This will take the entry you've created and post it to the server.
View
@@ -1,143 +0,0 @@
-#!/usr/bin/env php
-<?php
-/**
- * Console tool for invoking mwop.net scripts
- *
- * Usage:
- *
- * console [--global-options] Module:script [--script-options]
- *
- * where "Module" is a module name, and "script" is a script found in that
- * module's "bin" directory, minus the ".php" suffix. Example:
- *
- * console Blog:post -c config.file -p post.file
- *
- * It then executes the requested script in the given environment, and within
- * the same execution session.
- */
-
-use Zend\Mvc\Service;
-use Zend\ServiceManager\ServiceManager;
-
-chdir(__DIR__);
-
-ini_set("display_errors", true);
-error_reporting(E_ALL | E_STRICT);
-define('MWOP_CONSOLE', true);
-
-// Setup autoloading
-include_once 'vendor/autoload.php';
-
-// Setup getopt rules
-$rules = array(
- 'help|h' => 'Console usage message (this message)',
-);
-
-if (2 > $argc) {
- $message = "Too few arguments.\n";
- try {
- $opt = new Zend\Console\Getopt($rules);
- $message .= $opt->getUsageMessage();
- } catch (Zend\Console\Exception $e) {
- $message .= $e->getUsageMessage();
- }
- usage($message, 1);
-}
-
-$consoleArgs = array();
-$breakFound = false;
-$scriptFound = false;
-for ($i = 1; $i <= $argc; $i++) {
- if (!isset($argv[$i])) {
- break;
- }
- $value = $argv[$i];
- if ('--' == $value) {
- $breakFound = true;
- break;
- }
- if (strstr($value, ':')) {
- $scriptFound = true;
- break;
- }
-}
-if (!$breakFound && !$scriptFound) {
- $message = "No script argument provided.\n";
- try {
- $opt = new Zend\Console\Getopt($rules);
- $message .= $opt->getUsageMessage();
- } catch (Zend\Console\Exception $e) {
- $message .= $e->getUsageMessage();
- }
- usage($message, 1);
-}
-$consoleArgs = array_slice($argv, 1, $i - 1);
-$scriptArgs = array_slice($argv, $i);
-
-try {
- $opt = new Zend\Console\Getopt($rules, $consoleArgs);
-} catch (Zend\Console\Exception $e) {
- $message = "Error parsing arguments.\n";
- $message .= $e->getUsageMessage();
- usage($message, 1);
-}
-
-if ($opt->getOption('h')) {
- usage($opt->getUsageMessage(), 1);
-}
-
-if ($breakFound) {
- array_shift($scriptArgs);
- $keys = array_keys($scriptArgs);
- $firstKey = array_shift($keys);
- $first = $scriptArgs[$firstKey];
- if (!strstr($first, ':')) {
- $message = "Missing command argument\n";
- $message .= $opt->getUsageMessage();
- usage($message, 1);
- }
- unset($keys, $firstKey, $first);
-}
-$scriptArg = array_shift($scriptArgs);
-list($module, $script) = explode(':', $scriptArg, 2);
-
-// Initialize application
-// Need to allow overriding services so we can override the various places the
-// console substitutes itself
-$config = include 'config/application.config.php';
-$smConfig = isset($config['service_manager']) ? $config['service_manager'] : array();
-$services = new ServiceManager(new Service\ServiceManagerConfig($smConfig));
-$services->setService('ApplicationConfig', $config);
-$services->setAllowOverride(true);
-$moduleManager = $services->get('ModuleManager');
-$moduleManager->loadModules();
-$application = $services->get('Application')->bootstrap();
-$services->setAllowOverride(false);
-
-// Determine what modules are present
-$loadedModules = $moduleManager->getLoadedModules();
-if (!isset($loadedModules[$module])) {
- usage("Module '$module' not found; cannot execute script\n", 1);
-}
-$moduleClass = $loadedModules[$module];
-$r = new ReflectionObject($moduleClass);
-$scriptPath = dirname($r->getFileName()) . '/bin/' . $script . '.php';
-$argv = $scriptArgs;
-
-// Cleanup before execution: unset variables
-unset(
- $rules, $opt, $consoleArgs, $breakFound, $scriptFound, $i, $value,
- $scriptArgs, $module, $script, $appConfig, $loadedModules,
- $moduleClass, $r
-);
-
-include $scriptPath;
-exit(0);
-
-function usage($message, $exit = 1)
-{
- echo "Console tool:\n";
- echo "console [options] Module:script [options]\n\n";
- echo $message;
- exit($exit);
-}

0 comments on commit e826679

Please sign in to comment.