Fix most coding standard issues in Controller.

This commit is contained in:
mark_story 2012-03-03 19:27:46 -05:00
parent db8c6b5c78
commit 61aba0f0f8
22 changed files with 111 additions and 91 deletions

View file

@ -75,4 +75,5 @@ class CakeErrorController extends AppController {
}
}
}
}

View file

@ -106,7 +106,8 @@ class Component extends Object {
* @return void
* @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::initialize
*/
public function initialize(Controller $controller) { }
public function initialize(Controller $controller) {
}
/**
* Called after the Controller::beforeFilter() and before the controller action
@ -115,7 +116,8 @@ class Component extends Object {
* @return void
* @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::startup
*/
public function startup(Controller $controller) { }
public function startup(Controller $controller) {
}
/**
* Called after the Controller::beforeRender(), after the view class is loaded, and before the
@ -125,7 +127,8 @@ class Component extends Object {
* @return void
* @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::beforeRender
*/
public function beforeRender(Controller $controller) { }
public function beforeRender(Controller $controller) {
}
/**
* Called after Controller::render() and before the output is printed to the browser.
@ -134,7 +137,8 @@ class Component extends Object {
* @return void
* @link @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::shutdown
*/
public function shutdown(Controller $controller) { }
public function shutdown(Controller $controller) {
}
/**
* Called before Controller::redirect(). Allows you to replace the url that will
@ -155,6 +159,7 @@ class Component extends Object {
* @return array|null Either an array or null.
* @link @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::beforeRedirect
*/
public function beforeRedirect(Controller $controller, $url, $status = null, $exit = true) {}
public function beforeRedirect(Controller $controller, $url, $status = null, $exit = true) {
}
}

View file

@ -66,4 +66,5 @@ interface AclInterface {
* @param AclComponent $component
*/
public function initialize(Component $component);
}

View file

@ -289,5 +289,5 @@ class DbAcl extends Object implements AclInterface {
}
return $newKeys;
}
}
}

View file

