/**
  * static task getter
  * 
  * @param  string $_type
  * @param  array $_requestOptions
  * @param  array $_taskOptions
  * @return Tinebase_Scheduler_Task
  */
 public static function getPreparedTask($_type, array $_requestOptions, array $_taskOptions = array())
 {
     $request = new Zend_Controller_Request_Simple();
     $request->setControllerName($_requestOptions['controller']);
     $request->setActionName($_requestOptions['action']);
     if (isset($_requestOptions['params']) || array_key_exists('params', $_requestOptions)) {
         foreach ($_requestOptions['params'] as $key => $value) {
             $request->setParam($key, $value);
         }
     }
     $task = new Tinebase_Scheduler_Task($_taskOptions);
     $task->setMonths("Jan-Dec");
     $task->setWeekdays("Sun-Sat");
     $task->setDays("1-31");
     $task->setRequest($request);
     switch ($_type) {
         case self::TASK_TYPE_MINUTELY:
             $task->setHours("0-23");
             $task->setMinutes("0/1");
             break;
         case self::TASK_TYPE_HOURLY:
             $task->setHours("0-23");
             $task->setMinutes("0");
             break;
         case self::TASK_TYPE_DAILY:
             $task->setHours("0");
             $task->setMinutes("0");
             break;
     }
     return $task;
 }
 public function routeStartup(Zend_Controller_Request_Abstract $request)
 {
     try {
         $opts = new Zend_Console_Getopt(array('controller|c=s' => 'Name of the controller to open', 'action|a=s' => 'The command line action to execute', 'cityId|ci=i' => 'City id to get trend data for', 'startDate|sd=s' => 'Start date for the price trends', 'endDate|ed=s' => 'End date for the price trends', 'hours|h=i' => 'How many hours to simulate for'));
         $opts->parse();
         $args = $opts->getRemainingArgs();
         if (!isset($opts->action)) {
             throw new Zend_Console_Getopt_Exception('Action parameter missing');
         }
         $cliAction = $opts->action;
         $cliController = $opts->controller;
         $paramters = array();
         $optArray = $opts->toArray();
         for ($i = 0; $i < count($optArray); $i += 2) {
             $paramters[$optArray[$i]] = $optArray[$i + 1];
         }
     } catch (Zend_Console_Getopt_Exception $e) {
         echo $opts->getUsageMessage();
         exit;
     }
     // set the request as a CLI request
     $request = new Zend_Controller_Request_Simple($cliAction, $cliController, 'cli');
     foreach ($paramters as $key => $paramVal) {
         $request->setParam($key, $paramVal);
     }
     foreach ($args as $argument) {
         $request->setParam($argument, true);
     }
     $response = new Zend_Controller_Response_Cli();
     $front = Zend_Controller_Front::getInstance();
     $front->setRequest($request)->setResponse($response);
 }
 /**
  * @group ZF-3472
  */
 public function testSettingParamToNullInSetparamsCorrectlyUnsetsValue()
 {
     $request = new Zend_Controller_Request_Simple();
     $request->setParam('key', 'value');
     $request->setParams(array('key' => null));
     $this->assertNull($request->getParam('key'));
 }
Exemple #4
0
 public function testSimpleReqestRetainsValuesPassedFromConstructor()
 {
     $request = new Zend_Controller_Request_Simple('test1', 'test2', 'test3', array('test4' => 'test5'));
     $this->assertEquals($request->getActionName(), 'test1');
     $this->assertEquals($request->getControllerName(), 'test2');
     $this->assertEquals($request->getModuleName(), 'test3');
     $this->assertEquals($request->getParam('test4'), 'test5');
 }
 public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
 {
     $stack = $this->getStack();
     // category menu
     $categoryRequest = new Zend_Controller_Request_Simple();
     $categoryRequest->setModuleName('storefront')->setControllerName('category')->setActionName('index')->setParam('responseSegment', 'categoryMain');
     // push requests into the stack
     $stack->pushStack($categoryRequest);
 }
