/** * @internal */ public function preDispatch() { $this->getResponse()->setHttpResponseCode(500); if (!($error = $this->getParam('error_handler'))) { return; } $code = $error->exception->getCode(); $callback = Benri_Util_String::camelize($this->getResponse()->getMessageFromCode($code)); $this->_pushError(null, $code, $error->exception->getMessage()); if ($callback) { $this->getResponse()->setHttpResponseCode($code); if (method_exists($this, "{$callback}Action")) { return $this->getRequest()->setActionName($callback); } } else { switch ($error->type) { case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE: case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER: case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION: $this->getResponse()->setHttpResponseCode(404); $this->getRequest()->setActionName('not-found'); break; } } }
/** * Set a row field value. * * @internal */ public function __set($columnName, $value) { $setter = Benri_Util_String::camelize($columnName, true); if (method_exists($this, $setter = "set{$setter}")) { $value = call_user_func_array([$this, $setter], [$value]); } return parent::__set($columnName, $value); }
/** * Attempts to make certain that only one record was returned in the * resultset. * * @param array $resultIdentities * @return Zend_Auth_Result * @see http://framework.zend.com/manual/1.12/en/zend.auth.introduction.html#zend.auth.introduction.results Zend_Auth_Result */ protected function _authenticateValidateResult($resultIdentity) { $code = Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID; $message = 'Supplied credential is invalid.'; if (Benri_Util_String::verifyPassword($this->_credential, $resultIdentity[$this->_credentialColumn])) { $code = Zend_Auth_Result::SUCCESS; $message = 'Authentication successful.'; $this->_resultRow = $resultIdentity; } $this->_authenticateResultInfo['code'] = $code; $this->_authenticateResultInfo['messages'][] = $message; /// _authenticateCreateAuthResult creates a Zend_Auth_Result object /// from the information that has been collected during the /// Benri_Auth_Adapter_DbTable::authenticate() attempt. return $this->_authenticateCreateAuthResult(); }
/** * Create dynamic finders. * * Dynamic finders ease your life in a way to do queries quickly without * having to eventually instantiate a `Benri_Db_Table` class. * * <code> * // `where name = ?, "douggr"` * Person::whereNameEq('douggr'); * * // `where phone IS NULL` * Person::wherePhoneIsNull(); * * // `where id IN (?), $values` * SomeModel::whereIdIn(1, 2, 3, 4); * </code> * * @internal * @return Benri_Db_Table_Rowset * @throws Zend_Db_Table_Exception if invalid query */ public static function __callStatic($method, array $args = []) { preg_match('/where(?P<column>[a-zA-Z]+)(?P<operator>Lt|Le|Gt|Ge|Eq|Ne|In|IsNull|IsNotNull)+/', $method, $matches); if (!$matches) { throw new Zend_Db_Table_Exception(sprintf('Call to undefined method %s::%s()', get_called_class(), $method)); } // // PHP's black magic extract($matches); $table = new static(); $select = $table->select(); $options = []; $column = $table->getAdapter()->quoteIdentifier(Benri_Util_String::dasherize($column)); foreach ($args as $key => $arg) { if (is_array($arg)) { $options = $arg; unset($args[$key]); } } foreach ($options as $method => $value) { call_user_func_array([$select, $method], (array) $value); } if ('IsNull' === $operator) { return $table->fetchAll($select->where("{$column} IS NULL")); } if ('IsNotNull' === $operator) { return $table->fetchAll($select->where("{$column} IS NOT NULL")); } switch ($operator) { case 'Lt': $operator = '< ?'; break; case 'Le': $operator = '<= ?'; break; case 'Gt': $operator = '> ?'; break; case 'Ge': $operator = '>= ?'; break; case 'Eq': $operator = '= ?'; break; case 'Ne': $operator = '<> ?'; break; case 'In': $operator = 'IN (?)'; break; } return $table->fetchAll($select->where("{$column} {$operator}", $args)); }