コード例 #1
0
ファイル: Initializer.php プロジェクト: ngukho/ducbui-cms
 /**
  * Constructor
  *
  * Initialize environment, root path, and configuration.
  *
  * @param  string      $env
  * @param  string|null $root
  * @return void
  */
 public function __construct()
 {
     // Get front controller instance
     $this->_front = Zend_Controller_Front::getInstance();
     // Get request object
     $this->_request = $this->_front->getRequest();
 }
コード例 #2
0
ファイル: Rest.php プロジェクト: vrtulka23/daiquiri
 /**
  * Matches a user submitted path with parts defined by a map. Assigns and
  * returns an array of variables on a successful match.
  *
  * @param string $path Path used to match against this routing map
  * @return array|false An array of assigned values or a false on a mismatch
  */
 public function match($path, $partial = false)
 {
     $return = parent::match($path, $partial);
     // add the RESTful action mapping
     if ($return) {
         //add the data that is a wildcard to the end of the return array
         $path = trim($path, self::URI_DELIMITER);
         $this->_route = trim($this->_route, self::URI_DELIMITER);
         if ($path != '') {
             $elementsPath = explode(self::URI_DELIMITER, $path);
         }
         if ($this->_route != '') {
             $elementsRoute = explode(self::URI_DELIMITER, $this->_route);
         }
         //and now get rid of all entries that are not a wildcard. when we have done that,
         //we have what we wanted...
         foreach ($elementsRoute as $key => $value) {
             if ($value !== "*") {
                 array_shift($elementsPath);
             } else {
                 break;
             }
         }
         $i = 0;
         foreach ($elementsPath as $value) {
             $return['wild' . $i] = $value;
             $i++;
         }
         //reset things
         $request = $this->_front->getRequest();
         $params = $request->getParams();
         $path = $elementsPath;
         //Store path count for method mapping
         $pathElementCount = count($path);
         // Determine Action
         $requestMethod = strtolower($request->getMethod());
         if ($requestMethod != 'get') {
             if ($request->getParam('_method')) {
                 $return[$this->_actionKey] = strtolower($request->getParam('_method'));
             } elseif ($request->getHeader('X-HTTP-Method-Override')) {
                 $return[$this->_actionKey] = strtolower($request->getHeader('X-HTTP-Method-Override'));
             } else {
                 $return[$this->_actionKey] = $requestMethod;
             }
         } else {
             // this is only an index call, if no options are acutally provided
             if ($pathElementCount > 0) {
                 $return[$this->_actionKey] = 'get';
             } else {
                 $return[$this->_actionKey] = 'index';
             }
         }
     }
     return $return;
 }
コード例 #3
0
 /**
  * Matches a user submitted path with parts defined by a map. Assigns and
  * returns an array of variables on a successful match.
  *
  * @param string $path Path used to match against this routing map
  * @return array|false An array of assigned values or a false on a mismatch
  */
 public function match($path, $partial = false)
 {
     $return = parent::match($path, $partial);
     // add the RESTful action mapping
     if ($return) {
         $request = $this->_front->getRequest();
         $path = $request->getPathInfo();
         $params = $request->getParams();
         $path = trim($path, self::URI_DELIMITER);
         if ($path != '') {
             $path = explode(self::URI_DELIMITER, $path);
         }
         //Store path count for method mapping
         $pathElementCount = count($path);
         // Determine Action
         $requestMethod = strtolower($request->getMethod());
         if ($requestMethod != 'get') {
             if ($request->getParam('_method')) {
                 $return[$this->_actionKey] = strtolower($request->getParam('_method'));
             } elseif ($request->getHeader('X-HTTP-Method-Override')) {
                 $return[$this->_actionKey] = strtolower($request->getHeader('X-HTTP-Method-Override'));
             } else {
                 $return[$this->_actionKey] = $requestMethod;
             }
             // Map PUT and POST to actual create/update actions
             // based on parameter count (posting to resource or collection)
             switch ($return[$this->_actionKey]) {
                 case 'post':
                     if ($pathElementCount > 0) {
                         $return[$this->_actionKey] = 'put';
                     } else {
                         $return[$this->_actionKey] = 'post';
                     }
                     break;
                 case 'put':
                     $return[$this->_actionKey] = 'put';
                     break;
             }
         } else {
             // if the last argument in the path is a numeric value, consider this request a GET of an item
             $lastParam = array_pop($path);
             if (is_numeric($lastParam)) {
                 $return[$this->_actionKey] = 'get';
             } else {
                 $return[$this->_actionKey] = 'index';
             }
         }
     }
     return $return;
 }