Exemple #6
0
 public function routeShutdown(Zend_Controller_Request_Abstract $request)
 {
     $stack = $this->getStack();
     // category menu
     $categoryRequest = new Zend_Controller_Request_Simple();
     $categoryRequest->setModuleName('wenda')->setControllerName('category')->setActionName('menu')->setParam('responseSegment', 'categoryMain');
     // push requests into the stack
     $stack->pushStack($categoryRequest);
 }
Exemple #7
0
 public function testMagicCallProxiesToRepositoryMethod()
 {
     $model = new Waf_Model();
     $model->register();
     $model->setEntityManager(new Waf_Zend_Controller_Action_Helper_RepositoryTest_TestEntityManager());
     $request = new Zend_Controller_Request_Simple();
     $request->setControllerName('test');
     $request->setModuleName('default');
     Zend_Controller_Front::getInstance()->setRequest($request);
     $this->assertType('Waf_Zend_Controller_Action_Helper_RepositoryTest_TestRepository', $this->repositoryHelper->testMagicCall());
 }
 /**
  * Tests if a task can be saved.
  */
 public function testSaveTask()
 {
     $this->testClearQueue();
     $request = new Zend_Controller_Request_Simple();
     $request->setControllerName('Tinebase_Alarm');
     $request->setActionName('sendPendingAlarms');
     $request->setParam('eventName', 'Tinebase_Event_Async_Minutely');
     $task = Zend_Scheduler_Task::getTask()->setMonths("Jan-Dec")->setWeekdays("Sun-Sat")->setDays("1-31")->setHours("0-23")->setMinutes("0/1")->setRequest($request);
     $this->_scheduler->addTask('Tinebase_Alarm_Test', $task);
     $this->_scheduler->saveTask();
     $tasks = $this->_scheduler->getBackend()->loadQueue();
     $this->assertEquals(1, count($tasks));
 }
