public function regformAction() { // show reg form $view = Zend::registry("view"); $view->title = "User Registration"; print $view->render('user/regform.php'); }
public function addAdvancedRoute($name, $map, $params = array(), $reqs = array()) { if (!class_exists('Custom_Controller_Router_AdvancedRoute')) { Zend::loadClass('Custom_Controller_Router_AdvancedRoute'); } $this->_routes[$name] = new Custom_Controller_Router_AdvancedRoute($map, $params, $reqs); }
/** * Authenticates against the given parameters * * $options requires the following key-value pairs: * * 'filename' => path to digest authentication file * 'realm' => digest authentication realm * 'username' => digest authentication user * 'password' => password for the user of the realm * * @param array $options * @throws Zend_Auth_Digest_Exception * @return Zend_Auth_Digest_Token */ public static function staticAuthenticate(array $options) { $optionsRequired = array('filename', 'realm', 'username', 'password'); foreach ($optionsRequired as $optionRequired) { if (!isset($options[$optionRequired]) || !is_string($options[$optionRequired])) { throw Zend::exception('Zend_Auth_Digest_Exception', "Option '{$optionRequired}' is required to be " . 'provided as a string'); } } if (false === ($fileHandle = @fopen($options['filename'], 'r'))) { throw Zend::exception('Zend_Auth_Digest_Exception', "Cannot open '{$options['filename']}' for reading"); } require_once 'Zend/Auth/Digest/Token.php'; $id = "{$options['username']}:{$options['realm']}"; $idLength = strlen($id); $tokenValid = false; $tokenIdentity = array('realm' => $options['realm'], 'username' => $options['username']); while ($line = trim(fgets($fileHandle))) { if (substr($line, 0, $idLength) === $id) { if (substr($line, -32) === md5("{$options['username']}:{$options['realm']}:{$options['password']}")) { $tokenValid = true; $tokenMessage = null; } else { $tokenMessage = 'Password incorrect'; } return new Zend_Auth_Digest_Token($tokenValid, $tokenIdentity, $tokenMessage); } } $tokenMessage = "Username '{$options['username']}' and realm '{$options['realm']}' combination not found"; return new Zend_Auth_Digest_Token($tokenValid, $tokenIdentity, $tokenMessage); }
/** * recurses through the Test subdir and includes classes in each test group subdir, * then builds an array of classnames for the tests that will be run * */ public function loadTests($test_path = NULL) { $this->resetStats(); if ($test_path === NULL) { // this seems hackey. is it? dunno. $test_path = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'Security' . DIRECTORY_SEPARATOR . 'Test'; } $test_root = dir($test_path); while (false !== ($entry = $test_root->read())) { if (is_dir($test_root->path . DIRECTORY_SEPARATOR . $entry) && !preg_match('|^\\.(.*)$|', $entry)) { $test_dirs[] = $entry; } } // include_once all files in each test dir foreach ($test_dirs as $test_dir) { $this_dir = dir($test_root->path . DIRECTORY_SEPARATOR . $test_dir); while (false !== ($entry = $this_dir->read())) { if (!is_dir($this_dir->path . DIRECTORY_SEPARATOR . $entry) && preg_match('/[A-Za-z]+\\.php/i', $entry)) { $className = "Zend_Environment_Security_Test_" . $test_dir . "_" . basename($entry, '.php'); Zend::loadClass($className); $classNames[] = $className; } } } $this->_tests_to_run = $classNames; }
/** * Disconnects from the peer, closes the socket. * * @return void */ protected function _disconnect() { if (!is_resource($this->_socket)) { throw Zend::exception('Zend_TimeSync_ProtocolException', "could not close server connection from '{$this->_timeserver}' on port '{$this->_port}'"); } @fclose($this->_socket); $this->_socket = null; }
public static function autoload($class) { try { Zend::loadClass($class); } catch (Zend_Exception $e) { return false; } return true; }
public function testException() { $this->assertTrue(Zend::exception('Zend_Exception') instanceof Exception); try { $e = Zend::exception('Zend_FooBar_Baz', 'should fail'); $this->fail('invalid exception class should throw exception'); } catch (Exception $e) { // success... } }
/** * @param string $var * @param string $value */ protected function __set($var, $value) { switch ($var) { case 'updatedMin': case 'updatedMax': throw Zend::exception('Zend_Gdata_Exception', "Parameter '{$var}' is not currently supported in Spreadsheets."); break; } parent::__set($var, $value); }
public function routeShutdown($action) { $user = Zend::registry('user'); if ($user->getPermission($action->getControllerName(), $action->getActionName())) { return $action; } else { $action->setControllerName('index'); $action->setActionName('unauthorized'); return $action; } }
function __construct($config = array()) { // set a Zend_Db_Adapter connection if (!empty($config['db'])) { // convenience variable $db = $config['db']; // use an object from the registry? if (is_string($db)) { $db = Zend::registry($db); } // make sure it's a Zend_Db_Adapter if (!$db instanceof Zend_Db_Adapter_Abstract) { throw new Varien_Db_Tree_Exception('db object does not implement Zend_Db_Adapter_Abstract'); } // save the connection $this->_db = $db; $conn = $this->_db->getConnection(); if ($conn instanceof PDO) { $conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); } elseif ($conn instanceof mysqli) { //TODO: ??? } } else { throw new Varien_Db_Tree_Exception('db object is not set in config'); } if (!empty($config['table'])) { $this->setTable($config['table']); } if (!empty($config['id'])) { $this->setIdField($config['id']); } else { $this->setIdField('id'); } if (!empty($config['left'])) { $this->setLeftField($config['left']); } else { $this->setLeftField('left_key'); } if (!empty($config['right'])) { $this->setRightField($config['right']); } else { $this->setRightField('right_key'); } if (!empty($config['level'])) { $this->setLevelField($config['level']); } else { $this->setLevelField('level'); } if (!empty($config['pid'])) { $this->setPidField($config['pid']); } else { $this->setPidField('parent_id'); } }
public function getDriver() { // @todo: when the Mysqli adapter moves out of the incubator, // the following trick to allow it to be loaded should be removed. $incubator = dirname(dirname(dirname(dirname(dirname(__FILE__))))) . DIRECTORY_SEPARATOR . 'incubator' . DIRECTORY_SEPARATOR . 'library'; Zend::loadClass('Zend_Db_Adapter_Mysqli', $incubator); // @todo: also load any auxiliary classes if necessary, e.g.: // Zend_Db_Adapter_Mysqli_Exception // Zend_Db_Statement_Mysqli // Zend_Db_Statement_Mysqli_Exception return 'Mysqli'; }
/** * @param array $config * @throws LocalizedException * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function __construct($config = []) { // set a \Zend_Db_Adapter connection if (!empty($config['db'])) { // convenience variable $connection = $config['db']; // use an object from the registry? if (is_string($connection)) { $connection = \Zend::registry($connection); } // make sure it's a \Zend_Db_Adapter if (!$connection instanceof \Zend_Db_Adapter_Abstract) { throw new LocalizedException(new \Magento\Framework\Phrase('db object does not implement \\Zend_Db_Adapter_Abstract')); } // save the connection $this->_db = $connection; $conn = $this->_db->getConnection(); if ($conn instanceof \PDO) { $conn->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true); } } else { throw new LocalizedException(new \Magento\Framework\Phrase('db object is not set in config')); } if (!empty($config['table'])) { $this->setTable($config['table']); } if (!empty($config['id'])) { $this->setIdField($config['id']); } else { $this->setIdField('id'); } if (!empty($config['left'])) { $this->setLeftField($config['left']); } else { $this->setLeftField('left_key'); } if (!empty($config['right'])) { $this->setRightField($config['right']); } else { $this->setRightField('right_key'); } if (!empty($config['level'])) { $this->setLevelField($config['level']); } else { $this->setLevelField('level'); } if (!empty($config['pid'])) { $this->setPidField($config['pid']); } else { $this->setPidField('parent_id'); } }
/** * Sets a new timestamp * * @param $date mixed - OPTIONAL timestamp otherwise actual timestamp is used * @return boolean * @throws Zend_Date_Exception */ public function setTimestamp($date = false) { // no date value, take actual time if ($date === false) { $this->_unixtimestamp = time(); return true; } if (is_numeric($date)) { $this->_unixtimestamp = $date; return true; } throw Zend::exception('Zend_Date_Exception', '\'' . $date . '\' is no valid date'); }
public static function autoload($class) { try { if (class_exists('Zend_Version')) { Zend_Loader::loadClass($class); } else { Zend::loadClass($class); } } catch (Zend_Exception $e) { return false; } return true; }
/** * Tworzy now� ankiet� i przekierowuje do akcji edytujAction */ public function nowaAction() { $post = new Zend_Filter_Input($_POST); $user = Zend::registry('user'); $poll = new Ankiety(); $data = array('nazwa' => $post->getRaw('ankieta_nazwa'), 'opis' => $post->getRaw('ankieta_opis'), 'id_uzytkownik' => 1); try { $id = $poll->insert($data); $this->_forward('ankieter', 'edytuj', array('ankieta' => $id)); } catch (Hamster_Validation_Exception $e) { $this->_forward('ankieter', 'index', array('validationError' => $e->getMessage())); } }
public static function autoload($class) { try { if (self::$withLoader) { Zend_Loader::loadClass($class); } else { Zend::loadClass($class); } } catch (Zend_Exception $e) { return false; } return true; }
public function setUp() { if (!class_exists('Zend_Log') || !class_exists('Zend_Log_Adapter_Null')) { Zend::loadClass('Zend_Log'); Zend::loadClass('Zend_Log_Adapter_Null'); } if (!Zend_Log::hasLogger('LOG')) { Zend_Log::registerLogger(new Zend_Log_Adapter_Null(), 'LOG'); } $this->_instance->setDirectives(array('logging' => true)); $this->_instance->save('bar : data to cache', 'bar', array('tag3', 'tag4')); $this->_instance->save('bar2 : data to cache', 'bar2', array('tag3', 'tag1')); $this->_instance->save('bar3 : data to cache', 'bar3', array('tag2', 'tag3')); }
/** * Writes/receives data to/from the timeserver * * @return int unix timestamp */ protected function _query() { $this->_connect(); $begin = time(); fputs($this->_socket, "\n"); $result = fread($this->_socket, 49); $end = time(); $this->_disconnect(); if (!$result) { throw Zend::exception('Zend_TimeSync_ProtocolException', 'invalid result returned from server'); } else { $time = abs(hexdec('7fffffff') - hexdec(bin2hex($result)) - hexdec('7fffffff')); $time -= 2208988800; // socket delay $time -= ($end - $begin) / 2; return $time; } }
/** * The Primitus View plugin is a procedural function which implements the logic of * the template-level {render} function. It is responsible for either calling the * requested controller's render() method to get the template, or simply processing * the template in the views/ directory if the controller didn't exist. * * You can set template-level variables in the module being rendered by simply setting * them in the smarty {render} function. i.e. * * {render module="blog" action="view" entry=$entry} * * will expose the {$entry} template variable to the blog::view template in /blog/view.tpl * * @category Primitus * @package Primitus * @subpackage View * @copyright Copyright (c) 2006 John Coggeshall * @license http://framework.zend.com/license/new-bsd New BSD License */ function Primitus_View_Plugin_Render($params, &$smarty) { if (!isset($params['module'])) { throw new Primitus_View_Exception("No module name was provided to render"); } $module = $params['module']; if (strtolower(substr($module, strlen($module) - 10)) != "controller") { $module .= "Controller"; } $action = isset($params['action']) ? $params['action'] : "indexAction"; $dispatcher = Primitus::registry('Dispatcher'); $controllerFile = $dispatcher->formatControllerFile($module); if (file_exists($controllerFile)) { // Load the Class Zend::loadClass($module, $dispatcher->getControllerDirectory()); $controller = new $module(); if ($controller instanceof Primitus_Controller_Action_Base) { unset($params['module']); unset($params['action']); if (!empty($params)) { $view = Primitus_View::getInstance($module); foreach ($params as $key => $value) { $view->assign($key, $value); } } return $controller->render($action); } else { throw new Primitus_View_Exception("Bad Request"); } } else { $view = Primitus_View::getInstance($module); unset($params['module']); unset($params['action']); if (!empty($params)) { $view = Primitus_View::getInstance($module); foreach ($params as $key => $value) { $view->assign($key, $value); } } return $view->render($action); } }
/** * load class * @param string $className : the class to load * @throws Exception */ function __autoload($className) { if (class_exists('Zend', false)) { if (is_int(strrpos($className, '_Interface'))) { Zend::loadClass($className); } else { Zend::loadInterface($className); } } else { if (!defined('__CLASS_PATH__')) { define('__CLASS_PATH__', realpath(dirname(__FILE__))); } $file = __CLASS_PATH__ . '/' . str_replace('_', '/', $className) . '.php'; if (!file_exists($file)) { throw new Exception('Cannot load class file ' . $className); } else { require_once $file; } } }
public static function init() { if (!self::$init) { Zend::_use('Zend_Mail'); if (Settings::get(self::SMTP_HOST, false)) { Zend::_use('Zend_Mail_Transport_Smtp'); $config = array('port' => Settings::get(self::SMTP_PORT, 25)); if (Settings::get(self::SMTP_USER, false)) { $config['auth'] = 'login'; $config['username'] = Settings::get(self::SMTP_USER, ''); $config['password'] = Settings::get(self::SMTP_PASS, ''); } if (Settings::get(self::SMTP_SSL, false)) { $config['ssl'] = Settings::get(self::SMTP_SSL); } $transport = new Zend_Mail_Transport_Smtp(Settings::get(self::SMTP_HOST), $config); Zend_Mail::setDefaultTransport($transport); } self::$init = true; } }
/** * @param array $modules * @param array $config * @throws Zend_Environment_Exception * @return void */ public function __construct($modules, $config = array()) { if (is_array($config)) { if (isset($config['cache'])) { $this->_cache = $config['cache']; } } if (isset($this->_cache)) { if ($data = $this->_cache->load($this->_cachePrefix . 'module')) { $this->_data = unserialize($data); return; } } if ($modules === null) { $modules = array(); $registry = new Zend_Environment_ModuleRegistry(); foreach ($registry as $file) { $class = rtrim($file->getFilename(), '.php'); $module = "Zend_Environment_Module_{$class}"; Zend::loadClass($module); try { $modules[] = new $module(strtolower($class)); } catch (Zend_Environment_Exception $e) { } } } elseif (!is_array($modules)) { $modules = array($modules); } foreach ($modules as $instance) { if (!$instance instanceof Zend_Environment_Module_Interface) { throw new Zend_Environment_Exception("Module does not implement Zend_Environment_Module_Interface"); } $this->_data[$instance->getId()] = $instance; } $this->_cache('module', serialize($this->_data)); }
/** * magic method for unserialize() * * with this method you can cache the mbox class * for cache validation the mtime of the mbox file is used */ public function __wakeup() { if ($this->_filemtime != filemtime($this->_filename)) { $this->close(); $this->_openMboxFile($this->_filename); } else { $this->_fh = @fopen($this->_filename, 'r'); if (!$this->_fh) { throw Zend::exception('Zend_Mail_Exception', 'cannot open mbox file'); } } }
/** * Dispatch to a controller/action * * @param Zend_Controller_Request_Abstract $request * @param Zend_Controller_Response_Abstract $response * @return boolean */ public function dispatch(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response) { $this->setResponse($response); /** * Get controller directories */ $directories = $this->getControllerDirectory(); /** * Get controller class */ $className = $this->_getController($request); /** * If no class name returned, report exceptional behaviour */ if (!$className) { throw new Zend_Controller_Dispatcher_Exception('"' . $request->getControllerName() . '" controller does not exist'); } /** * Load the controller class file * * Attempts to load the controller class file from {@link getControllerDirectory()}. */ Zend::loadClass($className, $this->getControllerDirectory()); /** * Instantiate controller with request, response, and invocation * arguments; throw exception if it's not an action controller */ $controller = new $className($request, $this->getResponse(), $this->getParams()); if (!$controller instanceof Zend_Controller_Action) { throw new Zend_Controller_Dispatcher_Exception("Controller '{$className}' is not an instance of Zend_Controller_Action"); } /** * Retrieve the action name */ $action = $this->_getAction($request); /** * If method does not exist, default to __call() */ $doCall = !method_exists($controller, $action); /** * Dispatch the method call */ $request->setDispatched(true); $controller->preDispatch(); if ($request->isDispatched()) { // preDispatch() didn't change the action, so we can continue if ($doCall) { $controller->__call($action, array()); } else { $controller->{$action}(); } $controller->postDispatch(); } // Destroy the page controller instance and reflection objects $controller = null; }
/** * Get a specific cookie according to a URI and name * * @param Zend_Uri_Http|string $uri The uri (domain and path) to match * @param string $cookie_name The cookie's name * @param int $ret_as Whether to return cookies as objects of Zend_Http_Cookie or as strings * @return Zend_Http_Cookie|string */ public function getCookie($uri, $cookie_name, $ret_as = self::COOKIE_OBJECT) { if (is_string($uri)) { $uri = Zend_Uri::factory($uri); } if (!$uri instanceof Zend_Uri_Http) { throw Zend::exception('Zend_Http_Exception', 'Invalid URI specified'); } // Get correct cookie path $path = $uri->getPath(); $path = substr($path, 0, strrpos($path, '/')); if (!$path) { $path = '/'; } if (isset($this->cookies[$uri->getHost()][$path][$cookie_name])) { $cookie = $this->cookies[$uri->getHost()][$path][$cookie_name]; switch ($ret_as) { case self::COOKIE_OBJECT: return $cookie; break; case self::COOKIE_STRING_ARRAY: case self::COOKIE_STRING_CONCAT: return $cookie->__toString(); break; default: throw Zend::exception('Zend_Http_Exception', "Invalid value passed for \$ret_as: {$ret_as}"); break; } } else { return false; } }
/** * Zend_Measure_Area provides an locale aware class for * conversion and formatting of area values * * Zend_Measure $input can be a locale based input string * or a value. $locale can be used to define that the * input is made in a different language than the actual one. * * @param $value mixed - Value as string, integer, real or float * @param $type type - OPTIONAL a Zend_Measure_Area Type * @param $locale locale - OPTIONAL a Zend_Locale Type * @throws Zend_Measure_Exception */ public function __construct($value, $type, $locale = false) { if ($locale === null) { $locale = $this->_Locale; } if (!($locale = Zend_Locale::isLocale($locale, true))) { throw new Zend_Measure_Exception("language ({$locale}) is a unknown language"); } if ($type === null) { $type = self::STANDARD; } if (strpos($type, '::') !== false) { $type = substr($type, 0, strpos($type, '::')); $sublib = substr($type, strpos($type, '::') + 2); } if (!array_key_exists($type, self::$_UNIT)) { throw new Zend_Measure_Exception("type ({$type}) is unknown"); } if (empty($sublib)) { $sublib = current(self::$_UNIT[$type]); } $library = 'Zend_Measure_' . key(self::$_UNIT[$type]); Zend::loadClass($library); $this->_Measurement = new $library($value, $sublib, $locale); }
/** * Assembles user submitted parameters forming a URL path defined by this route * * @param array An array of variable and value pairs used as parameters * @return string Route path with user submitted parameters */ public function assemble($data = array(), $reset = false) { $url = array(); if (!$reset) { $data += $this->_params; } foreach ($this->_parts as $key => $part) { if (isset($part['name'])) { if (isset($data[$part['name']])) { $url[$key] = $data[$part['name']]; unset($data[$part['name']]); } elseif (isset($this->_values[$part['name']])) { $url[$key] = $this->_values[$part['name']]; } elseif (isset($this->_defaults[$part['name']])) { $url[$key] = $this->_defaults[$part['name']]; } else { throw Zend::exception('Zend_Controller_Router_Exception', $part['name'] . ' is not specified'); } } else { if ($part['regex'] != '\\*') { $url[$key] = $part['regex']; } else { foreach ($data as $var => $value) { $url[$var] = $var . self::URI_DELIMITER . $value; } } } } return implode(self::URI_DELIMITER, $url); }
protected function __set($var, $value) { switch ($var) { case 'startMin': $var = 'start-min'; $value = $this->formatTimestamp($value); break; case 'startMax': $var = 'start-max'; $value = $this->formatTimestamp($value); break; case 'visibility': case 'projection': if (!Zend_Gdata_Data::isValid($value, $var)) { throw Zend::exception('Zend_Gdata_Exception', "Unsupported {$var} value: '{$value}'"); } $var = "_{$var}"; break; case 'orderby': if (!Zend_Gdata_Data::isValid($value, 'orderby#calendar')) { throw Zend::exception('Zend_Gdata_Exception', "Unsupported {$var} value: '{$value}'"); } break; case 'user': $var = '_user'; // @todo: validate user value break; case 'event': $var = '_event'; // @todo: validate event value break; case 'comments': $var = '_comments'; // @todo: validate comments subfeed value break; default: // other params are handled by parent break; } parent::__set($var, $value); }
/** * Unregister a plugin. * * @param Zend_Controller_Plugin_Abstract $plugin * @return Zend_Controller_Plugin_Broker */ public function unregisterPlugin(Zend_Controller_Plugin_Abstract $plugin) { $key = array_search($plugin, $this->_plugins, true); if (false === $key) { throw Zend::exception('Zend_Controller_Exception', 'Plugin never registered.'); } unset($this->_plugins[$key]); return $this; }
/** * Find a matching route to the current PATH_INFO and inject * returning values to the Request object. * * @throws Zend_Controller_Router_Exception * @return Zend_Controller_Request_Abstract Request object */ public function route(Zend_Controller_Request_Abstract $request) { if (!$request instanceof Zend_Controller_Request_Http) { throw Zend::exception('Zend_Controller_Router_Exception', 'Zend_Controller_RewriteRouter requires a Zend_Controller_Request_Http-based request object'); } if ($this->useDefaultRoutes) { $this->addDefaultRoutes(); } $pathInfo = $request->getPathInfo(); /** Find the matching route */ foreach (array_reverse($this->_routes) as $name => $route) { if ($params = $route->match($pathInfo)) { foreach ($params as $param => $value) { $request->setParam($param, $value); } $this->_currentRoute = $name; break; } } return $request; }