コード例 #4
0
 /**
  * Assembles user submitted parameters forming a URL path defined by this route
  *
  * @param array $data An array of variable and value pairs used as parameters
  * @param bool $reset Weither to reset the current params
  * @param bool $encode Weither to return urlencoded string
  * @return string Route path with user submitted parameters
  */
 public function assemble($data = array(), $reset = false, $encode = true)
 {
     if (!$this->_keysSet) {
         if (null === $this->_request) {
             $this->_request = $this->_front->getRequest();
         }
         $this->_setRequestKeys();
     }
     $params = !$reset ? $this->_values : array();
     foreach ($data as $key => $value) {
         if ($value !== null) {
             $params[$key] = $value;
         } elseif (isset($params[$key])) {
             unset($params[$key]);
         }
     }
     $params += $this->_defaults;
     $url = '';
     if ($this->_moduleValid || array_key_exists($this->_moduleKey, $data)) {
         if ($params[$this->_moduleKey] != $this->_defaults[$this->_moduleKey]) {
             $module = $params[$this->_moduleKey];
         }
     }
     unset($params[$this->_moduleKey]);
     $controller = $params[$this->_controllerKey];
     unset($params[$this->_controllerKey]);
     // set $action if value given is 'new' or 'edit'
     if (in_array($params[$this->_actionKey], array('new', 'edit'))) {
         $action = $params[$this->_actionKey];
     }
     unset($params[$this->_actionKey]);
     if (isset($params['index']) && $params['index']) {
         unset($params['index']);
         $url .= '/index';
         if (isset($params['id'])) {
             $url .= '/' . $params['id'];
             unset($params['id']);
         }
         foreach ($params as $key => $value) {
             if ($encode) {
                 $value = urlencode($value);
             }
             $url .= '/' . $key . '/' . $value;
         }
     } elseif (!empty($action) && isset($params['id'])) {
         $url .= sprintf('/%s/%s', $params['id'], $action);
     } elseif (!empty($action)) {
         $url .= sprintf('/%s', $action);
     } elseif (isset($params['id'])) {
         $url .= '/' . $params['id'];
     }
     if (!empty($url) || $controller !== $this->_defaults[$this->_controllerKey]) {
         $url = '/' . $controller . $url;
     }
     if (isset($module)) {
         $url = '/' . $module . $url;
     }
     return ltrim($url, self::URI_DELIMITER);
 }
コード例 #5
0
 /**
  * Get full name of script to render
  * 
  * @return string 
  */
 protected function getScript()
 {
     if (null === $this->getScriptName()) {
         $request = $this->frontController->getRequest();
         $this->setScriptName($request->getControllerName() . DIRECTORY_SEPARATOR . $request->getActionName());
     }
     return $this->getScriptName() . '.' . $this->getViewSuffix();
 }
コード例 #6
0
ファイル: Route.php プロジェクト: robeendey/ce
 /**
  * Constructor
  *
  * @param Zend_Controller_Front $front Front Controller object
  * @param array $defaults Defaults for map variables with keys as variable names
  * @param array $responders Modules or controllers to receive RESTful routes
  */
 public function __construct(Zend_Controller_Front $front, array $defaults = array(), array $responders = array())
 {
     $this->_defaults = $defaults;
     if ($responders) {
         $this->_parseResponders($responders);
     }
     if (isset($front)) {
         $this->_request = $front->getRequest();
         $this->_dispatcher = $front->getDispatcher();
     }
 }