@ -45,7 +45,6 @@ class IniAcl extends Object implements AclInterface {
* @return void
*/
public function initialize(Component $component) {
}
/**
@ -57,7 +56,6 @@ class IniAcl extends Object implements AclInterface {
* @return boolean Success
*/
public function allow($aro, $aco, $action = "*") {
}
/**
@ -69,7 +67,6 @@ class IniAcl extends Object implements AclInterface {
* @return boolean Success
*/
public function deny($aro, $aco, $action = "*") {
}
/**
@ -81,7 +78,6 @@ class IniAcl extends Object implements AclInterface {
* @return boolean Success
*/
public function inherit($aro, $aco, $action = "*") {
}
/**
@ -91,10 +87,10 @@ class IniAcl extends Object implements AclInterface {
*
* @param string $aro ARO
* @param string $aco ACO
* @param string $aco_action Action
* @param string $action Action
* @return boolean Success
*/
public function check($aro, $aco, $aco_action = null) {
public function check($aro, $aco, $action = null) {
if ($this->config == null) {
$this->config = $this->readConfigFile(APP . 'Config' . DS . 'acl.ini.php');
}
@ -147,7 +143,8 @@ class IniAcl extends Object implements AclInterface {
}
/**
* Parses an INI file and returns an array that reflects the INI file's section structure. Double-quote friendly.
* Parses an INI file and returns an array that reflects the
* INI file's section structure. Double-quote friendly.
*
* @param string $filename File
* @return array INI section structure
@ -171,4 +168,5 @@ class IniAcl extends Object implements AclInterface {
array_unshift($array, "");
return $array;
}
}

View file

@ -37,7 +37,6 @@ class PhpAcl extends Object implements AclInterface {
*/
public $options = array();
/**
* Aro Object
*
@ -52,13 +51,18 @@ class PhpAcl extends Object implements AclInterface {
*/
public $Aco = null;
/**
* Constructor
*
* Sets a few default settings up.
*/
public function __construct() {
$this->options = array(
'policy' => self::DENY,
'config' => APP . 'Config' . DS . 'acl.php',
);
}
/**
* Initialize method
*
@ -83,6 +87,7 @@ class PhpAcl extends Object implements AclInterface {
*
* @param array $config configuration array, see docs
* @return void
* @throws AclException When required keys are missing.
*/
public function build(array $config) {
if (empty($config['roles'])) {
@ -145,15 +150,15 @@ class PhpAcl extends Object implements AclInterface {
*
* @param string $aro ARO
* @param string $aco ACO
* @param string $aco_action Action
* @param string $action Action
* @return boolean true if access is granted, false otherwise
*/
public function check($aro, $aco, $aco_action = "*") {
public function check($aro, $aco, $action = "*") {
$allow = $this->options['policy'];
$prioritizedAros = $this->Aro->roles($aro);
if ($aco_action && $aco_action != "*") {
$aco .= '/' . $aco_action;
if ($action && $action != "*") {
$aco .= '/' . $action;
}
$path = $this->Aco->path($aco);
@ -176,6 +181,7 @@ class PhpAcl extends Object implements AclInterface {
return $allow;
}
}
/**
@ -189,7 +195,7 @@ class PhpAco {
*
* @var array
*/
protected $tree = array();
protected $_tree = array();
/**
* map modifiers for ACO paths to their respective PCRE pattern
@ -219,7 +225,7 @@ class PhpAco {
$aco = $this->resolve($aco);
$path = array();
$level = 0;
$root = $this->tree;
$root = $this->_tree;
$stack = array(array($root, 0));
while (!empty($stack)) {
@ -239,7 +245,6 @@ class PhpAco {
if (empty($path[$level][$policy])) {
$path[$level][$policy] = array();
}
$path[$level][$policy] = array_merge($path[$level][$policy], $elements[$policy]);
}
}
@ -255,7 +260,6 @@ class PhpAco {
return $path;
}
/**
* allow/deny ARO access to ARO
*
@ -264,7 +268,7 @@ class PhpAco {
public function access($aro, $aco, $action, $type = 'deny') {
$aco = $this->resolve($aco);
$depth = count($aco);
$root = $this->tree;
$root = $this->_tree;
$tree = &$root;
foreach ($aco as $i => $node) {
@ -285,7 +289,7 @@ class PhpAco {
}
}
$this->tree = &$root;
$this->_tree = &$root;
}
/**
@ -315,7 +319,7 @@ class PhpAco {
*/
public function build(array $allow, array $deny = array()) {
$stack = array();
$this->tree = array();
$this->_tree = array();
$tree = array();
$root = &$tree;
@ -336,7 +340,6 @@ class PhpAco {
}
}
}
/**
@ -382,7 +385,7 @@ class PhpAro {
*
* @var array
*/
protected $tree = array();
protected $_tree = array();
public function __construct(array $aro = array(), array $map = array(), array $aliases = array()) {
if (!empty($map)) {
@ -393,7 +396,6 @@ class PhpAro {
$this->build($aro);
}
/**
* From the perspective of the given ARO, walk down the tree and
* collect all inherited AROs levelwise such that AROs from different
@ -413,7 +415,7 @@ class PhpAro {
list($element, $depth) = array_pop($stack);
$aros[$depth][] = $element;
foreach ($this->tree as $node => $children) {
foreach ($this->_tree as $node => $children) {
if (in_array($element, $children)) {
array_push($stack, array($node, $depth + 1));
}
@ -423,7 +425,6 @@ class PhpAro {
return array_reverse($aros);
}
/**
* resolve an ARO identifier to an internal ARO string using
* the internal mapping information.
@ -460,7 +461,7 @@ class PhpAro {
}
}
if (isset($this->tree[$mapped])) {
if (isset($this->_tree[$mapped])) {
return $mapped;
}
@ -468,13 +469,10 @@ class PhpAro {
if (!empty($this->aliases[$mapped])) {
return $this->aliases[$mapped];
}
}
return self::DEFAULT_ROLE;
}
/**
* adds a new ARO to the tree
*
@ -483,8 +481,8 @@ class PhpAro {
*/
public function addRole(array $aro) {
foreach ($aro as $role => $inheritedRoles) {
if (!isset($this->tree[$role])) {
$this->tree[$role] = array();
if (!isset($this->_tree[$role])) {
$this->_tree[$role] = array();
}
if (!empty($inheritedRoles)) {
@ -507,11 +505,11 @@ class PhpAro {
continue;
}
if (!isset($this->tree[$dependency])) {
$this->tree[$dependency] = array();
if (!isset($this->_tree[$dependency])) {
$this->_tree[$dependency] = array();
}
$this->tree[$dependency][] = $role;
$this->_tree[$dependency][] = $role;
}
}
}
@ -534,7 +532,8 @@ class PhpAro {
* @return void
*/
public function build(array $aros) {
$this->tree = array();
$this->_tree = array();
$this->addRole($aros);
}
}

View file

@ -177,6 +177,5 @@ class AclComponent extends Component {
trigger_error(__d('cake_dev', 'AclComponent::revoke() is deprecated, use deny() instead'), E_USER_WARNING);
return $this->_Instance->deny($aro, $aco, $action);
}
}

View file

@ -38,4 +38,5 @@ class ActionsAuthorize extends BaseAuthorize {
$user = array($this->settings['userModel'] => $user);
return $Acl->check($user, $this->action($request));
}
}

View file

@ -121,7 +121,8 @@ abstract class BaseAuthenticate {
* @param array $user The user about to be logged out.
* @return void
*/
public function logout($user) { }
public function logout($user) {
}
/**
* Get a user based on information in the request. Primarily used by stateless authentication
@ -133,4 +134,5 @@ abstract class BaseAuthenticate {
public function getUser($request) {
return false;
}
}

View file

@ -21,6 +21,7 @@
* @see AuthComponent::$authenticate
*/
abstract class BaseAuthorize {
/**
* Controller for the request.
*
@ -156,4 +157,5 @@ abstract class BaseAuthorize {
}
}
}
}

View file

@ -41,6 +41,7 @@ App::uses('BaseAuthenticate', 'Controller/Component/Auth');
* @since 2.0
*/
class BasicAuthenticate extends BaseAuthenticate {
/**
* Settings for this object.
*
@ -121,4 +122,5 @@ class BasicAuthenticate extends BaseAuthenticate {
public function loginHeaders() {
return sprintf('WWW-Authenticate: Basic realm="%s"', $this->settings['realm']);
}
}

View file

@ -98,4 +98,5 @@ class CrudAuthorize extends BaseAuthorize {
$this->settings['actionMap'][$request->params['action']]
);
}
}

View file

@ -55,6 +55,7 @@ App::uses('BaseAuthenticate', 'Controller/Component/Auth');
* @since 2.0
*/
class DigestAuthenticate extends BaseAuthenticate {
/**
* Settings for this object.
*
@ -65,7 +66,8 @@ class DigestAuthenticate extends BaseAuthenticate {
* - `realm` The realm authentication is for, Defaults to the servername.
* - `nonce` A nonce used for authentication. Defaults to `uniqid()`.
* - `qop` Defaults to auth, no other values are supported at this time.
* - `opaque` A string that must be returned unchanged by clients. Defaults to `md5($settings['realm'])`
* - `opaque` A string that must be returned unchanged by clients.
* Defaults to `md5($settings['realm'])`
*
* @var array
*/
@ -261,4 +263,5 @@ class DigestAuthenticate extends BaseAuthenticate {
}
return 'WWW-Authenticate: Digest ' . implode(',', $opts);
}
}

View file

@ -718,4 +718,5 @@ class AuthComponent extends Component {
public function flash($message) {
$this->Session->setFlash($message, $this->flash['element'], $this->flash['params'], $this->flash['key']);
}
}

View file

@ -503,4 +503,5 @@ class CookieComponent extends Component {
}
return $array;
}
}

View file

@ -377,4 +377,5 @@ class PaginatorComponent extends Component {
$options['limit'] = min((int)$options['limit'], $options['maxLimit']);
return $options;
}
}

View file

@ -592,4 +592,5 @@ class SecurityComponent extends Component {
return null;
}
}
}

View file

@ -124,4 +124,5 @@ class ComponentCollection extends ObjectCollection implements CakeEventListener
'Controller.shutdown' => array('callable' => 'trigger'),
);
}
}

View file

@ -1,9 +1,5 @@
<?php
/**
* Base controller class.
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
@ -145,7 +141,6 @@ class Controller extends Object implements CakeEventListener {
*/
public $viewVars = array();
/**
* The name of the view file to render. The name specified
* is the filename in /app/View/<SubFolder> without the .ctp extension.
@ -476,7 +471,9 @@ class Controller extends Object implements CakeEventListener {
*
* @param CakeRequest $request
* @return mixed The resulting response.
* @throws PrivateActionException, MissingActionException
* @throws PrivateActionException When actions are not public or prefixed by _
* @throws MissingActionException When actions are not defined and scaffolding is
* not enabled.
*/
public function invokeAction(CakeRequest $request) {
try {

View file

@ -125,7 +125,7 @@ class Scaffold {
$this->ScaffoldModel = $this->controller->{$this->modelClass};
$this->scaffoldTitle = Inflector::humanize(Inflector::underscore($this->viewPath));
$this->scaffoldActions = $controller->scaffold;
$title_for_layout = __d('cake', 'Scaffold :: ') . Inflector::humanize($request->action) . ' :: ' . $this->scaffoldTitle;
$title = __d('cake', 'Scaffold :: ') . Inflector::humanize($request->action) . ' :: ' . $this->scaffoldTitle;
$modelClass = $this->controller->modelClass;
$primaryKey = $this->ScaffoldModel->primaryKey;
$displayField = $this->ScaffoldModel->displayField;
@ -140,6 +140,7 @@ class Scaffold {
'title_for_layout', 'modelClass', 'primaryKey', 'displayField', 'singularVar', 'pluralVar',
'singularHumanName', 'pluralHumanName', 'scaffoldFields', 'associations'
));
$this->set('title_for_layout', $title);
if ($this->controller->viewClass) {
$this->controller->viewClass = 'Scaffold';
@ -287,7 +288,8 @@ class Scaffold {
*
* @param CakeRequest $request Request for scaffolding
* @return mixed Success on delete, error if delete fails
* @throws MethodNotAllowedException, NotFoundException
* @throws MethodNotAllowedException When HTTP method is not a DELETE
* @throws NotFoundException When id being deleted does not exist.
*/
protected function _scaffoldDelete(CakeRequest $request) {
if ($this->controller->beforeScaffold('delete')) {
@ -350,7 +352,8 @@ class Scaffold {
*
* @param CakeRequest $request Request object for scaffolding
* @return mixed A rendered view of scaffold action, or showing the error
* @throws MissingActionException, MissingDatabaseException
* @throws MissingActionException When methods are not scaffolded.
* @throws MissingDatabaseException When the database connection is undefined.
*/
protected function _scaffold(CakeRequest $request) {
$db = ConnectionManager::getDataSource($this->ScaffoldModel->useDbConfig);
@ -440,4 +443,5 @@ class Scaffold {
}
return $associations;
}
}