Exemple #9
0
    {
    }
    public function route(Zend_Controller_Request_Abstract $dispatcher)
    {
    }
}
try {
    $opts = new Zend_Console_Getopt(array('help|h' => 'Displays usage information.', 'action|a=s' => 'Action to perform in format of module.controller.action', 'verbose|v' => 'Verbose messages will be dumped to the default output.', 'development|d' => 'Enables development mode.'));
    $opts->parse();
} catch (Zend_Console_Getopt_Exception $e) {
    exit($e->getMessage() . "\n\n" . $e->getUsageMessage());
}
if (isset($opts->h)) {
    echo $opts->getUsageMessage();
    exit;
}
if (isset($opts->a)) {
    $reqRoute = array_reverse(explode('::', $opts->a));
    @(list($action, $controller) = $reqRoute);
    $request = new Zend_Controller_Request_Simple();
    $request->setControllerName($controller);
    $request->setActionName($action);
    $request->setModuleName('default');
    $front = Zend_Controller_Front::getInstance();
    $front->setRequest($request);
    $front->setRouter(new RouterCli());
    $front->setResponse(new Zend_Controller_Response_Cli());
    $front->throwExceptions(true);
    $front->addModuleDirectory(APPLICATION_PATH . '/modules/');
    $front->dispatch();
}
 public function testLoadClassLoadsControllerInDefaultModuleWithModulePrefixWhenRequested()
 {
     Zend_Controller_Front::getInstance()
         ->setDispatcher($this->_dispatcher)
         ->addModuleDirectory(dirname(__FILE__) . '/../_files/modules');
     $this->_dispatcher->setDefaultModule('foo')
                       ->setParam('prefixDefaultModule', true);
     $request = new Zend_Controller_Request_Simple();
     $request->setControllerName('index');
     $class = $this->_dispatcher->getControllerClass($request);
     $this->assertEquals('IndexController', $class);
     $test = $this->_dispatcher->loadClass($class);
     $this->assertEquals('Foo_IndexController', $test);
     $this->assertTrue(class_exists($test));
 }
 public function __call($method, $args)
 {
     if ($method == 'isXmlHttpRequest') {
         throw new exception('test testAjaxContextIsRequestDependent failed');
     }
     return parent::__call($method, $args);
 }
 public function testPassingRequestToActionToStackPushesRequestToPluginStack()
 {
     $helper = new Zend_Controller_Action_Helper_ActionStack();
     $plugin = $this->front->getPlugin('Zend_Controller_Plugin_ActionStack');
     $request = new Zend_Controller_Request_Simple();
     $request->setModuleName('foo')->setControllerName('bar')->setActionName('baz');
     $helper->actionToStack($request);
     $next = $plugin->popStack();
     $this->assertTrue($next instanceof Zend_Controller_Request_Abstract);
     $this->assertEquals($request->getModuleName(), $next->getModuleName());
     $this->assertEquals($request->getControllerName(), $next->getControllerName());
     $this->assertEquals($request->getActionName(), $next->getActionName());
     $this->assertFalse($next->isDispatched());
 }
 /**
  * @group ZF-8041
  */
 public function testPostDispatchDoesNotRenderLayoutWhenResponseRedirected()
 {
     $front = Zend_Controller_Front::getInstance();
     $request = new Zend_Controller_Request_Simple();
     $response = new Zend_Controller_Response_Cli();
     $request->setDispatched(true);
     $response->setHttpResponseCode(302);
     $response->setBody('Application content');
     $front->setRequest($request)->setResponse($response);
     $layout = Zend_Layout::startMvc();
     $layout->setLayoutPath(dirname(__FILE__) . '/_files/layouts')->setLayout('plugin.phtml')->setMvcSuccessfulActionOnly(false)->disableInflector();
     $plugin = $front->getPlugin('Zend_Layout_Controller_Plugin_Layout');
     $plugin->setResponse($response);
     $plugin->postDispatch($request);
     $body = $response->getBody();
     $this->assertContains('Application content', $body);
     $this->assertNotContains('Site Layout', $body);
 }
Exemple #14
0
 public function testPostDispatchDoesNothingWithExistingForwardRequest()
 {
     $plugin = new Zend_Controller_Plugin_ActionStack();
     $request = new Zend_Controller_Request_Simple();
     $request->setDispatched(false);
     $plugin->setRequest($request);
     $request1 = new Zend_Controller_Request_Simple();
     $request2 = new Zend_Controller_Request_Simple();
     $request3 = new Zend_Controller_Request_Simple();
     $plugin->pushStack($request1)->pushStack($request2)->pushStack($request3);
     $plugin->postDispatch($request);
     $stack = $plugin->getStack();
     $this->assertEquals(3, count($stack));
 }