コード例 #7
0
ファイル: Bootstrapper.php プロジェクト: Cryde/sydney-core
    /**
     * Do the MVC magic... Dispatch the frontcontroller
     */
    private function dispatch()
    {
        /**
         * Do the magic
         */
        try {
            $this->frontController->dispatch();
        } catch (Exception $e) {
            if ($this->config->general->env == 'DEV') {
                /**
                 * Custom error message if any
                 */
                $prms = $this->frontController->getRequest();
                if ($prms->format == 'json') {
                    $outp = array();
                    $outp['CaughtException'] = get_class($e);
                    $outp['message'] = $e->getMessage();
                    $outp['code'] = $e->getCode();
                    $outp['file'] = $e->getFile();
                    $outp['line'] = $e->getLine();
                    $outp['trace'] = $e->getTrace();
                    $outp['tracehtml'] = '';
                    foreach ($outp['trace'] as $le) {
                        $outp['tracehtml'] .= "" . "<b>Line</b>: " . $le['line'] . " | " . "<b>Function</b>: " . $le['function'] . " | " . "<b>Class</b>: " . $le['class'] . " | " . "<br>";
                    }
                    print Zend_Json::encode($outp);
                } else {
                    $outp = '';
                    $outp .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
					<html xmlns="http://www.w3.org/1999/xhtml">
					<head>
					<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
					<title>APPLICATION ERROR</title>
					<link href="' . $this->config->general->cdn . '/sydneyassets/styles/main.css" rel="stylesheet" type="text/css" />
					</head><style>.errorbug { font-face: courrier; } th { text-align: left; background: #EEE; } </style><body>';
                    $outp .= '<div class="errorbug subBox"><h1>Sydney debug info</h1><ul>';
                    $outp .= "<li><b>Caught exception:</b> " . get_class($e) . "</li>\n";
                    $outp .= "<li><b>Message:</b> " . $e->getMessage() . "</li>\n";
                    $outp .= "<hr>\n";
                    $outp .= "<li><b>Code:</b> " . $e->getCode() . "</li>\n";
                    $outp .= "<li><b>File:</b> " . $e->getFile() . "</li>\n";
                    $outp .= "<li><b>Line:</b> " . $e->getLine() . "</li>\n";
                    $outp .= "<li><b>Trace:</b><table><tr><th class=\"errortrace\">" . implode('</td></tr><tr><th class="errortrace">', explode("\n", $e->getTraceAsString())) . "</td></tr></table>";
                    $outp .= '</ul></div>';
                    $outp .= '</body></html>';
                    print $this->_errologtreat($outp);
                }
            } else {
                print "APPLICATION ERROR... Please contact the technical support";
            }
        }
    }
コード例 #8
0
 /**
  * @group ZF-11442
  */
 public function testIsActiveIsChainedRouteAware()
 {
     // Create page
     $page = new Zend_Navigation_Page_Mvc(array('action' => 'myaction', 'route' => 'myroute', 'params' => array('page' => 1337, 'item' => 1234)));
     // Create chained route
     $chain = new Zend_Controller_Router_Route_Chain();
     $foo = new Zend_Controller_Router_Route('lolcat/:action', array('module' => 'default', 'controller' => 'foobar', 'action' => 'bazbat'));
     $bar = new Zend_Controller_Router_Route(':page/:item', array('page' => 1, 'item' => 1));
     $chain->chain($foo)->chain($bar);
     // Set up router
     $this->_front->getRouter()->addRoute('myroute', $chain);
     $this->_front->getRequest()->setParams(array('module' => 'default', 'controller' => 'foobar', 'action' => 'myaction', 'page' => 1337, 'item' => 1234));
     // Test
     $this->assertTrue($page->isActive());
 }
コード例 #9
0
 /**
  * _dojoResponse
  *
  * @return void
  */
 private function _dojoResponse()
 {
     if (!$this->_viewRenderer->getResponse()->isException()) {
         $id = $this->_front->getRequest()->getParam("__identifier");
         $label = $this->_front->getRequest()->getParam("__label");
         $itemsVar = $this->_front->getRequest()->getParam("__items");
         $numRowsVar = $this->_front->getRequest()->getParam("__numRows");
         $items = $this->_view->getVar($itemsVar);
         $numRows = $this->_view->getVar($numRowsVar);
         $array = array('identifier' => $id, 'items' => $items, 'label' => $label, 'numRows' => $numRows);
         $dojoData = Zend_Json::encode($array);
         //$dojoData = new Zend_Dojo_Data($id,$items,$label);
         $this->_viewRenderer->getResponse()->setBody($dojoData);
         //$this->_view->_helper->autoCompleteDojo($data);
     } else {
         $contextSwitch = Zend_Controller_Action_HelperBroker::getExistingHelper('ContextSwitch');
         $contextSwitch->postJsonContext();
     }
 }
コード例 #10
0
ファイル: Form.php プロジェクト: kytvi2p/ZettaFramework
 public function getPostData()
 {
     foreach ($this->_fields as $field) {
         if ($field['type'] == 'date' || $field['type'] == 'datetime') {
             $string_date = $this->getValue($field['name']) . ($field['type'] == 'datetime' ? ' ' . Zend_Controller_Front::getRequest()->getParam($field['name'] . '_time') : '');
             $parse_date = date_parse($string_date);
             $arrayData[$field['name']] = sprintf('%04d-%02d-%02d' . ($field['type'] == 'datetime' ? ' %02d:%02d' : ''), $parse_date['year'], $parse_date['month'], $parse_date['day'], $parse_date['hour'], $parse_date['minute']);
         } else {
             if ($field['type'] == 'multiCheckbox') {
                 $arrayData[$field['name']] = '÷' . implode('÷', $this->getValue($field['name'])) . '÷';
             } else {
                 if ($field['type'] == 'file' && sizeof($_FILES)) {
                     // закачиваем файлик
                     if (array_key_exists($field['name'], $_FILES) && !$_FILES[$field['name']]['error']) {
                         $incomingDir = USER_FILES_PATH . DS . 'files/incoming';
                         if (false == is_dir($incomingDir)) {
                             mkdir($incomingDir);
                         }
                         $fName = explode('.', $_FILES[$field['name']]['name']);
                         $ext = end($fName);
                         $fileName = str_replace($ext, '_' . time() . '.' . $ext, $_FILES[$field['name']]['name']);
                         move_uploaded_file($_FILES[$field['name']]['tmp_name'], $incomingDir . DS . $fileName);
                         $arrayData[$field['name']] = '/UserFiles/files/incoming/' . $fileName;
                     }
                 } else {
                     $arrayData[$field['name']] = $this->getValue($field['name']);
                 }
             }
         }
     }
     unset($arrayData['captcha']);
     return $arrayData;
 }
コード例 #11
0
ファイル: Request.php プロジェクト: BGCX261/zlayer-svn-to-git
 /**
  * Return the param
  *
  * @param string $param
  * @return string
  */
 public function getParam($param)
 {
     return $this->_front->getRequest()->getParam($param);
 }