Exemple #15
0
    }
    public function route(Zend_Controller_Request_Abstract $dispatcher)
    {
    }
}
set_exception_handler('cli_exception_handler');
// Process our action
if (isset($opts->a)) {
    // Load up our route and get our variables
    $request_actions = explode(':', $opts->a);
    // Reverse our request actions in order to easily skip checking for a default module
    // if it is not present, as the $module variable will be null and Zend will assume
    // the default module.
    $request_route = array_reverse($request_actions);
    @(list($action, $controller, $module) = $request_route);
    $request = new Zend_Controller_Request_Simple($action, $controller, $module);
    // Parse and add any other params into the request
    if (isset($opts->p)) {
        $output = array();
        parse_str($opts->p, $output);
        $request->setParams($output);
    }
    $front = Zend_Controller_Front::getInstance();
    $front->setRequest($request);
    $front->addModuleDirectory(APPLICATION_PATH);
    $front->setRouter(new XSync_Controller_Router_Cli());
    $front->setResponse(new Zend_Controller_Response_Cli());
    $front->throwExceptions(true);
    $front->dispatch();
    exit(0);
}
Exemple #16
0
 /**
  * update to 3.8
  * - schedulers
  */
 public function update_7()
 {
     $declaration = new Setup_Backend_Schema_Table_Xml('
      <table>
         <name>scheduler</name>
         <version>1</version>
         <declaration>
             <field>
                 <name>id</name>
                 <type>integer</type>
                 <length>11</length>
                 <autoincrement>true</autoincrement>
                 <notnull>true</notnull>
             </field>
             <field>
                 <name>name</name>
                 <type>text</type>
                 <length>255</length>
                 <notnull>true</notnull>
             </field>
             <field>
                 <name>data</name>
                 <type>text</type>
                 <notnull>true</notnull>
             </field>
             <index>
                 <name>id</name>
                 <primary>true</primary>
                 <field>
                     <name>id</name>
                 </field>
             </index>
         </declaration>
     </table>');
     try {
         $this->_backend->createTable($declaration);
         Tinebase_Application::getInstance()->addApplicationTable(Tinebase_Application::getInstance()->getApplicationByName('Tinebase'), 'scheduler', 1);
     } catch (Zend_Db_Statement_Exception $zdse) {
         // do nothing
     }
     $request = new Zend_Controller_Request_Simple();
     $request->setControllerName('Tinebase_Alarm');
     $request->setActionName('sendPendingAlarms');
     $request->setParam('eventName', 'Tinebase_Event_Async_Minutely');
     $task = new Tinebase_Scheduler_Task();
     $task->setMonths("Jan-Dec");
     $task->setWeekdays("Sun-Sat");
     $task->setDays("1-31");
     $task->setHours("0-23");
     $task->setMinutes("0/1");
     $task->setRequest($request);
     $scheduler = Tinebase_Core::getScheduler();
     $scheduler->addTask('Tinebase_Alarm', $task);
     $scheduler->saveTask();
     $this->setApplicationVersion('Tinebase', '3.8');
 }
Exemple #17
0
 public function __construct()
 {
     parent::__construct('index', 'index');
 }
 /**
  * @see ZF-2887
  */
 public function testGetControllerClassThrowsExceptionIfNoDefaultModuleDefined()
 {
     $this->_dispatcher->setControllerDirectory(array());
     $request = new Zend_Controller_Request_Simple();
     $request->setControllerName('empty');
     try {
         $class = $this->_dispatcher->getControllerClass($request);
     } catch (Zend_Controller_Exception $e) {
         $this->assertContains('No default module', $e->getMessage());
     }
 }
Exemple #19
0
 public function __construct($a, $c, $m)
 {
     parent::__construct($a, $c, $m);
 }
    $opts->parse();
} catch (Zend_Console_Getopt_Exception $e) {
    exit($e->getMessage() . "\n\n" . $e->getUsageMessage());
}
//mostra o help
if (isset($opts->h)) {
    echo $opts->getUsageMessage();
    exit;
}
//monta a requisição
if (isset($opts->a)) {
    //separa os componentes
    $reqRoute = explode('/', $opts->a);
    $module = array_shift($reqRoute);
    $controller = array_shift($reqRoute);
    $action = array_shift($reqRoute);
    $request = new Zend_Controller_Request_Simple($action, $controller, $module);
    //trata os parâmetros, caso existam
    $argc = count($reqRoute);
    for ($i = 0; $i < $argc; $i++) {
        $request->setParam($reqRoute[$i], $reqRoute[++$i]);
    }
    $front = Zend_Controller_Front::getInstance();
    $front->setRequest($request);
    $front->setRouter(new Coderockr_Controller_Router_Cli());
    $front->setResponse(new Zend_Controller_Response_Cli());
    $front->throwExceptions(true);
    $front->addModuleDirectory(MODULE_CONTROLLER_PATH);
    //Zend_Debug::dump($request->getParams());
    $front->dispatch();
}