diff --git a/application/clicommands/AutocompleteCommand.php b/application/clicommands/AutocompleteCommand.php index a407153f4..538d7c4d6 100644 --- a/application/clicommands/AutocompleteCommand.php +++ b/application/clicommands/AutocompleteCommand.php @@ -55,7 +55,7 @@ class AutocompleteCommand extends Command $search_word = $bare_params[$cword]; if ($search_word === '--') { // TODO: Unfinished, completion missing - return $this->suggest(array('--verbose', '--help', '--debug')); + return $this->suggest(['--verbose', '--help', '--debug']); } $search = $params->shift(); @@ -68,7 +68,7 @@ class AutocompleteCommand extends Command if ($found) { // Do not return suggestions if we are already on the next word: if ($bare_params[$cword] === $search) { - return $this->suggest(array($found)); + return $this->suggest([$found]); } } else { return $this->suggest($loader->getLastSuggestions()); @@ -90,7 +90,7 @@ class AutocompleteCommand extends Command if ($command) { // Do not return suggestions if we are already on the next word: if ($bare_params[$cword] === $search) { - return $this->suggest(array($command)); + return $this->suggest([$command]); } $obj = $loader->getModuleCommandInstance( $module, @@ -112,7 +112,7 @@ class AutocompleteCommand extends Command ); if ($action) { if ($bare_params[$cword] === $search) { - return $this->suggest(array($action)); + return $this->suggest([$action]); } } else { return $this->suggest($loader->getLastSuggestions()); diff --git a/application/clicommands/ModuleCommand.php b/application/clicommands/ModuleCommand.php index 2bb6796ec..0ebe1ecba 100644 --- a/application/clicommands/ModuleCommand.php +++ b/application/clicommands/ModuleCommand.php @@ -40,7 +40,7 @@ class ModuleCommand extends Command public function listAction() { if ($type = $this->params->shift()) { - if (! in_array($type, array('enabled', 'installed'))) { + if (! in_array($type, ['enabled', 'installed'])) { return $this->showUsage(); } } else { diff --git a/application/controllers/AboutController.php b/application/controllers/AboutController.php index 919351f65..94c8b9698 100644 --- a/application/controllers/AboutController.php +++ b/application/controllers/AboutController.php @@ -19,11 +19,11 @@ class AboutController extends Controller $this->view->title = $this->translate('About'); $this->view->tabs = $this->getTabs()->add( 'about', - array( + [ 'label' => $this->translate('About'), 'title' => $this->translate('About Icinga Web 2'), 'url' => 'about' - ) + ] )->activate('about'); } } diff --git a/application/controllers/AccountController.php b/application/controllers/AccountController.php index 40c60a408..0a85e8e0e 100644 --- a/application/controllers/AccountController.php +++ b/application/controllers/AccountController.php @@ -25,23 +25,23 @@ class AccountController extends Controller public function init() { $this->getTabs() - ->add('account', array( + ->add('account', [ 'title' => $this->translate('Update your account'), 'label' => $this->translate('My Account'), 'url' => 'account' - )) - ->add('navigation', array( + ]) + ->add('navigation', [ 'title' => $this->translate('List and configure your own navigation items'), 'label' => $this->translate('Navigation'), 'url' => 'navigation' - )) + ]) ->add( 'devices', - array( + [ 'title' => $this->translate('List of devices you are logged in'), 'label' => $this->translate('My Devices'), 'url' => 'my-devices' - ) + ] ); } @@ -72,9 +72,9 @@ class AccountController extends Controller $form = new PreferenceForm(); $form->setPreferences($user->getPreferences()); if (isset($config->config_resource)) { - $form->setStore(PreferencesStore::create(new ConfigObject(array( - 'resource' => $config->config_resource - )), $user)); + $form->setStore(PreferencesStore::create(new ConfigObject([ + 'resource' => $config->config_resource + ]), $user)); } $form->handleRequest(); diff --git a/application/controllers/AnnouncementsController.php b/application/controllers/AnnouncementsController.php index 7942ff5e2..12df103fc 100644 --- a/application/controllers/AnnouncementsController.php +++ b/application/controllers/AnnouncementsController.php @@ -28,12 +28,12 @@ class AnnouncementsController extends Controller { $this->getTabs()->add( 'announcements', - array( + [ 'active' => true, 'label' => $this->translate('Announcements'), 'title' => $this->translate('List All Announcements'), 'url' => Url::fromPath('announcements') - ) + ] ); $announcements = (new AnnouncementIniRepository()) diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php index 7a1246fa8..33f9fb793 100644 --- a/application/controllers/ConfigController.php +++ b/application/controllers/ConfigController.php @@ -38,30 +38,30 @@ class ConfigController extends Controller { $tabs = $this->getTabs(); if ($this->hasPermission('config/general')) { - $tabs->add('general', array( + $tabs->add('general', [ 'title' => $this->translate('Adjust the general configuration of Icinga Web 2'), 'label' => $this->translate('General'), 'url' => 'config/general', 'baseTarget' => '_main' - )); + ]); } if ($this->hasPermission('config/resources')) { - $tabs->add('resource', array( + $tabs->add('resource', [ 'title' => $this->translate('Configure which resources are being utilized by Icinga Web 2'), 'label' => $this->translate('Resources'), 'url' => 'config/resource', 'baseTarget' => '_main' - )); + ]); } if ($this->hasPermission('config/access-control/users') || $this->hasPermission('config/access-control/groups') ) { - $tabs->add('authentication', array( + $tabs->add('authentication', [ 'title' => $this->translate('Configure the user and group backends'), 'label' => $this->translate('Access Control Backends'), 'url' => 'config/userbackend', 'baseTarget' => '_main' - )); + ]); } return $tabs; @@ -125,11 +125,11 @@ class ConfigController extends Controller // Overwrite tabs created in init // @TODO(el): This seems not natural to me. Module configuration should have its own controller. $this->view->tabs = Widget::create('tabs') - ->add('modules', array( + ->add('modules', [ 'label' => $this->translate('Modules'), 'title' => $this->translate('List intalled modules'), 'url' => 'config/modules' - )) + ]) ->activate('modules'); $this->view->modules = Icinga::app()->getModuleManager()->select() ->from('modules') @@ -418,10 +418,10 @@ class ConfigController extends Controller public function createresourceAction() { $this->assertPermission('config/resources'); - $this->getTabs()->add('resources/new', array( + $this->getTabs()->add('resources/new', [ 'label' => $this->translate('New Resource'), 'url' => Url::fromRequest() - ))->activate('resources/new'); + ])->activate('resources/new'); $form = new ResourceConfigForm(); $form->addDescription($this->translate('Resources are entities that provide data to Icinga Web 2.')); $form->setIniConfig(Config::app('resources')); @@ -439,10 +439,10 @@ class ConfigController extends Controller public function editresourceAction() { $this->assertPermission('config/resources'); - $this->getTabs()->add('resources/update', array( + $this->getTabs()->add('resources/update', [ 'label' => $this->translate('Update Resource'), 'url' => Url::fromRequest() - ))->activate('resources/update'); + ])->activate('resources/update'); $form = new ResourceConfigForm(); $form->setIniConfig(Config::app('resources')); $form->setRedirectUrl('config/resource'); @@ -459,11 +459,11 @@ class ConfigController extends Controller public function removeresourceAction() { $this->assertPermission('config/resources'); - $this->getTabs()->add('resources/remove', array( + $this->getTabs()->add('resources/remove', [ 'label' => $this->translate('Remove Resource'), 'url' => Url::fromRequest() - ))->activate('resources/remove'); - $form = new ConfirmRemovalForm(array( + ])->activate('resources/remove'); + $form = new ConfirmRemovalForm([ 'onSuccess' => function ($form) { $configForm = new ResourceConfigForm(); $configForm->setIniConfig(Config::app('resources')); @@ -482,7 +482,7 @@ class ConfigController extends Controller return false; } } - )); + ]); $form->setRedirectUrl('config/resource'); $form->handleRequest(); diff --git a/application/controllers/DashboardController.php b/application/controllers/DashboardController.php index dd70f13ea..1ebda46d7 100644 --- a/application/controllers/DashboardController.php +++ b/application/controllers/DashboardController.php @@ -40,11 +40,11 @@ class DashboardController extends ActionController public function newDashletAction() { $form = new DashletForm(); - $this->getTabs()->add('new-dashlet', array( + $this->getTabs()->add('new-dashlet', [ 'active' => true, 'label' => $this->translate('New Dashlet'), 'url' => Url::fromRequest() - )); + ]); $dashboard = $this->dashboard; $form->setDashboard($dashboard); if ($this->_request->getParam('url')) { @@ -84,11 +84,11 @@ class DashboardController extends ActionController public function updateDashletAction() { - $this->getTabs()->add('update-dashlet', array( + $this->getTabs()->add('update-dashlet', [ 'active' => true, 'label' => $this->translate('Update Dashlet'), 'url' => Url::fromRequest() - )); + ]); $dashboard = $this->dashboard; $form = new DashletForm(); $form->setDashboard($dashboard); @@ -149,11 +149,11 @@ class DashboardController extends ActionController public function removeDashletAction() { $form = new ConfirmRemovalForm(); - $this->getTabs()->add('remove-dashlet', array( + $this->getTabs()->add('remove-dashlet', [ 'active' => true, 'label' => $this->translate('Remove Dashlet'), 'url' => Url::fromRequest() - )); + ]); $dashboard = $this->dashboard; if (! $this->_request->getParam('pane')) { throw new Zend_Controller_Action_Exception( @@ -205,23 +205,23 @@ class DashboardController extends ActionController $form->addElement( 'text', 'name', - array( + [ 'required' => true, 'label' => $this->translate('Name') - ) + ] ); $form->addElement( 'text', 'title', - array( + [ 'required' => true, 'label' => $this->translate('Title') - ) + ] ); - $form->setDefaults(array( + $form->setDefaults([ 'name' => $paneName, 'title' => $this->dashboard->getPane($paneName)->getTitle() - )); + ]); $form->setOnSuccess(function ($form) use ($paneName) { $newName = $form->getValue('name'); $newTitle = $form->getValue('title'); @@ -241,10 +241,10 @@ class DashboardController extends ActionController $this->view->form = $form; $this->getTabs()->add( 'update-pane', - array( + [ 'title' => $this->translate('Update Pane'), 'url' => $this->getRequest()->getUrl() - ) + ] )->activate('update-pane'); } @@ -306,11 +306,11 @@ class DashboardController extends ActionController ); if (empty($panes)) { $this->view->title = 'Dashboard'; - $this->getTabs()->add('dashboard', array( + $this->getTabs()->add('dashboard', [ 'active' => true, 'title' => $this->translate('Dashboard'), 'url' => Url::fromRequest() - )); + ]); } else { if ($this->_getParam('pane')) { $pane = $this->_getParam('pane'); diff --git a/application/controllers/ErrorController.php b/application/controllers/ErrorController.php index 0aeb33d69..c744907ff 100644 --- a/application/controllers/ErrorController.php +++ b/application/controllers/ErrorController.php @@ -65,7 +65,7 @@ class ErrorController extends ActionController case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER: case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION: $this->getResponse()->setHttpResponseCode(404); - $this->view->messages = array($this->translate('Page not found.')); + $this->view->messages = [$this->translate('Page not found.')]; if ($isAuthenticated) { if ($modules->hasInstalled($moduleName) && ! $modules->hasEnabled($moduleName)) { $this->view->messages[0] .= ' ' . sprintf( @@ -136,10 +136,10 @@ class ErrorController extends ActionController } } - $this->view->messages = array(); + $this->view->messages = []; if ($this->getInvokeArg('displayExceptions')) { - $this->view->stackTraces = array(); + $this->view->stackTraces = []; do { $this->view->messages[] = $exception->getMessage(); @@ -168,11 +168,11 @@ class ErrorController extends ActionController $this->view->hideControls = true; } else { $this->view->hideControls = false; - $this->getTabs()->add('error', array( + $this->getTabs()->add('error', [ 'active' => true, 'label' => $this->translate('Error'), 'url' => Url::fromRequest() - )); + ]); } } } diff --git a/application/controllers/GroupController.php b/application/controllers/GroupController.php index 3c398a687..d000600d3 100644 --- a/application/controllers/GroupController.php +++ b/application/controllers/GroupController.php @@ -55,12 +55,12 @@ class GroupController extends AuthBackendController $this->view->backendSelection->addElement( 'select', 'backend', - array( + [ 'autosubmit' => true, 'label' => $this->translate('User Group Backend'), 'multiOptions' => array_combine($backendNames, $backendNames), 'value' => $this->params->get('backend') - ) + ] ); $backend = $this->getUserGroupBackend($this->params->get('backend')); @@ -69,7 +69,7 @@ class GroupController extends AuthBackendController return; } - $query = $backend->select(array('group_name')); + $query = $backend->select(['group_name']); $this->view->groups = $query; $this->view->backend = $backend; @@ -78,11 +78,11 @@ class GroupController extends AuthBackendController $this->setupFilterControl($query); $this->setupLimitControl(); $this->setupSortControl( - array( + [ 'group_name' => $this->translate('User Group'), 'created_at' => $this->translate('Created at'), 'last_modified' => $this->translate('Last modified') - ), + ], $query ); } @@ -96,29 +96,29 @@ class GroupController extends AuthBackendController $groupName = $this->params->getRequired('group'); $backend = $this->getUserGroupBackend($this->params->getRequired('backend')); - $group = $backend->select(array( + $group = $backend->select([ 'group_name', 'created_at', 'last_modified' - ))->where('group_name', $groupName)->fetchRow(); + ])->where('group_name', $groupName)->fetchRow(); if ($group === false) { $this->httpNotFound(sprintf($this->translate('Group "%s" not found'), $groupName)); } $members = $backend ->select() - ->from('group_membership', array('user_name')) + ->from('group_membership', ['user_name']) ->where('group_name', $groupName); - $this->setupFilterControl($members, null, array('user'), array('group')); + $this->setupFilterControl($members, null, ['user'], ['group']); $this->setupPaginationControl($members); $this->setupLimitControl(); $this->setupSortControl( - array( + [ 'user_name' => $this->translate('Username'), 'created_at' => $this->translate('Created at'), 'last_modified' => $this->translate('Last modified') - ), + ], $members ); @@ -132,28 +132,28 @@ class GroupController extends AuthBackendController $removeForm->setUidDisabled(); $removeForm->setAttrib('class', 'inline'); $removeForm->setAction( - Url::fromPath('group/removemember', array('backend' => $backend->getName(), 'group' => $groupName)) + Url::fromPath('group/removemember', ['backend' => $backend->getName(), 'group' => $groupName]) ); - $removeForm->addElement('hidden', 'user_name', array( + $removeForm->addElement('hidden', 'user_name', [ 'isArray' => true, - 'decorators' => array('ViewHelper') - )); - $removeForm->addElement('hidden', 'redirect', array( - 'value' => Url::fromPath('group/show', array( + 'decorators' => ['ViewHelper'] + ]); + $removeForm->addElement('hidden', 'redirect', [ + 'value' => Url::fromPath('group/show', [ 'backend' => $backend->getName(), 'group' => $groupName - )), - 'decorators' => array('ViewHelper') - )); - $removeForm->addElement('button', 'btn_submit', array( + ]), + 'decorators' => ['ViewHelper'] + ]); + $removeForm->addElement('button', 'btn_submit', [ 'escape' => false, 'type' => 'submit', 'class' => 'link-button spinner', 'value' => 'btn_submit', - 'decorators' => array('ViewHelper'), + 'decorators' => ['ViewHelper'], 'label' => $this->view->icon('cancel'), 'title' => $this->translate('Remove this member') - )); + ]); $this->view->removeForm = $removeForm; } } @@ -166,7 +166,7 @@ class GroupController extends AuthBackendController $this->assertPermission('config/access-control/groups'); $backend = $this->getUserGroupBackend($this->params->getRequired('backend'), 'Icinga\Data\Extensible'); $form = new UserGroupForm(); - $form->setRedirectUrl(Url::fromPath('group/list', array('backend' => $backend->getName()))); + $form->setRedirectUrl(Url::fromPath('group/list', ['backend' => $backend->getName()])); $form->setRepository($backend); $form->add()->handleRequest(); @@ -184,7 +184,7 @@ class GroupController extends AuthBackendController $form = new UserGroupForm(); $form->setRedirectUrl( - Url::fromPath('group/show', array('backend' => $backend->getName(), 'group' => $groupName)) + Url::fromPath('group/show', ['backend' => $backend->getName(), 'group' => $groupName]) ); $form->setRepository($backend); @@ -207,7 +207,7 @@ class GroupController extends AuthBackendController $backend = $this->getUserGroupBackend($this->params->getRequired('backend'), 'Icinga\Data\Reducible'); $form = new UserGroupForm(); - $form->setRedirectUrl(Url::fromPath('group/list', array('backend' => $backend->getName()))); + $form->setRedirectUrl(Url::fromPath('group/list', ['backend' => $backend->getName()])); $form->setRepository($backend); try { @@ -233,7 +233,7 @@ class GroupController extends AuthBackendController ->setBackend($backend) ->setGroupName($groupName) ->setRedirectUrl( - Url::fromPath('group/show', array('backend' => $backend->getName(), 'group' => $groupName)) + Url::fromPath('group/show', ['backend' => $backend->getName(), 'group' => $groupName]) ) ->setUidDisabled(); @@ -256,7 +256,7 @@ class GroupController extends AuthBackendController $groupName = $this->params->getRequired('group'); $backend = $this->getUserGroupBackend($this->params->getRequired('backend'), 'Icinga\Data\Reducible'); - $form = new Form(array( + $form = new Form([ 'onSuccess' => function ($form) use ($groupName, $backend) { foreach ($form->getValue('user_name') as $userName) { try { @@ -286,10 +286,10 @@ class GroupController extends AuthBackendController return true; } - )); + ]); $form->setUidDisabled(); $form->setSubmitLabel('btn_submit'); // Required to ensure that isSubmitted() is called - $form->addElement('hidden', 'user_name', array('required' => true, 'isArray' => true)); + $form->addElement('hidden', 'user_name', ['required' => true, 'isArray' => true]); $form->addElement('hidden', 'redirect'); try { @@ -306,7 +306,7 @@ class GroupController extends AuthBackendController */ protected function fetchUsers() { - $users = array(); + $users = []; foreach ($this->loadUserBackends('Icinga\Data\Selectable') as $backend) { try { if ($backend instanceof DomainAwareInterface) { @@ -314,7 +314,7 @@ class GroupController extends AuthBackendController } else { $domain = null; } - foreach ($backend->select(array('user_name')) as $user) { + foreach ($backend->select(['user_name']) as $user) { $userObj = new User($user->user_name); if ($domain !== null) { if ($userObj->hasDomain() && $userObj->getDomain() !== $domain) { @@ -354,11 +354,11 @@ class GroupController extends AuthBackendController $tabs = $this->getTabs(); $tabs->add( 'group/show', - array( + [ 'title' => sprintf($this->translate('Show group %s'), $groupName), 'label' => $this->translate('Group'), - 'url' => Url::fromPath('group/show', array('backend' => $backendName, 'group' => $groupName)) - ) + 'url' => Url::fromPath('group/show', ['backend' => $backendName, 'group' => $groupName]) + ] ); return $tabs; @@ -374,14 +374,14 @@ class GroupController extends AuthBackendController if ($this->hasPermission('config/access-control/roles')) { $tabs->add( 'role/list', - array( + [ 'baseTarget' => '_main', 'label' => $this->translate('Roles'), 'title' => $this->translate( 'Configure roles to permit or restrict users and groups accessing Icinga Web 2' ), 'url' => 'role/list' - ) + ] ); $tabs->add( @@ -398,21 +398,21 @@ class GroupController extends AuthBackendController if ($this->hasPermission('config/access-control/users')) { $tabs->add( 'user/list', - array( + [ 'title' => $this->translate('List users of authentication backends'), 'label' => $this->translate('Users'), 'url' => 'user/list' - ) + ] ); } $tabs->add( 'group/list', - array( + [ 'title' => $this->translate('List groups of user group backends'), 'label' => $this->translate('User Groups'), 'url' => 'group/list' - ) + ] ); return $tabs; diff --git a/application/controllers/ListController.php b/application/controllers/ListController.php index bfed72a1c..dfdba0afe 100644 --- a/application/controllers/ListController.php +++ b/application/controllers/ListController.php @@ -27,10 +27,10 @@ class ListController extends Controller */ protected function addTitleTab($action) { - $this->getTabs()->add($action, array( + $this->getTabs()->add($action, [ 'label' => ucfirst($action), 'url' => Url::fromPath('list/' . str_replace(' ', '', $action)) - ))->extend(new OutputFormat())->extend(new DashboardAction())->extend(new MenuAction())->activate($action); + ])->extend(new OutputFormat())->extend(new DashboardAction())->extend(new MenuAction())->activate($action); } /** @@ -46,12 +46,12 @@ class ListController extends Controller $this->addTitleTab('application log'); - $resource = new FileReader(new ConfigObject(array( + $resource = new FileReader(new ConfigObject([ 'filename' => Config::app()->get('logging', 'file'), 'fields' => '/(?[0-9]{4}(?:-[0-9]{2}){2}' // date . 'T[0-9]{2}(?::[0-9]{2}){2}(?:[\+\-][0-9]{2}:[0-9]{2})?)' // time . ' - (?[A-Za-z]+) - (?.*)(?!.)/msS' // loglevel, message - ))); + ])); $this->view->logData = $resource->select()->order('DESC'); $this->setupLimitControl(); diff --git a/application/controllers/ManageUserDevicesController.php b/application/controllers/ManageUserDevicesController.php index 97e89ca93..414c581de 100644 --- a/application/controllers/ManageUserDevicesController.php +++ b/application/controllers/ManageUserDevicesController.php @@ -32,12 +32,12 @@ class ManageUserDevicesController extends CompatController $this->getTabs() ->add( 'manage-user-devices', - array( + [ 'title' => $this->translate('List of users who stay logged in'), 'label' => $this->translate('Users'), 'url' => 'manage-user-devices', 'data-base-target' => '_self' - ) + ] )->activate('manage-user-devices'); $usersList = (new RememberMeUserList()) @@ -58,11 +58,11 @@ class ManageUserDevicesController extends CompatController $this->getTabs() ->add( 'manage-devices', - array( + [ 'title' => $this->translate('List of devices'), 'label' => $this->translate('Devices'), 'url' => 'manage-user-devices/devices' - ) + ] )->activate('manage-devices'); $name = $this->params->getRequired('name'); diff --git a/application/controllers/MyDevicesController.php b/application/controllers/MyDevicesController.php index dc01558d7..22337da8b 100644 --- a/application/controllers/MyDevicesController.php +++ b/application/controllers/MyDevicesController.php @@ -25,27 +25,27 @@ class MyDevicesController extends CompatController $this->getTabs() ->add( 'account', - array( + [ 'title' => $this->translate('Update your account'), 'label' => $this->translate('My Account'), 'url' => 'account' - ) + ] ) ->add( 'navigation', - array( + [ 'title' => $this->translate('List and configure your own navigation items'), 'label' => $this->translate('Navigation'), 'url' => 'navigation' - ) + ] ) ->add( 'devices', - array( + [ 'title' => $this->translate('List of devices you are logged in'), 'label' => $this->translate('My Devices'), 'url' => 'my-devices' - ) + ] )->activate('devices'); } diff --git a/application/controllers/NavigationController.php b/application/controllers/NavigationController.php index 66b3b1d54..48731c3b3 100644 --- a/application/controllers/NavigationController.php +++ b/application/controllers/NavigationController.php @@ -59,7 +59,7 @@ class NavigationController extends Controller */ protected function listItemTypes() { - $types = array(); + $types = []; foreach ($this->itemTypeConfig as $type => $options) { $types[$type] = isset($options['label']) ? $options['label'] : $type; } @@ -76,7 +76,7 @@ class NavigationController extends Controller */ protected function fetchSharedNavigationItemConfigs($owner = null) { - $configs = array(); + $configs = []; foreach ($this->itemTypeConfig as $type => $_) { $config = Config::navigation($type); $config->getConfigObject()->setKeyColumn('name'); @@ -102,7 +102,7 @@ class NavigationController extends Controller */ protected function fetchUserNavigationItemConfigs($username) { - $configs = array(); + $configs = []; foreach ($this->itemTypeConfig as $type => $_) { $config = Config::navigation($type, $username); $config->getConfigObject()->setKeyColumn('name'); @@ -133,35 +133,35 @@ class NavigationController extends Controller $this->getTabs() ->add( 'account', - array( + [ 'title' => $this->translate('Update your account'), 'label' => $this->translate('My Account'), 'url' => 'account' - ) + ] ) ->add( 'navigation', - array( + [ 'active' => true, 'title' => $this->translate('List and configure your own navigation items'), 'label' => $this->translate('Navigation'), 'url' => 'navigation' - ) + ] ) ->add( 'devices', - array( + [ 'title' => $this->translate('List of devices you are logged in'), 'label' => $this->translate('My Devices'), 'url' => 'my-devices' - ) + ] ); $this->setupSortControl( - array( + [ 'type' => $this->translate('Type'), 'owner' => $this->translate('Shared'), 'name' => $this->translate('Navigation') - ), + ], $query ); } @@ -178,22 +178,22 @@ class NavigationController extends Controller $removeForm = new Form(); $removeForm->setUidDisabled(); $removeForm->setAttrib('class', 'inline'); - $removeForm->addElement('hidden', 'name', array( - 'decorators' => array('ViewHelper') - )); - $removeForm->addElement('hidden', 'redirect', array( + $removeForm->addElement('hidden', 'name', [ + 'decorators' => ['ViewHelper'] + ]); + $removeForm->addElement('hidden', 'redirect', [ 'value' => Url::fromPath('navigation/shared'), - 'decorators' => array('ViewHelper') - )); - $removeForm->addElement('button', 'btn_submit', array( + 'decorators' => ['ViewHelper'] + ]); + $removeForm->addElement('button', 'btn_submit', [ 'escape' => false, 'type' => 'submit', 'class' => 'link-button spinner', 'value' => 'btn_submit', - 'decorators' => array('ViewHelper'), + 'decorators' => ['ViewHelper'], 'label' => $this->view->icon('cancel'), 'title' => $this->translate('Unshare this navigation item') - )); + ]); $this->view->removeForm = $removeForm; $this->view->types = $this->listItemTypes(); @@ -202,18 +202,18 @@ class NavigationController extends Controller $this->view->title = $this->translate('Shared Navigation'); $this->getTabs()->add( 'navigation/shared', - array( + [ 'title' => $this->translate('List and configure shared navigation items'), 'label' => $this->translate('Shared Navigation'), 'url' => 'navigation/shared' - ) + ] )->activate('navigation/shared'); $this->setupSortControl( - array( + [ 'type' => $this->translate('Type'), 'owner' => $this->translate('Owner'), 'name' => $this->translate('Shared Navigation') - ), + ], $query ); } @@ -376,7 +376,7 @@ class NavigationController extends Controller $navigationConfigForm->setShareConfig(Config::navigation($itemType)); $navigationConfigForm->setUserConfig(Config::navigation($itemType, $itemOwner)); - $form = new Form(array( + $form = new Form([ 'onSuccess' => function ($form) use ($navigationConfigForm) { $itemName = $form->getValue('name'); @@ -412,10 +412,10 @@ class NavigationController extends Controller return true; } - )); + ]); $form->setUidDisabled(); $form->setSubmitLabel('btn_submit'); // Required to ensure that isSubmitted() is called - $form->addElement('hidden', 'name', array('required' => true)); + $form->addElement('hidden', 'name', ['required' => true]); $form->addElement('hidden', 'redirect'); try { @@ -429,11 +429,11 @@ class NavigationController extends Controller { $name = $this->params->getRequired('name'); - $this->getTabs()->add('dashboard', array( + $this->getTabs()->add('dashboard', [ 'active' => true, 'label' => ucwords($name), 'url' => Url::fromRequest() - )); + ]); $menu = new Menu(); diff --git a/application/controllers/RoleController.php b/application/controllers/RoleController.php index 232305db4..ca483331b 100644 --- a/application/controllers/RoleController.php +++ b/application/controllers/RoleController.php @@ -345,14 +345,14 @@ class RoleController extends AuthBackendController $tabs = $this->getTabs(); $tabs->add( 'role/list', - array( + [ 'baseTarget' => '_main', 'label' => $this->translate('Roles'), 'title' => $this->translate( 'Configure roles to permit or restrict users and groups accessing Icinga Web 2' ), 'url' => 'role/list' - ) + ] ); $tabs->add( @@ -368,22 +368,22 @@ class RoleController extends AuthBackendController if ($this->hasPermission('config/access-control/users')) { $tabs->add( 'user/list', - array( + [ 'title' => $this->translate('List users of authentication backends'), 'label' => $this->translate('Users'), 'url' => 'user/list' - ) + ] ); } if ($this->hasPermission('config/access-control/groups')) { $tabs->add( 'group/list', - array( + [ 'title' => $this->translate('List groups of user group backends'), 'label' => $this->translate('User Groups'), 'url' => 'group/list' - ) + ] ); } diff --git a/application/controllers/UserController.php b/application/controllers/UserController.php index 3d069ec4e..9aaf331b8 100644 --- a/application/controllers/UserController.php +++ b/application/controllers/UserController.php @@ -55,12 +55,12 @@ class UserController extends AuthBackendController $this->view->backendSelection->addElement( 'select', 'backend', - array( + [ 'autosubmit' => true, 'label' => $this->translate('User Backend'), 'multiOptions' => array_combine($backendNames, $backendNames), 'value' => $this->params->get('backend') - ) + ] ); $backend = $this->getUserBackend($this->params->get('backend')); @@ -69,7 +69,7 @@ class UserController extends AuthBackendController return; } - $query = $backend->select(array('user_name')); + $query = $backend->select(['user_name']); $this->view->users = $query; $this->view->backend = $backend; @@ -78,12 +78,12 @@ class UserController extends AuthBackendController $this->setupFilterControl($query); $this->setupLimitControl(); $this->setupSortControl( - array( + [ 'user_name' => $this->translate('Username'), 'is_active' => $this->translate('Active'), 'created_at' => $this->translate('Created at'), 'last_modified' => $this->translate('Last modified') - ), + ], $query ); } @@ -97,12 +97,12 @@ class UserController extends AuthBackendController $userName = $this->params->getRequired('user'); $backend = $this->getUserBackend($this->params->getRequired('backend')); - $user = $backend->select(array( + $user = $backend->select([ 'user_name', 'is_active', 'created_at', 'last_modified' - ))->where('user_name', $userName)->fetchRow(); + ])->where('user_name', $userName)->fetchRow(); if ($user === false) { $this->httpNotFound(sprintf($this->translate('User "%s" not found'), $userName)); } @@ -116,16 +116,16 @@ class UserController extends AuthBackendController $this->setupFilterControl( $memberships, - array('group_name' => t('User Group')), - array('group'), - array('user') + ['group_name' => t('User Group')], + ['group'], + ['user'] ); $this->setupPaginationControl($memberships); $this->setupLimitControl(); $this->setupSortControl( - array( + [ 'group_name' => $this->translate('Group') - ), + ], $memberships ); @@ -145,27 +145,27 @@ class UserController extends AuthBackendController $removeForm = new Form(); $removeForm->setUidDisabled(); $removeForm->setAttrib('class', 'inline'); - $removeForm->addElement('hidden', 'user_name', array( + $removeForm->addElement('hidden', 'user_name', [ 'isArray' => true, 'value' => $userName, - 'decorators' => array('ViewHelper') - )); - $removeForm->addElement('hidden', 'redirect', array( - 'value' => Url::fromPath('user/show', array( + 'decorators' => ['ViewHelper'] + ]); + $removeForm->addElement('hidden', 'redirect', [ + 'value' => Url::fromPath('user/show', [ 'backend' => $backend->getName(), 'user' => $userName - )), - 'decorators' => array('ViewHelper') - )); - $removeForm->addElement('button', 'btn_submit', array( + ]), + 'decorators' => ['ViewHelper'] + ]); + $removeForm->addElement('button', 'btn_submit', [ 'escape' => false, 'type' => 'submit', 'class' => 'link-button spinner', 'value' => 'btn_submit', - 'decorators' => array('ViewHelper'), + 'decorators' => ['ViewHelper'], 'label' => $this->view->icon('cancel'), 'title' => $this->translate('Cancel this membership') - )); + ]); $this->view->removeForm = $removeForm; } @@ -183,7 +183,7 @@ class UserController extends AuthBackendController $this->assertPermission('config/access-control/users'); $backend = $this->getUserBackend($this->params->getRequired('backend'), 'Icinga\Data\Extensible'); $form = new UserForm(); - $form->setRedirectUrl(Url::fromPath('user/list', array('backend' => $backend->getName()))); + $form->setRedirectUrl(Url::fromPath('user/list', ['backend' => $backend->getName()])); $form->setRepository($backend); $form->add()->handleRequest(); @@ -200,7 +200,7 @@ class UserController extends AuthBackendController $backend = $this->getUserBackend($this->params->getRequired('backend'), 'Icinga\Data\Updatable'); $form = new UserForm(); - $form->setRedirectUrl(Url::fromPath('user/show', array('backend' => $backend->getName(), 'user' => $userName))); + $form->setRedirectUrl(Url::fromPath('user/show', ['backend' => $backend->getName(), 'user' => $userName])); $form->setRepository($backend); try { @@ -222,7 +222,7 @@ class UserController extends AuthBackendController $backend = $this->getUserBackend($this->params->getRequired('backend'), 'Icinga\Data\Reducible'); $form = new UserForm(); - $form->setRedirectUrl(Url::fromPath('user/list', array('backend' => $backend->getName()))); + $form->setRedirectUrl(Url::fromPath('user/list', ['backend' => $backend->getName()])); $form->setRepository($backend); try { @@ -257,7 +257,7 @@ class UserController extends AuthBackendController $form = new CreateMembershipForm(); $form->setBackends($backends) ->setUsername($userName) - ->setRedirectUrl(Url::fromPath('user/show', array('backend' => $backend->getName(), 'user' => $userName))) + ->setRedirectUrl(Url::fromPath('user/show', ['backend' => $backend->getName(), 'user' => $userName])) ->handleRequest(); $this->renderForm($form, $this->translate('Create New Membership')); @@ -272,7 +272,7 @@ class UserController extends AuthBackendController */ protected function loadMemberships(User $user) { - $groups = $alreadySeen = array(); + $groups = $alreadySeen = []; foreach ($this->loadUserGroupBackends() as $backend) { try { foreach ($backend->getMemberships($user) as $groupName) { @@ -281,11 +281,11 @@ class UserController extends AuthBackendController } $alreadySeen[$groupName] = null; - $groups[] = (object) array( + $groups[] = (object) [ 'group_name' => $groupName, 'group' => $groupName, 'backend' => $backend - ); + ]; } } catch (Exception $e) { Logger::error($e); @@ -310,11 +310,11 @@ class UserController extends AuthBackendController $tabs = $this->getTabs(); $tabs->add( 'user/show', - array( + [ 'title' => sprintf($this->translate('Show user %s'), $userName), 'label' => $this->translate('User'), - 'url' => Url::fromPath('user/show', array('backend' => $backendName, 'user' => $userName)) - ) + 'url' => Url::fromPath('user/show', ['backend' => $backendName, 'user' => $userName]) + ] ); return $tabs; @@ -330,14 +330,14 @@ class UserController extends AuthBackendController if ($this->hasPermission('config/access-control/roles')) { $tabs->add( 'role/list', - array( + [ 'baseTarget' => '_main', 'label' => $this->translate('Roles'), 'title' => $this->translate( 'Configure roles to permit or restrict users and groups accessing Icinga Web 2' ), 'url' => 'role/list' - ) + ] ); $tabs->add( @@ -353,21 +353,21 @@ class UserController extends AuthBackendController $tabs->add( 'user/list', - array( + [ 'title' => $this->translate('List users of authentication backends'), 'label' => $this->translate('Users'), 'url' => 'user/list' - ) + ] ); if ($this->hasPermission('config/access-control/groups')) { $tabs->add( 'group/list', - array( + [ 'title' => $this->translate('List groups of user group backends'), 'label' => $this->translate('User Groups'), 'url' => 'group/list' - ) + ] ); } diff --git a/application/forms/Account/ChangePasswordForm.php b/application/forms/Account/ChangePasswordForm.php index c49684af9..cdf222b60 100644 --- a/application/forms/Account/ChangePasswordForm.php +++ b/application/forms/Account/ChangePasswordForm.php @@ -39,29 +39,29 @@ class ChangePasswordForm extends Form $this->addElement( 'password', 'old_password', - array( + [ 'label' => $this->translate('Old Password'), 'required' => true - ) + ] ); $this->addElement( 'password', 'new_password', - array( + [ 'label' => $this->translate('New Password'), 'required' => true - ) + ] ); $this->addElement( 'password', 'new_password_confirmation', - array( + [ 'label' => $this->translate('Confirm New Password'), 'required' => true, - 'validators' => array( - array('identical', false, array('new_password')) - ) - ) + 'validators' => [ + ['identical', false, ['new_password']] + ] + ] ); } @@ -73,7 +73,7 @@ class ChangePasswordForm extends Form $backend = $this->getBackend(); $backend->update( $backend->getBaseTable(), - array('password' => $this->getElement('new_password')->getValue()), + ['password' => $this->getElement('new_password')->getValue()], Filter::where('user_name', $this->Auth()->getUser()->getUsername()) ); Notification::success($this->translate('Account updated')); diff --git a/application/forms/Announcement/AcknowledgeAnnouncementForm.php b/application/forms/Announcement/AcknowledgeAnnouncementForm.php index 6e8c20ab7..b71fd8087 100644 --- a/application/forms/Announcement/AcknowledgeAnnouncementForm.php +++ b/application/forms/Announcement/AcknowledgeAnnouncementForm.php @@ -31,18 +31,18 @@ class AcknowledgeAnnouncementForm extends Form $this->addElement( 'button', 'btn_submit', - array( + [ 'class' => 'link-button spinner', - 'decorators' => array( + 'decorators' => [ 'ViewHelper', - array('HtmlTag', array('tag' => 'div', 'class' => 'control-group form-controls')) - ), + ['HtmlTag', ['tag' => 'div', 'class' => 'control-group form-controls']] + ], 'escape' => false, 'ignore' => true, 'label' => $this->getView()->icon('cancel'), 'title' => $this->translate('Acknowledge this announcement'), 'type' => 'submit' - ) + ] ); return $this; } @@ -50,20 +50,20 @@ class AcknowledgeAnnouncementForm extends Form /** * {@inheritdoc} */ - public function createElements(array $formData = array()) + public function createElements(array $formData = []) { $this->addElements( - array( - array( + [ + [ 'hidden', 'hash', - array( + [ 'required' => true, - 'validators' => array('NotEmpty'), - 'decorators' => array('ViewHelper') - ) - ) - ) + 'validators' => ['NotEmpty'], + 'decorators' => ['ViewHelper'] + ] + ] + ] ); return $this; @@ -77,12 +77,12 @@ class AcknowledgeAnnouncementForm extends Form $cookie = new AnnouncementCookie(); $repo = new AnnouncementIniRepository(); $query = $repo->findActive(); - $filter = array(); + $filter = []; foreach ($cookie->getAcknowledged() as $hash) { $filter[] = Filter::expression('hash', '=', $hash); } $query->addFilter(Filter::matchAny($filter)); - $acknowledged = array(); + $acknowledged = []; foreach ($query as $row) { $acknowledged[] = $row->hash; } diff --git a/application/forms/Announcement/AnnouncementForm.php b/application/forms/Announcement/AnnouncementForm.php index cdd93165c..bbe14a6a4 100644 --- a/application/forms/Announcement/AnnouncementForm.php +++ b/application/forms/Announcement/AnnouncementForm.php @@ -38,40 +38,40 @@ class AnnouncementForm extends RepositoryForm $this->addElement( 'text', 'author', - array( + [ 'disabled' => ! $this->getRequest()->isApiRequest(), 'required' => true, 'value' => Auth::getInstance()->getUser()->getUsername() - ) + ] ); $this->addElement( 'textarea', 'message', - array( + [ 'description' => $this->translate('The message to display to users'), 'label' => $this->translate('Message'), 'required' => true - ) + ] ); $this->addElement( 'dateTimePicker', 'start', - array( + [ 'description' => $this->translate('The time to display the announcement from'), 'label' => $this->translate('Start'), 'placeholder' => new DateTime('tomorrow'), 'required' => true - ) + ] ); $this->addElement( 'dateTimePicker', 'end', - array( + [ 'description' => $this->translate('The time to display the announcement until'), 'label' => $this->translate('End'), 'placeholder' => new DateTime('tomorrow +1day'), 'required' => true - ) + ] ); $this->setTitle($this->translate('Create a new announcement')); diff --git a/application/forms/AutoRefreshForm.php b/application/forms/AutoRefreshForm.php index 49c962124..8427587b2 100644 --- a/application/forms/AutoRefreshForm.php +++ b/application/forms/AutoRefreshForm.php @@ -67,19 +67,19 @@ class AutoRefreshForm extends Form $value = $this->translate('Disable auto refresh'); } - $this->addElements(array( - array( + $this->addElements([ + [ 'button', 'btn_submit', - array( + [ 'ignore' => true, 'type' => 'submit', 'value' => $value, - 'decorators' => array('ViewHelper'), + 'decorators' => ['ViewHelper'], 'escape' => false, 'class' => 'link-like' - ) - ) - )); + ] + ] + ]); } } diff --git a/application/forms/Config/General/ApplicationConfigForm.php b/application/forms/Config/General/ApplicationConfigForm.php index 96c6a860c..c8fcd7ae3 100644 --- a/application/forms/Config/General/ApplicationConfigForm.php +++ b/application/forms/Config/General/ApplicationConfigForm.php @@ -34,27 +34,27 @@ class ApplicationConfigForm extends Form $this->addElement( 'checkbox', 'global_show_stacktraces', - array( + [ 'value' => true, 'label' => $this->translate('Show Stacktraces'), 'description' => $this->translate( 'Set whether to show an exception\'s stacktrace by default. This can also' . ' be set in a user\'s preferences with the appropriate permission.' ) - ) + ] ); $this->addElement( 'checkbox', 'global_show_application_state_messages', - array( + [ 'value' => true, 'label' => $this->translate('Show Application State Messages'), 'description' => $this->translate( "Set whether to show application state messages." . " This can also be set in a user's preferences." ) - ) + ] ); $this->addElement( @@ -72,7 +72,7 @@ class ApplicationConfigForm extends Form $this->addElement( 'text', 'global_module_path', - array( + [ 'label' => $this->translate('Module Path'), 'required' => true, 'value' => implode(':', Icinga::app()->getModuleManager()->getModuleDirs()), @@ -81,7 +81,7 @@ class ApplicationConfigForm extends Form . 'colons. Modules that don\'t exist in these directories can still be symlinked in ' . 'the module folder, but won\'t show up in the list of disabled modules.' ) - ) + ] ); $backends = array_keys(ResourceFactory::getResourceConfigs()->toArray()); @@ -90,7 +90,7 @@ class ApplicationConfigForm extends Form $this->addElement( 'select', 'global_config_resource', - array( + [ 'required' => true, 'multiOptions' => array_merge( ['' => sprintf(' - %s - ', $this->translate('Please choose'))], @@ -99,7 +99,7 @@ class ApplicationConfigForm extends Form 'disable' => [''], 'value' => '', 'label' => $this->translate('Configuration Database') - ) + ] ); return $this; diff --git a/application/forms/Config/General/DefaultAuthenticationDomainConfigForm.php b/application/forms/Config/General/DefaultAuthenticationDomainConfigForm.php index 92e1fd71b..376cf2625 100644 --- a/application/forms/Config/General/DefaultAuthenticationDomainConfigForm.php +++ b/application/forms/Config/General/DefaultAuthenticationDomainConfigForm.php @@ -32,7 +32,7 @@ class DefaultAuthenticationDomainConfigForm extends Form $this->addElement( 'text', 'authentication_default_domain', - array( + [ 'label' => $this->translate('Default Login Domain'), 'description' => $this->translate( 'If a user logs in without specifying any domain (e.g. "jdoe" instead of "jdoe@example.com"),' @@ -40,7 +40,7 @@ class DefaultAuthenticationDomainConfigForm extends Form . ' backends are configured to be responsible for this domain or if none of your authentication' . ' backends holds usernames with the domain part, users will not be able to login.' ) - ) + ] ); return $this; diff --git a/application/forms/Config/General/LoggingConfigForm.php b/application/forms/Config/General/LoggingConfigForm.php index 8d0ab27ed..c5bb053fd 100644 --- a/application/forms/Config/General/LoggingConfigForm.php +++ b/application/forms/Config/General/LoggingConfigForm.php @@ -37,44 +37,44 @@ class LoggingConfigForm extends Form $this->addElement( 'select', 'logging_log', - array( + [ 'required' => true, 'autosubmit' => true, 'label' => $this->translate('Logging Type'), 'description' => $this->translate('The type of logging to utilize.'), 'value' => $defaultType, - 'multiOptions' => array( + 'multiOptions' => [ 'syslog' => 'Syslog', 'php' => $this->translate('Webserver Log', 'app.config.logging.type'), 'file' => $this->translate('File', 'app.config.logging.type'), 'none' => $this->translate('None', 'app.config.logging.type') - ) - ) + ] + ] ); if (! isset($formData['logging_log']) || $formData['logging_log'] !== 'none') { $this->addElement( 'select', 'logging_level', - array( + [ 'required' => true, 'label' => $this->translate('Logging Level'), 'description' => $this->translate('The maximum logging level to emit.'), - 'multiOptions' => array( + 'multiOptions' => [ Logger::$levels[Logger::ERROR] => $this->translate('Error', 'app.config.logging.level'), Logger::$levels[Logger::WARNING] => $this->translate('Warning', 'app.config.logging.level'), Logger::$levels[Logger::INFO] => $this->translate('Information', 'app.config.logging.level'), Logger::$levels[Logger::DEBUG] => $this->translate('Debug', 'app.config.logging.level') - ) - ) + ] + ] ); } - if (! isset($formData['logging_log']) || in_array($formData['logging_log'], array('syslog', 'php'))) { + if (! isset($formData['logging_log']) || in_array($formData['logging_log'], ['syslog', 'php'])) { $this->addElement( 'text', 'logging_application', - array( + [ 'required' => true, 'label' => $this->translate('Application Prefix'), 'description' => $this->translate( @@ -82,21 +82,21 @@ class LoggingConfigForm extends Form ), 'requirement' => $this->translate('The application prefix must not contain whitespace.'), 'value' => 'icingaweb2', - 'validators' => array( - array( + 'validators' => [ + [ 'Regex', false, - array( + [ 'pattern' => '/^\S+$/', - 'messages' => array( + 'messages' => [ 'regexNotMatch' => $this->translate( 'The application prefix must not contain whitespace.' ) - ) - ) - ) - ) - ) + ] + ] + ] + ] + ] ); if ((isset($formData['logging_log']) ? $formData['logging_log'] : $defaultType) === 'syslog') { @@ -105,23 +105,23 @@ class LoggingConfigForm extends Form $this->addElement( 'hidden', 'logging_facility', - array( + [ 'value' => 'user', 'disabled' => true - ) + ] ); } else { $facilities = array_keys(SyslogWriter::$facilities); $this->addElement( 'select', 'logging_facility', - array( + [ 'required' => true, 'label' => $this->translate('Facility'), 'description' => $this->translate('The syslog facility to utilize.'), 'value' => 'user', 'multiOptions' => array_combine($facilities, $facilities) - ) + ] ); } } @@ -129,13 +129,13 @@ class LoggingConfigForm extends Form $this->addElement( 'text', 'logging_file', - array( + [ 'required' => true, 'label' => $this->translate('File path'), 'description' => $this->translate('The full path to the log file to write messages to.'), 'value' => '/var/log/icingaweb2/icingaweb2.log', - 'validators' => array('WritablePathValidator') - ) + 'validators' => ['WritablePathValidator'] + ] ); } diff --git a/application/forms/Config/General/ThemingConfigForm.php b/application/forms/Config/General/ThemingConfigForm.php index 0560ec413..91625c47d 100644 --- a/application/forms/Config/General/ThemingConfigForm.php +++ b/application/forms/Config/General/ThemingConfigForm.php @@ -38,26 +38,26 @@ class ThemingConfigForm extends Form $this->addElement( 'select', 'themes_default', - array( + [ 'description' => $this->translate('The default theme', 'Form element description'), 'disabled' => count($themes) < 2 ? 'disabled' : null, 'label' => $this->translate('Default Theme', 'Form element label'), 'multiOptions' => $themes, 'value' => StyleSheet::DEFAULT_THEME - ) + ] ); $this->addElement( 'checkbox', 'themes_disabled', - array( + [ 'description' => $this->translate( 'Check this box for disallowing users to change the theme. If a default theme is set, it will be' . ' used nonetheless', 'Form element description' ), 'label' => $this->translate('Users Can\'t Change Theme', 'Form element label') - ) + ] ); return $this; diff --git a/application/forms/Config/Resource/DbResourceForm.php b/application/forms/Config/Resource/DbResourceForm.php index 294e60a5f..77ce5c052 100644 --- a/application/forms/Config/Resource/DbResourceForm.php +++ b/application/forms/Config/Resource/DbResourceForm.php @@ -29,7 +29,7 @@ class DbResourceForm extends Form */ public function createElements(array $formData) { - $dbChoices = array(); + $dbChoices = []; if (Platform::hasMysqlSupport()) { $dbChoices['mysql'] = 'MySQL'; } @@ -81,158 +81,158 @@ class DbResourceForm extends Form $this->addElement( 'text', 'name', - array( + [ 'required' => true, 'label' => $this->translate('Resource Name'), 'description' => $this->translate('The unique name of this resource') - ) + ] ); $this->addElement( 'select', 'db', - array( + [ 'required' => true, 'autosubmit' => true, 'label' => $this->translate('Database Type'), 'description' => $this->translate('The type of SQL database'), 'multiOptions' => $dbChoices - ) + ] ); if ($dbChoice === 'sqlite') { $this->addElement( 'text', 'dbname', - array( + [ 'required' => true, 'label' => $this->translate('Database Name'), 'description' => $this->translate('The name of the database to use') - ) + ] ); } else { $this->addElement( 'text', 'host', - array ( + [ 'required' => $hostIsRequired, 'label' => $this->translate('Host'), 'description' => $this->translate('The hostname of the database') . ($socketInfo ? '. ' . $socketInfo : ''), 'value' => $hostIsRequired ? 'localhost' : '' - ) + ] ); $this->addElement( 'number', 'port', - array( + [ 'description' => $this->translate('The port to use'), 'label' => $this->translate('Port'), 'preserveDefault' => true, 'required' => $offerPostgres, 'value' => $offerPostgres ? 5432 : null - ) + ] ); $this->addElement( 'text', 'dbname', - array( + [ 'required' => true, 'label' => $this->translate('Database Name'), 'description' => $this->translate('The name of the database to use') - ) + ] ); $this->addElement( 'text', 'username', - array ( + [ 'required' => true, 'label' => $this->translate('Username'), 'description' => $this->translate('The user name to use for authentication') - ) + ] ); $this->addElement( 'password', 'password', - array( + [ 'required' => true, 'renderPassword' => true, 'label' => $this->translate('Password'), 'description' => $this->translate('The password to use for authentication'), 'autocomplete' => 'new-password' - ) + ] ); $this->addElement( 'text', 'charset', - array ( + [ 'description' => $this->translate('The character set for the database'), 'label' => $this->translate('Character Set') - ) + ] ); $this->addElement( 'checkbox', 'use_ssl', - array( + [ 'autosubmit' => true, 'label' => $this->translate('Use SSL'), 'description' => $this->translate( 'Whether to encrypt the connection or to authenticate using certificates' ) - ) + ] ); if (isset($formData['use_ssl']) && $formData['use_ssl']) { if (defined(Mysql::class . '::ATTR_SSL_VERIFY_SERVER_CERT')) { $this->addElement( 'checkbox', 'ssl_do_not_verify_server_cert', - array( + [ 'label' => $this->translate('SSL Do Not Verify Server Certificate'), 'description' => $this->translate( 'Whether to disable verification of the server certificate' ) - ) + ] ); } $this->addElement( 'text', 'ssl_key', - array( + [ 'label' => $this->translate('SSL Key'), 'description' => $this->translate('The client key file path') - ) + ] ); $this->addElement( 'text', 'ssl_cert', - array( + [ 'label' => $this->translate('SSL Certificate'), 'description' => $this->translate('The certificate file path') - ) + ] ); $this->addElement( 'text', 'ssl_ca', - array( + [ 'label' => $this->translate('SSL CA'), 'description' => $this->translate('The CA certificate file path') - ) + ] ); $this->addElement( 'text', 'ssl_capath', - array( + [ 'label' => $this->translate('SSL CA Path'), 'description' => $this->translate( 'The trusted CA certificates in PEM format directory path' ) - ) + ] ); $this->addElement( 'text', 'ssl_cipher', - array( + [ 'label' => $this->translate('SSL Cipher'), 'description' => $this->translate('The list of permissible ciphers') - ) + ] ); } } diff --git a/application/forms/Config/Resource/FileResourceForm.php b/application/forms/Config/Resource/FileResourceForm.php index ff9cb1990..8e26b2920 100644 --- a/application/forms/Config/Resource/FileResourceForm.php +++ b/application/forms/Config/Resource/FileResourceForm.php @@ -29,21 +29,21 @@ class FileResourceForm extends Form $this->addElement( 'text', 'name', - array( + [ 'required' => true, 'label' => $this->translate('Resource Name'), 'description' => $this->translate('The unique name of this resource') - ) + ] ); $this->addElement( 'text', 'filename', - array( + [ 'required' => true, 'label' => $this->translate('Filepath'), 'description' => $this->translate('The filename to fetch information from'), - 'validators' => array('ReadablePathValidator') - ) + 'validators' => ['ReadablePathValidator'] + ] ); $callbackValidator = new Zend_Validate_Callback(function ($value) { return @preg_match($value, '') !== false; @@ -55,13 +55,13 @@ class FileResourceForm extends Form $this->addElement( 'text', 'fields', - array( + [ 'required' => true, 'label' => $this->translate('Pattern'), 'description' => $this->translate('The pattern by which to identify columns.'), 'requirement' => $this->translate('The column pattern must be a valid regular expression.'), - 'validators' => array($callbackValidator) - ) + 'validators' => [$callbackValidator] + ] ); return $this; diff --git a/application/forms/Config/Resource/LdapResourceForm.php b/application/forms/Config/Resource/LdapResourceForm.php index 6d289fea7..8c594d053 100644 --- a/application/forms/Config/Resource/LdapResourceForm.php +++ b/application/forms/Config/Resource/LdapResourceForm.php @@ -34,16 +34,16 @@ class LdapResourceForm extends Form $this->addElement( 'text', 'name', - array( + [ 'required' => true, 'label' => $this->translate('Resource Name'), 'description' => $this->translate('The unique name of this resource') - ) + ] ); $this->addElement( 'text', 'hostname', - array( + [ 'required' => true, 'label' => $this->translate('Host'), 'description' => $this->translate( @@ -51,23 +51,23 @@ class LdapResourceForm extends Form . ' You can also provide multiple hosts separated by a space' ), 'value' => 'localhost' - ) + ] ); $this->addElement( 'number', 'port', - array( + [ 'required' => true, 'preserveDefault' => true, 'label' => $this->translate('Port'), 'description' => $this->translate('The port of the LDAP server to use for authentication'), 'value' => $defaultPort - ) + ] ); $this->addElement( 'select', 'encryption', - array( + [ 'required' => true, 'autosubmit' => true, 'label' => $this->translate('Encryption'), @@ -75,55 +75,55 @@ class LdapResourceForm extends Form 'Whether to encrypt communication. Choose STARTTLS or LDAPS for encrypted communication or' . ' none for unencrypted communication' ), - 'multiOptions' => array( + 'multiOptions' => [ 'none' => $this->translate('None', 'resource.ldap.encryption'), LdapConnection::STARTTLS => 'STARTTLS', LdapConnection::LDAPS => 'LDAPS' - ) - ) + ] + ] ); $this->addElement( 'text', 'root_dn', - array( + [ 'required' => true, 'label' => $this->translate('Root DN'), 'description' => $this->translate( 'Only the root and its child nodes will be accessible on this resource.' ) - ) + ] ); $this->addElement( 'text', 'bind_dn', - array( + [ 'label' => $this->translate('Bind DN'), 'description' => $this->translate( 'The user dn to use for querying the ldap server. Leave the dn and password empty for attempting' . ' an anonymous bind' ) - ) + ] ); $this->addElement( 'password', 'bind_pw', - array( + [ 'renderPassword' => true, 'label' => $this->translate('Bind Password'), 'description' => $this->translate('The password to use for querying the ldap server') - ) + ] ); $this->addElement( 'number', 'timeout', - array( + [ 'preserveDefault' => true, 'label' => $this->translate('Timeout'), 'description' => $this->translate('Connection timeout for every LDAP connection'), 'value' => 5 // see LdapConnection::__construct() - ) + ] ); return $this; diff --git a/application/forms/Config/Resource/SshResourceForm.php b/application/forms/Config/Resource/SshResourceForm.php index 0f96c1eb3..ce3cb468d 100644 --- a/application/forms/Config/Resource/SshResourceForm.php +++ b/application/forms/Config/Resource/SshResourceForm.php @@ -33,23 +33,23 @@ class SshResourceForm extends Form $this->addElement( 'text', 'name', - array( + [ 'required' => true, 'label' => $this->translate('Resource Name'), 'description' => $this->translate('The unique name of this resource') - ) + ] ); $this->addElement( 'text', 'user', - array( + [ 'required' => true, 'label' => $this->translate('User'), 'description' => $this->translate( 'User to log in as on the remote Icinga instance. Please note that key-based SSH login must be' . ' possible for this user' ) - ) + ] ); if ($this->getRequest()->getActionName() != 'editresource') { @@ -70,31 +70,31 @@ class SshResourceForm extends Form $this->addElement( 'textarea', 'private_key', - array( + [ 'required' => true, 'label' => $this->translate('Private Key'), 'description' => $this->translate('The private key which will be used for the SSH connections'), 'class' => 'resource ssh-identity', - 'validators' => array($callbackValidator) - ) + 'validators' => [$callbackValidator] + ] ); } else { $resourceName = $formData['name']; $this->addElement( 'note', 'private_key_note', - array( + [ 'escape' => false, 'label' => $this->translate('Private Key'), 'value' => sprintf( '%3$s', - $this->getView()->url('config/removeresource', array('resource' => $resourceName)), + $this->getView()->url('config/removeresource', ['resource' => $resourceName]), $this->getView()->escape(sprintf($this->translate( 'Remove the %s resource' ), $resourceName)), $this->translate('To modify the private key you must recreate this resource.') ) - ) + ] ); } diff --git a/application/forms/Config/ResourceConfigForm.php b/application/forms/Config/ResourceConfigForm.php index cdd9d8f3d..51d930ed8 100644 --- a/application/forms/Config/ResourceConfigForm.php +++ b/application/forms/Config/ResourceConfigForm.php @@ -244,12 +244,12 @@ class ResourceConfigForm extends ConfigForm return $this->createElement( 'checkbox', 'force_creation', - array( + [ 'order' => 0, 'ignore' => true, 'label' => $this->translate('Force Changes'), 'description' => $this->translate('Check this box to enforce changes without connectivity validation') - ) + ] ); } @@ -260,10 +260,10 @@ class ResourceConfigForm extends ConfigForm { $resourceType = isset($formData['type']) ? $formData['type'] : 'db'; - $resourceTypes = array( + $resourceTypes = [ 'file' => $this->translate('File'), 'ssh' => $this->translate('SSH Identity'), - ); + ]; if ($resourceType === 'ldap' || Platform::hasLdapSupport()) { $resourceTypes['ldap'] = 'LDAP'; } @@ -274,14 +274,14 @@ class ResourceConfigForm extends ConfigForm $this->addElement( 'select', 'type', - array( + [ 'required' => true, 'autosubmit' => true, 'label' => $this->translate('Resource Type'), 'description' => $this->translate('The type of resource'), 'multiOptions' => $resourceTypes, 'value' => $resourceType - ) + ] ); if (isset($formData['force_creation']) && $formData['force_creation']) { @@ -329,15 +329,15 @@ class ResourceConfigForm extends ConfigForm $this->addElement( 'note', 'inspection_output', - array( + [ 'order' => 0, 'value' => '' . $this->translate('Validation Log') . "\n\n" . join("\n", array_map($join, $inspection->toArray())), - 'decorators' => array( + 'decorators' => [ 'ViewHelper', - array('HtmlTag', array('tag' => 'pre', 'class' => 'log-output')), - ) - ) + ['HtmlTag', ['tag' => 'pre', 'class' => 'log-output']], + ] + ] ); if ($inspection->hasError()) { @@ -366,40 +366,40 @@ class ResourceConfigForm extends ConfigForm { parent::addSubmitButton() ->getElement('btn_submit') - ->setDecorators(array('ViewHelper')); + ->setDecorators(['ViewHelper']); $this->addElement( 'submit', 'resource_validation', - array( + [ 'ignore' => true, 'label' => $this->translate('Validate Configuration'), 'data-progress-label' => $this->translate('Validation In Progress'), - 'decorators' => array('ViewHelper') - ) + 'decorators' => ['ViewHelper'] + ] ); $this->setAttrib('data-progress-element', 'resource-progress'); $this->addElement( 'note', 'resource-progress', - array( - 'decorators' => array( + [ + 'decorators' => [ 'ViewHelper', - array('Spinner', array('id' => 'resource-progress')) - ) - ) + ['Spinner', ['id' => 'resource-progress']] + ] + ] ); $this->addDisplayGroup( - array('btn_submit', 'resource_validation', 'resource-progress'), + ['btn_submit', 'resource_validation', 'resource-progress'], 'submit_validation', - array( - 'decorators' => array( + [ + 'decorators' => [ 'FormElements', - array('HtmlTag', array('tag' => 'div', 'class' => 'control-group form-controls')) - ) - ) + ['HtmlTag', ['tag' => 'div', 'class' => 'control-group form-controls']] + ] + ] ); return $this; diff --git a/application/forms/Config/User/CreateMembershipForm.php b/application/forms/Config/User/CreateMembershipForm.php index 45ccb15f4..2d391a827 100644 --- a/application/forms/Config/User/CreateMembershipForm.php +++ b/application/forms/Config/User/CreateMembershipForm.php @@ -65,9 +65,9 @@ class CreateMembershipForm extends Form */ public function createElements(array $formData) { - $query = $this->createDataSource()->select()->from('group', array('group_name', 'backend_name')); + $query = $this->createDataSource()->select()->from('group', ['group_name', 'backend_name']); - $options = array(); + $options = []; foreach ($query as $row) { $options[$row->backend_name . ';' . $row->group_name] = $row->group_name . ' (' . $row->backend_name . ')'; } @@ -75,7 +75,7 @@ class CreateMembershipForm extends Form $this->addElement( 'multiselect', 'groups', - array( + [ 'required' => true, 'multiOptions' => $options, 'label' => $this->translate('Groups'), @@ -84,7 +84,7 @@ class CreateMembershipForm extends Form $this->userName ), 'class' => 'grant-permissions' - ) + ] ); $this->setTitle(sprintf($this->translate('Create memberships for %s'), $this->userName)); @@ -109,7 +109,7 @@ class CreateMembershipForm extends Form */ public function onSuccess() { - $backendMap = array(); + $backendMap = []; foreach ($this->backends as $backend) { $backendMap[$backend->getName()] = $backend; } @@ -121,10 +121,10 @@ class CreateMembershipForm extends Form try { $backendMap[$backendName]->insert( 'group_membership', - array( + [ 'group_name' => $groupName, 'user_name' => $this->userName - ) + ] ); } catch (Exception $e) { Notification::error(sprintf( @@ -157,22 +157,22 @@ class CreateMembershipForm extends Form */ protected function createDataSource() { - $groups = $failures = array(); + $groups = $failures = []; foreach ($this->backends as $backend) { try { $memberships = $backend ->select() - ->from('group_membership', array('group_name')) + ->from('group_membership', ['group_name']) ->where('user_name', $this->userName) ->fetchColumn(); - foreach ($backend->select(array('group_name')) as $row) { + foreach ($backend->select(['group_name']) as $row) { if (! in_array($row->group_name, $memberships)) { // TODO(jom): Apply this as native query filter $row->backend_name = $backend->getName(); $groups[] = $row; } } } catch (Exception $e) { - $failures[] = array($backend->getName(), $e); + $failures[] = [$backend->getName(), $e]; } } diff --git a/application/forms/Config/User/UserForm.php b/application/forms/Config/User/UserForm.php index 0cd54322c..7eb342cb5 100644 --- a/application/forms/Config/User/UserForm.php +++ b/application/forms/Config/User/UserForm.php @@ -22,27 +22,27 @@ class UserForm extends RepositoryForm $this->addElement( 'checkbox', 'is_active', - array( + [ 'value' => true, 'label' => $this->translate('Active'), 'description' => $this->translate('Prevents the user from logging in if unchecked') - ) + ] ); $this->addElement( 'text', 'user_name', - array( + [ 'required' => true, 'label' => $this->translate('Username') - ) + ] ); $this->addElement( 'password', 'password', - array( + [ 'required' => true, 'label' => $this->translate('Password') - ) + ] ); $this->setTitle($this->translate('Add a new user')); @@ -61,10 +61,10 @@ class UserForm extends RepositoryForm $this->addElement( 'password', 'password', - array( + [ 'description' => $this->translate('Leave empty for not updating the user\'s password'), 'label' => $this->translate('Password'), - ) + ] ); $this->setTitle(sprintf($this->translate('Edit user %s'), $this->getIdentifier())); diff --git a/application/forms/Config/UserBackend/DbBackendForm.php b/application/forms/Config/UserBackend/DbBackendForm.php index ec58cf2d7..17d4ae974 100644 --- a/application/forms/Config/UserBackend/DbBackendForm.php +++ b/application/forms/Config/UserBackend/DbBackendForm.php @@ -50,18 +50,18 @@ class DbBackendForm extends Form $this->addElement( 'text', 'name', - array( + [ 'required' => true, 'label' => $this->translate('Backend Name'), 'description' => $this->translate( 'The name of this authentication provider that is used to differentiate it from others' ) - ) + ] ); $this->addElement( 'select', 'resource', - array( + [ 'required' => true, 'label' => $this->translate('Database Connection'), 'description' => $this->translate( @@ -69,16 +69,16 @@ class DbBackendForm extends Form ), 'multiOptions' => !empty($this->resources) ? array_combine($this->resources, $this->resources) - : array() - ) + : [] + ] ); $this->addElement( 'hidden', 'backend', - array( + [ 'disabled' => true, 'value' => 'db' - ) + ] ); } } diff --git a/application/forms/Config/UserBackend/ExternalBackendForm.php b/application/forms/Config/UserBackend/ExternalBackendForm.php index 4b8120359..de1ece90c 100644 --- a/application/forms/Config/UserBackend/ExternalBackendForm.php +++ b/application/forms/Config/UserBackend/ExternalBackendForm.php @@ -29,13 +29,13 @@ class ExternalBackendForm extends Form $this->addElement( 'text', 'name', - array( + [ 'required' => true, 'label' => $this->translate('Backend Name'), 'description' => $this->translate( 'The name of this authentication provider that is used to differentiate it from others' ) - ) + ] ); $callbackValidator = new Zend_Validate_Callback(function ($value) { return @preg_match($value, '') !== false; @@ -47,23 +47,23 @@ class ExternalBackendForm extends Form $this->addElement( 'text', 'strip_username_regexp', - array( + [ 'label' => $this->translate('Filter Pattern'), 'description' => $this->translate( 'The filter to use to strip specific parts off from usernames.' . ' Leave empty if you do not want to strip off anything.' ), 'requirement' => $this->translate('The filter pattern must be a valid regular expression.'), - 'validators' => array($callbackValidator) - ) + 'validators' => [$callbackValidator] + ] ); $this->addElement( 'hidden', 'backend', - array( + [ 'disabled' => true, 'value' => 'external' - ) + ] ); return $this; diff --git a/application/forms/Config/UserBackend/LdapBackendForm.php b/application/forms/Config/UserBackend/LdapBackendForm.php index e9dae57f9..4cacd29f3 100644 --- a/application/forms/Config/UserBackend/LdapBackendForm.php +++ b/application/forms/Config/UserBackend/LdapBackendForm.php @@ -29,7 +29,7 @@ class LdapBackendForm extends Form * * @var string[] */ - protected $suggestions = array(); + protected $suggestions = []; /** * Cache for {@link getLdapCapabilities()} @@ -71,19 +71,19 @@ class LdapBackendForm extends Form $this->addElement( 'text', 'name', - array( + [ 'required' => true, 'label' => $this->translate('Backend Name'), 'description' => $this->translate( 'The name of this authentication provider that is used to differentiate it from others.' ), 'value' => $this->getSuggestion('name') - ) + ] ); $this->addElement( 'select', 'resource', - array( + [ 'required' => true, 'label' => $this->translate('LDAP Connection'), 'description' => $this->translate( @@ -91,16 +91,16 @@ class LdapBackendForm extends Form ), 'multiOptions' => !empty($this->resources) ? array_combine($this->resources, $this->resources) - : array(), + : [], 'value' => $this->getSuggestion('resource') - ) + ] ); if (! $isAd && !empty($this->resources)) { $this->addElement( 'button', 'discovery_btn', - array( + [ 'class' => 'control-button', 'type' => 'submit', 'value' => 'discovery_btn', @@ -108,13 +108,13 @@ class LdapBackendForm extends Form 'title' => $this->translate( 'Push to fill in the chosen connection\'s default settings.' ), - 'decorators' => array( - array('ViewHelper', array('separator' => '')), - array('Spinner'), - array('HtmlTag', array('tag' => 'div', 'class' => 'control-group form-controls')) - ), + 'decorators' => [ + ['ViewHelper', ['separator' => '']], + ['Spinner'], + ['HtmlTag', ['tag' => 'div', 'class' => 'control-group form-controls']] + ], 'formnovalidate' => 'formnovalidate' - ) + ] ); } @@ -133,7 +133,7 @@ class LdapBackendForm extends Form $this->addElement( 'text', 'user_class', - array( + [ 'preserveDefault' => true, 'required' => ! $isAd, 'ignore' => $isAd, @@ -141,12 +141,12 @@ class LdapBackendForm extends Form 'label' => $this->translate('LDAP User Object Class'), 'description' => $this->translate('The object class used for storing users on the LDAP server.'), 'value' => $this->getSuggestion('user_class', $userClass) - ) + ] ); $this->addElement( 'text', 'filter', - array( + [ 'preserveDefault' => true, 'allowEmpty' => true, 'value' => $this->getSuggestion('filter', $filter), @@ -159,11 +159,11 @@ class LdapBackendForm extends Form 'The filter needs to be expressed as standard LDAP expression.' . ' (e.g. &(foo=bar)(bar=foo) or foo=bar)' ), - 'validators' => array( - array( + 'validators' => [ + [ 'Callback', false, - array( + [ 'callback' => function ($v) { // This is not meant to be a full syntax check. It will just // ensure that we can safely strip unnecessary parentheses. @@ -172,18 +172,18 @@ class LdapBackendForm extends Form strpos($v, ')(') !== false ? substr($v, -2) === '))' : substr($v, -1) === ')' ); }, - 'messages' => array( + 'messages' => [ 'callbackValue' => $this->translate('The filter is invalid. Please check your syntax.') - ) - ) - ) - ) - ) + ] + ] + ] + ] + ] ); $this->addElement( 'text', 'user_name_attribute', - array( + [ 'preserveDefault' => true, 'required' => ! $isAd, 'ignore' => $isAd, @@ -193,20 +193,20 @@ class LdapBackendForm extends Form 'The attribute name used for storing the user name on the LDAP server.' ), 'value' => $this->getSuggestion('user_name_attribute', $userNameAttribute) - ) + ] ); $this->addElement( 'hidden', 'backend', - array( + [ 'disabled' => true, 'value' => $this->getSuggestion('backend', $isAd ? 'msldap' : 'ldap') - ) + ] ); $this->addElement( 'text', 'base_dn', - array( + [ 'preserveDefault' => true, 'required' => false, 'label' => $this->translate('LDAP Base DN'), @@ -215,13 +215,13 @@ class LdapBackendForm extends Form 'empty to select all users available using the specified connection.' ), 'value' => $this->getSuggestion('base_dn') - ) + ] ); $this->addElement( 'text', 'domain', - array( + [ 'label' => $this->translate('Domain'), 'description' => $this->translate( 'The domain the LDAP server is responsible for upon authentication.' @@ -234,13 +234,13 @@ class LdapBackendForm extends Form ), 'preserveDefault' => true, 'value' => $this->getSuggestion('domain') - ) + ] ); $this->addElement( 'button', 'btn_discover_domain', - array( + [ 'class' => 'control-button', 'type' => 'submit', 'value' => 'discovery_btn', @@ -248,13 +248,13 @@ class LdapBackendForm extends Form 'title' => $this->translate( 'Push to disover and fill in the domain of the LDAP server.' ), - 'decorators' => array( - array('ViewHelper', array('separator' => '')), - array('Spinner'), - array('HtmlTag', array('tag' => 'div', 'class' => 'control-group form-controls')) - ), + 'decorators' => [ + ['ViewHelper', ['separator' => '']], + ['Spinner'], + ['HtmlTag', ['tag' => 'div', 'class' => 'control-group form-controls']] + ], 'formnovalidate' => 'formnovalidate' - ) + ] ); } @@ -368,9 +368,9 @@ class LdapBackendForm extends Form { $defaultNamingContext = $cap->getDefaultNamingContext(); if ($defaultNamingContext !== null) { - $validationMatches = array(); + $validationMatches = []; if (preg_match('/\bdc=[^,]+(?:,dc=[^,]+)*$/', strtolower($defaultNamingContext), $validationMatches)) { - $splitMatches = array(); + $splitMatches = []; preg_match_all('/dc=([^,]+)/', $validationMatches[0], $splitMatches); return implode('.', $splitMatches[1]); } diff --git a/application/forms/Config/UserBackendConfigForm.php b/application/forms/Config/UserBackendConfigForm.php index 82bd27bd1..a788ad15c 100644 --- a/application/forms/Config/UserBackendConfigForm.php +++ b/application/forms/Config/UserBackendConfigForm.php @@ -68,9 +68,9 @@ class UserBackendConfigForm extends ConfigForm */ public function setResourceConfig(Config $resourceConfig) { - $resources = array(); + $resources = []; foreach ($resourceConfig as $name => $resource) { - if (in_array($resource->type, array('db', 'ldap'))) { + if (in_array($resource->type, ['db', 'ldap'])) { $resources[$resource->type][] = $name; } } @@ -113,12 +113,12 @@ class UserBackendConfigForm extends ConfigForm switch ($type) { case 'db': $form = new DbBackendForm(); - $form->setResources(isset($this->resources['db']) ? $this->resources['db'] : array()); + $form->setResources(isset($this->resources['db']) ? $this->resources['db'] : []); break; case 'ldap': case 'msldap': $form = new LdapBackendForm(); - $form->setResources(isset($this->resources['ldap']) ? $this->resources['ldap'] : array()); + $form->setResources(isset($this->resources['ldap']) ? $this->resources['ldap'] : []); break; case 'external': $form = new ExternalBackendForm(); @@ -250,7 +250,7 @@ class UserBackendConfigForm extends ConfigForm array_splice($backendOrder, array_search($name, $backendOrder), 1); array_splice($backendOrder, $position, 0, $name); - $newConfig = array(); + $newConfig = []; foreach ($backendOrder as $backendName) { $newConfig[$backendName] = $this->config->getSection($backendName); } @@ -267,7 +267,7 @@ class UserBackendConfigForm extends ConfigForm */ public function createElements(array $formData) { - $backendTypes = array(); + $backendTypes = []; $backendType = isset($formData['type']) ? $formData['type'] : null; if (isset($this->resources['db'])) { @@ -298,7 +298,7 @@ class UserBackendConfigForm extends ConfigForm $this->addElement( 'select', 'type', - array( + [ 'ignore' => true, 'required' => true, 'autosubmit' => true, @@ -307,7 +307,7 @@ class UserBackendConfigForm extends ConfigForm 'The type of the resource to use for this authenticaton provider' ), 'multiOptions' => $backendTypes - ) + ] ); if (isset($formData['skip_validation']) && $formData['skip_validation']) { @@ -384,14 +384,14 @@ class UserBackendConfigForm extends ConfigForm $this->addElement( 'checkbox', 'skip_validation', - array( + [ 'order' => 0, 'ignore' => true, 'label' => $this->translate('Skip Validation'), 'description' => $this->translate( 'Check this box to enforce changes without validating that authentication is possible.' ) - ) + ] ); } @@ -419,15 +419,15 @@ class UserBackendConfigForm extends ConfigForm $this->addElement( 'note', 'inspection_output', - array( + [ 'order' => 0, 'value' => '' . $this->translate('Validation Log') . "\n\n" . join("\n", array_map($join, $inspection->toArray())), - 'decorators' => array( + 'decorators' => [ 'ViewHelper', - array('HtmlTag', array('tag' => 'pre', 'class' => 'log-output')), - ) - ) + ['HtmlTag', ['tag' => 'pre', 'class' => 'log-output']], + ] + ] ); if ($inspection->hasError()) { @@ -456,27 +456,27 @@ class UserBackendConfigForm extends ConfigForm { parent::addSubmitButton() ->getElement('btn_submit') - ->setDecorators(array('ViewHelper')); + ->setDecorators(['ViewHelper']); $this->addElement( 'submit', 'backend_validation', - array( + [ 'ignore' => true, 'label' => $this->translate('Validate Configuration'), 'data-progress-label' => $this->translate('Validation In Progress'), - 'decorators' => array('ViewHelper') - ) + 'decorators' => ['ViewHelper'] + ] ); $this->addDisplayGroup( - array('btn_submit', 'backend_validation'), + ['btn_submit', 'backend_validation'], 'submit_validation', - array( - 'decorators' => array( + [ + 'decorators' => [ 'FormElements', - array('HtmlTag', array('tag' => 'div', 'class' => 'control-group form-controls')) - ) - ) + ['HtmlTag', ['tag' => 'div', 'class' => 'control-group form-controls']] + ] + ] ); return $this; diff --git a/application/forms/Config/UserGroup/AddMemberForm.php b/application/forms/Config/UserGroup/AddMemberForm.php index dcde1b550..7b974e98f 100644 --- a/application/forms/Config/UserGroup/AddMemberForm.php +++ b/application/forms/Config/UserGroup/AddMemberForm.php @@ -91,37 +91,37 @@ class AddMemberForm extends Form // not work currently as our ldap protocol stuff is unable to handle our filter implementation.. $members = $this->backend ->select() - ->from('group_membership', array('user_name')) + ->from('group_membership', ['user_name']) ->where('group_name', $this->groupName) ->fetchColumn(); $filter = empty($members) ? Filter::matchAll() : Filter::not(Filter::where('user_name', $members)); - $users = $this->ds->select()->from('user', array('user_name'))->applyFilter($filter)->fetchColumn(); + $users = $this->ds->select()->from('user', ['user_name'])->applyFilter($filter)->fetchColumn(); if (! empty($users)) { $this->addElement( 'multiselect', 'user_name', - array( + [ 'multiOptions' => array_combine($users, $users), 'label' => $this->translate('Backend Users'), 'description' => $this->translate( 'Select one or more users (fetched from your user backends) to add as group member' ), 'class' => 'grant-permissions' - ) + ] ); } $this->addElement( 'textarea', 'users', - array( + [ 'required' => empty($users), 'label' => $this->translate('Users'), 'description' => $this->translate( 'Provide one or more usernames separated by comma to add as group member' ) - ) + ] ); $this->setTitle(sprintf($this->translate('Add members for group %s'), $this->groupName)); @@ -135,7 +135,7 @@ class AddMemberForm extends Form */ public function onSuccess() { - $userNames = $this->getValue('user_name') ?: array(); + $userNames = $this->getValue('user_name') ?: []; if (($users = $this->getValue('users'))) { $userNames = array_merge($userNames, array_map('trim', explode(',', $users))); } @@ -154,10 +154,10 @@ class AddMemberForm extends Form try { $this->backend->insert( 'group_membership', - array( + [ 'group_name' => $this->groupName, 'user_name' => $userName - ) + ] ); } catch (NotFoundError $e) { throw $e; // Trigger 404, the group name is initially accessed as GET parameter diff --git a/application/forms/Config/UserGroup/DbUserGroupBackendForm.php b/application/forms/Config/UserGroup/DbUserGroupBackendForm.php index 8240cbb9f..8dae6c92b 100644 --- a/application/forms/Config/UserGroup/DbUserGroupBackendForm.php +++ b/application/forms/Config/UserGroup/DbUserGroupBackendForm.php @@ -31,34 +31,34 @@ class DbUserGroupBackendForm extends Form $this->addElement( 'text', 'name', - array( + [ 'required' => true, 'label' => $this->translate('Backend Name'), 'description' => $this->translate( 'The name of this user group backend that is used to differentiate it from others' ) - ) + ] ); $resourceNames = $this->getDatabaseResourceNames(); $this->addElement( 'select', 'resource', - array( + [ 'required' => true, 'label' => $this->translate('Database Connection'), 'description' => $this->translate('The database connection to use for this backend'), - 'multiOptions' => empty($resourceNames) ? array() : array_combine($resourceNames, $resourceNames) - ) + 'multiOptions' => empty($resourceNames) ? [] : array_combine($resourceNames, $resourceNames) + ] ); $this->addElement( 'hidden', 'backend', - array( + [ 'disabled' => true, // Prevents the element from being submitted, see #7717 'value' => 'db' - ) + ] ); } @@ -69,7 +69,7 @@ class DbUserGroupBackendForm extends Form */ protected function getDatabaseResourceNames() { - $names = array(); + $names = []; foreach (ResourceFactory::getResourceConfigs() as $name => $config) { if (strtolower($config->type) === 'db') { $names[] = $name; diff --git a/application/forms/Config/UserGroup/LdapUserGroupBackendForm.php b/application/forms/Config/UserGroup/LdapUserGroupBackendForm.php index cae884c28..36368ccc4 100644 --- a/application/forms/Config/UserGroup/LdapUserGroupBackendForm.php +++ b/application/forms/Config/UserGroup/LdapUserGroupBackendForm.php @@ -36,26 +36,26 @@ class LdapUserGroupBackendForm extends Form $this->addElement( 'text', 'name', - array( + [ 'required' => true, 'label' => $this->translate('Backend Name'), 'description' => $this->translate( 'The name of this user group backend that is used to differentiate it from others' ) - ) + ] ); $resourceNames = $this->getLdapResourceNames(); $this->addElement( 'select', 'resource', - array( + [ 'required' => true, 'autosubmit' => true, 'label' => $this->translate('LDAP Connection'), 'description' => $this->translate('The LDAP connection to use for this backend.'), 'multiOptions' => array_combine($resourceNames, $resourceNames) - ) + ] ); $resource = ResourceFactory::create( isset($formData['resource']) && in_array($formData['resource'], $resourceNames) @@ -68,18 +68,18 @@ class LdapUserGroupBackendForm extends Form $userBackends = array_combine($userBackendNames, $userBackendNames); $userBackends['none'] = $this->translate('None', 'usergroupbackend.ldap.user_backend'); } else { - $userBackends = array('none' => $this->translate('None', 'usergroupbackend.ldap.user_backend')); + $userBackends = ['none' => $this->translate('None', 'usergroupbackend.ldap.user_backend')]; } $this->addElement( 'select', 'user_backend', - array( + [ 'required' => true, 'autosubmit' => true, 'label' => $this->translate('User Backend'), 'description' => $this->translate('The user backend to link with this user group backend.'), 'multiOptions' => $userBackends - ) + ] ); $groupBackend = new LdapUserGroupBackend($resource); @@ -95,16 +95,16 @@ class LdapUserGroupBackendForm extends Form $this->addElement( 'checkbox', 'nested_group_search', - array( + [ 'description' => $this->translate( 'Check this box for nested group search in Active Directory based on the user' ), 'label' => $this->translate('Nested Group Search') - ) + ] ); } else { // This is required to purge already present options - $this->addElement('hidden', 'nested_group_search', array('disabled' => true)); + $this->addElement('hidden', 'nested_group_search', ['disabled' => true]); } $this->createGroupConfigElements($defaults, $groupConfigDisabled); @@ -117,10 +117,10 @@ class LdapUserGroupBackendForm extends Form $this->addElement( 'hidden', 'backend', - array( + [ 'disabled' => true, // Prevents the element from being submitted, see #7717 'value' => $formData['type'] - ) + ] ); } @@ -135,19 +135,19 @@ class LdapUserGroupBackendForm extends Form $this->addElement( 'text', 'group_class', - array( + [ 'preserveDefault' => true, 'ignore' => $disabled, 'disabled' => $disabled, 'label' => $this->translate('LDAP Group Object Class'), 'description' => $this->translate('The object class used for storing groups on the LDAP server.'), 'value' => $defaults->group_class - ) + ] ); $this->addElement( 'text', 'group_filter', - array( + [ 'preserveDefault' => true, 'allowEmpty' => true, 'label' => $this->translate('LDAP Group Filter'), @@ -159,27 +159,27 @@ class LdapUserGroupBackendForm extends Form 'The filter needs to be expressed as standard LDAP expression, without' . ' outer parentheses. (e.g. &(foo=bar)(bar=foo) or foo=bar)' ), - 'validators' => array( - array( + 'validators' => [ + [ 'Callback', false, - array( + [ 'callback' => function ($v) { return strpos($v, '(') !== 0; }, - 'messages' => array( + 'messages' => [ 'callbackValue' => $this->translate('The filter must not be wrapped in parantheses.') - ) - ) - ) - ), + ] + ] + ] + ], 'value' => $defaults->group_filter - ) + ] ); $this->addElement( 'text', 'group_name_attribute', - array( + [ 'preserveDefault' => true, 'ignore' => $disabled, 'disabled' => $disabled, @@ -188,24 +188,24 @@ class LdapUserGroupBackendForm extends Form 'The attribute name used for storing a group\'s name on the LDAP server.' ), 'value' => $defaults->group_name_attribute - ) + ] ); $this->addElement( 'text', 'group_member_attribute', - array( + [ 'preserveDefault' => true, 'ignore' => $disabled, 'disabled' => $disabled, 'label' => $this->translate('LDAP Group Member Attribute'), 'description' => $this->translate('The attribute name used for storing a group\'s members.'), 'value' => $defaults->group_member_attribute - ) + ] ); $this->addElement( 'text', 'base_dn', - array( + [ 'preserveDefault' => true, 'label' => $this->translate('LDAP Group Base DN'), 'description' => $this->translate( @@ -213,7 +213,7 @@ class LdapUserGroupBackendForm extends Form 'empty to select all users available using the specified connection.' ), 'value' => $defaults->base_dn - ) + ] ); } @@ -228,19 +228,19 @@ class LdapUserGroupBackendForm extends Form $this->addElement( 'text', 'user_class', - array( + [ 'preserveDefault' => true, 'ignore' => $disabled, 'disabled' => $disabled, 'label' => $this->translate('LDAP User Object Class'), 'description' => $this->translate('The object class used for storing users on the LDAP server.'), 'value' => $defaults->user_class - ) + ] ); $this->addElement( 'text', 'user_filter', - array( + [ 'preserveDefault' => true, 'allowEmpty' => true, 'label' => $this->translate('LDAP User Filter'), @@ -252,27 +252,27 @@ class LdapUserGroupBackendForm extends Form 'The filter needs to be expressed as standard LDAP expression, without' . ' outer parentheses. (e.g. &(foo=bar)(bar=foo) or foo=bar)' ), - 'validators' => array( - array( + 'validators' => [ + [ 'Callback', false, - array( + [ 'callback' => function ($v) { return strpos($v, '(') !== 0; }, - 'messages' => array( + 'messages' => [ 'callbackValue' => $this->translate('The filter must not be wrapped in parantheses.') - ) - ) - ) - ), + ] + ] + ] + ], 'value' => $defaults->user_filter - ) + ] ); $this->addElement( 'text', 'user_name_attribute', - array( + [ 'preserveDefault' => true, 'ignore' => $disabled, 'disabled' => $disabled, @@ -281,12 +281,12 @@ class LdapUserGroupBackendForm extends Form 'The attribute name used for storing a user\'s name on the LDAP server.' ), 'value' => $defaults->user_name_attribute - ) + ] ); $this->addElement( 'text', 'user_base_dn', - array( + [ 'preserveDefault' => true, 'label' => $this->translate('LDAP User Base DN'), 'description' => $this->translate( @@ -294,17 +294,17 @@ class LdapUserGroupBackendForm extends Form 'empty to select all users available using the specified connection.' ), 'value' => $defaults->user_base_dn - ) + ] ); $this->addElement( 'text', 'domain', - array( + [ 'label' => $this->translate('Domain'), 'description' => $this->translate( 'The domain the LDAP server is responsible for.' ) - ) + ] ); } @@ -315,11 +315,11 @@ class LdapUserGroupBackendForm extends Form */ protected function createHiddenUserConfigElements() { - $this->addElement('hidden', 'user_class', array('disabled' => true)); - $this->addElement('hidden', 'user_filter', array('disabled' => true)); - $this->addElement('hidden', 'user_name_attribute', array('disabled' => true)); - $this->addElement('hidden', 'user_base_dn', array('disabled' => true)); - $this->addElement('hidden', 'domain', array('disabled' => true)); + $this->addElement('hidden', 'user_class', ['disabled' => true]); + $this->addElement('hidden', 'user_filter', ['disabled' => true]); + $this->addElement('hidden', 'user_name_attribute', ['disabled' => true]); + $this->addElement('hidden', 'user_base_dn', ['disabled' => true]); + $this->addElement('hidden', 'domain', ['disabled' => true]); } /** @@ -329,9 +329,9 @@ class LdapUserGroupBackendForm extends Form */ protected function getLdapResourceNames() { - $names = array(); + $names = []; foreach (ResourceFactory::getResourceConfigs() as $name => $config) { - if (in_array(strtolower($config->type), array('ldap', 'msldap'))) { + if (in_array(strtolower($config->type), ['ldap', 'msldap'])) { $names[] = $name; } } @@ -355,9 +355,9 @@ class LdapUserGroupBackendForm extends Form */ protected function getLdapUserBackendNames(LdapConnection $resource) { - $names = array(); + $names = []; foreach (UserBackend::getBackendConfigs() as $name => $config) { - if (in_array(strtolower($config->backend), array('ldap', 'msldap'))) { + if (in_array(strtolower($config->backend), ['ldap', 'msldap'])) { $backendResource = ResourceFactory::create($config->resource); if ($backendResource->getHostname() === $resource->getHostname() && $backendResource->getPort() === $resource->getPort() diff --git a/application/forms/Config/UserGroup/UserGroupBackendForm.php b/application/forms/Config/UserGroup/UserGroupBackendForm.php index d4bff708f..239294626 100644 --- a/application/forms/Config/UserGroup/UserGroupBackendForm.php +++ b/application/forms/Config/UserGroup/UserGroupBackendForm.php @@ -188,11 +188,11 @@ class UserGroupBackendForm extends ConfigForm */ public function createElements(array $formData) { - $backendTypes = array( + $backendTypes = [ 'db' => $this->translate('Database'), 'ldap' => 'LDAP', 'msldap' => 'ActiveDirectory' - ); + ]; $customBackendTypes = array_keys($this->customBackends); $backendTypes += array_combine($customBackendTypes, $customBackendTypes); @@ -205,14 +205,14 @@ class UserGroupBackendForm extends ConfigForm $this->addElement( 'select', 'type', - array( + [ 'ignore' => true, 'required' => true, 'autosubmit' => true, 'label' => $this->translate('Backend Type'), 'description' => $this->translate('The type of this user group backend'), 'multiOptions' => $backendTypes - ) + ] ); $this->addSubForm($this->getBackendForm($backendType)->create($formData), 'backend_form'); @@ -251,15 +251,15 @@ class UserGroupBackendForm extends ConfigForm $this->addElement( 'note', 'inspection_output', - array( + [ 'order' => 0, 'value' => '' . $this->translate('Validation Log') . "\n\n" . join("\n", array_map($join, $inspection->toArray())), - 'decorators' => array( + 'decorators' => [ 'ViewHelper', - array('HtmlTag', array('tag' => 'pre', 'class' => 'log-output')), - ) - ) + ['HtmlTag', ['tag' => 'pre', 'class' => 'log-output']], + ] + ] ); if ($inspection->hasError()) { @@ -288,27 +288,27 @@ class UserGroupBackendForm extends ConfigForm { parent::addSubmitButton() ->getElement('btn_submit') - ->setDecorators(array('ViewHelper')); + ->setDecorators(['ViewHelper']); $this->addElement( 'submit', 'backend_validation', - array( + [ 'ignore' => true, 'label' => $this->translate('Validate Configuration'), 'data-progress-label' => $this->translate('Validation In Progress'), - 'decorators' => array('ViewHelper') - ) + 'decorators' => ['ViewHelper'] + ] ); $this->addDisplayGroup( - array('btn_submit', 'backend_validation'), + ['btn_submit', 'backend_validation'], 'submit_validation', - array( - 'decorators' => array( + [ + 'decorators' => [ 'FormElements', - array('HtmlTag', array('tag' => 'div', 'class' => 'control-group form-controls')) - ) - ) + ['HtmlTag', ['tag' => 'div', 'class' => 'control-group form-controls']] + ] + ] ); return $this; diff --git a/application/forms/Config/UserGroup/UserGroupForm.php b/application/forms/Config/UserGroup/UserGroupForm.php index 382e34982..1d540c113 100644 --- a/application/forms/Config/UserGroup/UserGroupForm.php +++ b/application/forms/Config/UserGroup/UserGroupForm.php @@ -22,10 +22,10 @@ class UserGroupForm extends RepositoryForm $this->addElement( 'text', 'group_name', - array( + [ 'required' => true, 'label' => $this->translate('Group Name') - ) + ] ); if ($this->shouldInsert()) { diff --git a/application/forms/ConfigForm.php b/application/forms/ConfigForm.php index 9a8bf5cb5..37911ded7 100644 --- a/application/forms/ConfigForm.php +++ b/application/forms/ConfigForm.php @@ -72,7 +72,7 @@ class ConfigForm extends Form public function onSuccess() { - $sections = array(); + $sections = []; foreach (static::transformEmptyValuesToNull($this->getValues()) as $sectionAndPropertyName => $value) { list($section, $property) = explode('_', $sectionAndPropertyName, 2); $sections[$section][$property] = $value; @@ -102,7 +102,7 @@ class ConfigForm extends Form public function onRequest() { - $values = array(); + $values = []; foreach ($this->config as $section => $properties) { foreach ($properties as $name => $value) { $values[$section . '_' . $name] = $value; @@ -128,14 +128,14 @@ class ConfigForm extends Form return false; } catch (Exception $e) { - $this->addDecorator('ViewScript', array( + $this->addDecorator('ViewScript', [ 'viewModule' => 'default', 'viewScript' => 'showConfiguration.phtml', 'errorMessage' => $e->getMessage(), 'configString' => $this->config, 'filePath' => $this->config->getConfigFile(), 'placement' => Zend_Form_Decorator_Abstract::PREPEND - )); + ]); return false; } @@ -184,7 +184,7 @@ class ConfigForm extends Form public static function transformEmptyValuesToNull(array $values) { array_walk($values, function (&$v) { - if ($v === '' || $v === false || $v === array()) { + if ($v === '' || $v === false || $v === []) { $v = null; } }); diff --git a/application/forms/Control/LimiterControlForm.php b/application/forms/Control/LimiterControlForm.php index 7281b7631..9cada778a 100644 --- a/application/forms/Control/LimiterControlForm.php +++ b/application/forms/Control/LimiterControlForm.php @@ -31,13 +31,13 @@ class LimiterControlForm extends Form * * @var int[] */ - public static $limits = array( + public static $limits = [ 10 => '10', 25 => '25', 50 => '50', 100 => '100', 500 => '500' - ); + ]; public static $defaultElementDecorators = [ ['Label', ['tag' => 'span', 'separator' => '']], @@ -114,13 +114,13 @@ class LimiterControlForm extends Form $this->addElement( 'select', 'limit', - array( + [ 'autosubmit' => true, 'escape' => false, 'label' => '#', 'multiOptions' => $options, 'value' => $pageSize - ) + ] ); } diff --git a/application/forms/Dashboard/DashletForm.php b/application/forms/Dashboard/DashletForm.php index 02cba4ce0..5af52d113 100644 --- a/application/forms/Dashboard/DashletForm.php +++ b/application/forms/Dashboard/DashletForm.php @@ -41,8 +41,8 @@ class DashletForm extends Form */ public function createElements(array $formData) { - $groupElements = array(); - $panes = array(); + $groupElements = []; + $panes = []; if ($this->dashboard) { $panes = $this->dashboard->getPaneKeyTitleArray(); @@ -62,81 +62,81 @@ class DashletForm extends Form $this->addElement( 'hidden', 'org_pane', - array( + [ 'required' => false - ) + ] ); $this->addElement( 'hidden', 'org_dashlet', - array( + [ 'required' => false - ) + ] ); $this->addElement( 'textarea', 'url', - array( + [ 'required' => true, 'label' => $this->translate('Url'), 'description' => $this->translate( 'Enter url to be loaded in the dashlet. You can paste the full URL, including filters.' ), - 'validators' => array(new UrlValidator(), new InternalUrlValidator()) - ) + 'validators' => [new UrlValidator(), new InternalUrlValidator()] + ] ); $this->addElement( 'text', 'dashlet', - array( + [ 'required' => true, 'label' => $this->translate('Dashlet Title'), 'description' => $this->translate('Enter a title for the dashlet.'), 'validators' => [$sectionNameValidator] - ) + ] ); $this->addElement( 'note', 'note', - array( - 'decorators' => array( - array('HtmlTag', array('tag' => 'hr')) - ) - ) + [ + 'decorators' => [ + ['HtmlTag', ['tag' => 'hr']] + ] + ] ); $this->addElement( 'checkbox', 'create_new_pane', - array( + [ 'autosubmit' => true, 'required' => false, 'label' => $this->translate('New dashboard'), 'description' => $this->translate('Check this box if you want to add the dashlet to a new dashboard') - ) + ] ); if (empty($panes) || ((isset($formData['create_new_pane']) && $formData['create_new_pane'] != false))) { $this->addElement( 'text', 'pane', - array( + [ 'required' => true, 'label' => $this->translate('New Dashboard Title'), 'description' => $this->translate('Enter a title for the new dashboard'), 'validators' => [$sectionNameValidator] - ) + ] ); } else { $this->addElement( 'select', 'pane', - array( + [ 'required' => true, 'label' => $this->translate('Dashboard'), 'multiOptions' => $panes, 'description' => $this->translate('Select a dashboard you want to add the dashlet to') - ) + ] ); } } @@ -162,12 +162,12 @@ class DashletForm extends Form */ public function load(Dashlet $dashlet) { - $this->populate(array( + $this->populate([ 'pane' => $dashlet->getPane()->getTitle(), 'org_pane' => $dashlet->getPane()->getName(), 'dashlet' => $dashlet->getTitle(), 'org_dashlet' => $dashlet->getName(), 'url' => $dashlet->getUrl()->getRelativeUrl() - )); + ]); } } diff --git a/application/forms/LdapDiscoveryForm.php b/application/forms/LdapDiscoveryForm.php index 1e4ef2523..7f2cbc67a 100644 --- a/application/forms/LdapDiscoveryForm.php +++ b/application/forms/LdapDiscoveryForm.php @@ -25,10 +25,10 @@ class LdapDiscoveryForm extends Form $this->addElement( 'text', 'domain', - array( + [ 'label' => $this->translate('Search Domain'), 'description' => $this->translate('Search this domain for records of available servers.'), - ) + ] ); return $this; diff --git a/application/forms/Navigation/DashletForm.php b/application/forms/Navigation/DashletForm.php index 7c4a97236..6d38f2c95 100644 --- a/application/forms/Navigation/DashletForm.php +++ b/application/forms/Navigation/DashletForm.php @@ -15,23 +15,23 @@ class DashletForm extends NavigationItemForm $this->addElement( 'text', 'pane', - array( + [ 'required' => true, 'label' => $this->translate('Pane'), 'description' => $this->translate('The name of the dashboard pane in which to display this dashlet') - ) + ] ); $this->addElement( 'text', 'url', - array( + [ 'required' => true, 'label' => $this->translate('Url'), 'description' => $this->translate( 'The url to load in the dashlet. For external urls, make sure to prepend' . ' an appropriate protocol identifier (e.g. http://example.tld)' ) - ) + ] ); } } diff --git a/application/forms/Navigation/NavigationConfigForm.php b/application/forms/Navigation/NavigationConfigForm.php index 7ac449330..296c6f82c 100644 --- a/application/forms/Navigation/NavigationConfigForm.php +++ b/application/forms/Navigation/NavigationConfigForm.php @@ -198,7 +198,7 @@ class NavigationConfigForm extends ConfigForm */ public function getItemTypes() { - return $this->itemTypes ?: array(); + return $this->itemTypes ?: []; } /** @@ -211,9 +211,9 @@ class NavigationConfigForm extends ConfigForm */ public function listAvailableParents($type, $owner = null) { - $children = $this->itemToLoad ? $this->getFlattenedChildren($this->itemToLoad) : array(); + $children = $this->itemToLoad ? $this->getFlattenedChildren($this->itemToLoad) : []; - $names = array(); + $names = []; foreach ($this->getShareConfig($type) as $sectionName => $sectionConfig) { if ((string) $sectionName !== $this->itemToLoad && $sectionConfig->owner === ($owner ?: $this->getUser()->getUsername()) @@ -245,10 +245,10 @@ class NavigationConfigForm extends ConfigForm { $config = $this->getConfigForItem($name); if ($config === null) { - return array(); + return []; } - $children = array(); + $children = []; foreach ($config->toArray() as $sectionName => $sectionConfig) { if (isset($sectionConfig['parent']) && $sectionConfig['parent'] === $name) { $children[] = $sectionName; @@ -572,13 +572,13 @@ class NavigationConfigForm extends ConfigForm $this->addElement( 'text', 'name', - array( + [ 'required' => true, 'label' => $this->translate('Name'), 'description' => $this->translate( 'The name of this navigation item that is used to differentiate it from others' ) - ) + ] ); if ((! $itemForm->requiresParentSelection() || ! isset($formData['parent']) || ! $formData['parent']) @@ -589,13 +589,13 @@ class NavigationConfigForm extends ConfigForm $this->addElement( 'checkbox', 'shared', - array( + [ 'autosubmit' => true, 'ignore' => true, 'value' => $checked, 'label' => $this->translate('Shared'), 'description' => $this->translate('Tick this box to share this item with others') - ) + ] ); if ($checked || (isset($formData['shared']) && $formData['shared'])) { @@ -603,22 +603,22 @@ class NavigationConfigForm extends ConfigForm $this->addElement( 'textarea', 'users', - array( + [ 'label' => $this->translate('Users'), 'description' => $this->translate( 'Comma separated list of usernames to share this item with' ) - ) + ] ); $this->addElement( 'textarea', 'groups', - array( + [ 'label' => $this->translate('Groups'), 'description' => $this->translate( 'Comma separated list of group names to share this item with' ) - ) + ] ); } } @@ -627,21 +627,21 @@ class NavigationConfigForm extends ConfigForm $this->addElement( 'hidden', 'type', - array( + [ 'value' => $itemType - ) + ] ); } else { $this->addElement( 'select', 'type', - array( + [ 'required' => true, 'autosubmit' => true, 'label' => $this->translate('Type'), 'description' => $this->translate('The type of this navigation item'), 'multiOptions' => $itemTypes - ) + ] ); } @@ -656,7 +656,7 @@ class NavigationConfigForm extends ConfigForm $this->addElement( 'select', 'parent', - array( + [ 'allowEmpty' => true, 'autosubmit' => true, 'label' => $this->translate('Parent'), @@ -666,7 +666,7 @@ class NavigationConfigForm extends ConfigForm ), 'multiOptions' => ['' => $this->translate('None', 'No parent for a navigation item')] + (empty($availableParents) ? [] : array_combine($availableParents, $availableParents)) - ) + ] ); } else { $this->addElement('hidden', 'parent', ['disabled' => true]); @@ -694,7 +694,7 @@ class NavigationConfigForm extends ConfigForm $data['name'] = $this->itemToLoad; $this->populate($data); } elseif ($this->defaultUrl !== null) { - $this->populate(array('url' => $this->defaultUrl)); + $this->populate(['url' => $this->defaultUrl]); } } @@ -709,7 +709,7 @@ class NavigationConfigForm extends ConfigForm $valid = true; if (isset($formData['users']) && $formData['users']) { - $parsedUserRestrictions = array(); + $parsedUserRestrictions = []; foreach (Auth::getInstance()->getRestrictions('application/share/users') as $userRestriction) { $parsedUserRestrictions[] = array_map('trim', explode(',', $userRestriction)); } @@ -733,7 +733,7 @@ class NavigationConfigForm extends ConfigForm } if (isset($formData['groups']) && $formData['groups']) { - $parsedGroupRestrictions = array(); + $parsedGroupRestrictions = []; foreach (Auth::getInstance()->getRestrictions('application/share/groups') as $groupRestriction) { $parsedGroupRestrictions[] = array_map('trim', explode(',', $groupRestriction)); } diff --git a/application/forms/Navigation/NavigationItemForm.php b/application/forms/Navigation/NavigationItemForm.php index 0efe96d9c..a40771c73 100644 --- a/application/forms/Navigation/NavigationItemForm.php +++ b/application/forms/Navigation/NavigationItemForm.php @@ -35,23 +35,23 @@ class NavigationItemForm extends Form $this->addElement( 'select', 'target', - array( + [ 'allowEmpty' => true, 'label' => $this->translate('Target'), 'description' => $this->translate('The target where to open this navigation item\'s url'), - 'multiOptions' => array( + 'multiOptions' => [ '_blank' => $this->translate('New Window'), '_next' => $this->translate('New Column'), '_main' => $this->translate('Single Column'), '_self' => $this->translate('Current Column') - ) - ) + ] + ] ); $this->addElement( 'textarea', 'url', - array( + [ 'allowEmpty' => true, 'label' => $this->translate('Url'), 'description' => $this->translate( @@ -59,37 +59,37 @@ class NavigationItemForm extends Form . ' For urls with username and password and for all external urls,' . ' make sure to prepend an appropriate protocol identifier (e.g. http://example.tld)' ), - 'validators' => array( - array( + 'validators' => [ + [ 'Callback', false, - array( + [ 'callback' => function ($url) { // Matches if the given url contains obviously // a username but not any protocol identifier return !preg_match('#^((?=[^/@]).)+@.*$#', $url); }, - 'messages' => array( + 'messages' => [ 'callbackValue' => $this->translate( 'Missing protocol identifier' ) - ) - ) - ) - ) - ) + ] + ] + ] + ] + ] ); $this->addElement( 'text', 'icon', - array( + [ 'allowEmpty' => true, 'label' => $this->translate('Icon'), 'description' => $this->translate( 'The icon of this navigation item. Leave blank if you do not want a icon being displayed' ) - ) + ] ); } diff --git a/application/forms/PreferenceForm.php b/application/forms/PreferenceForm.php index 890444925..0fa9febe3 100644 --- a/application/forms/PreferenceForm.php +++ b/application/forms/PreferenceForm.php @@ -101,7 +101,7 @@ class PreferenceForm extends Form $oldLocale = $currentPreferences->getValue('icingaweb', 'language'); $defaultTheme = Config::app()->get('themes', 'default', StyleSheet::DEFAULT_THEME); - $this->preferences = new Preferences($this->store ? $this->store->load() : array()); + $this->preferences = new Preferences($this->store ? $this->store->load() : []); $webPreferences = $this->preferences->get('icingaweb'); foreach ($this->getValues() as $key => $value) { if ($value === '' @@ -199,7 +199,7 @@ class PreferenceForm extends Form $this->addElement( 'select', 'theme', - array( + [ 'label' => $this->translate('Theme', 'Form element label'), 'multiOptions' => $themes, 'autosubmit' => true, @@ -208,7 +208,7 @@ class PreferenceForm extends Form 'theme', $defaultTheme ) - ) + ] ); } } @@ -257,7 +257,7 @@ class PreferenceForm extends Form /** @var GettextTranslator $translator */ $translator = StaticTranslator::$instance; - $languages = array(); + $languages = []; $availableLocales = $translator->listLocales(); $locale = $this->getLocale($availableLocales); @@ -270,7 +270,7 @@ class PreferenceForm extends Form $languages[$language] = $language; } - $tzList = array(); + $tzList = []; $tzList['autodetect'] = sprintf( $this->translate('Browser (%s)', 'preferences.form'), $this->getDefaultTimezone() @@ -282,31 +282,31 @@ class PreferenceForm extends Form $this->addElement( 'select', 'language', - array( + [ 'required' => true, 'label' => $this->translate('Your Current Language'), 'description' => $this->translate('Use the following language to display texts and messages'), 'multiOptions' => $languages, 'value' => substr(setlocale(LC_ALL, 0), 0, 5) - ) + ] ); $this->addElement( 'select', 'timezone', - array( + [ 'required' => true, 'label' => $this->translate('Your Current Timezone'), 'description' => $this->translate('Use the following timezone for dates and times'), 'multiOptions' => $tzList, 'value' => $this->getDefaultTimezone() - ) + ] ); $this->addElement( 'select', 'show_application_state_messages', - array( + [ 'required' => true, 'label' => $this->translate('Show application state messages'), 'description' => $this->translate('Whether to show application state messages.'), @@ -317,33 +317,33 @@ class PreferenceForm extends Form 1 => $this->translate('Yes'), 0 => $this->translate('No')], 'value' => 'system' - ) + ] ); if (Auth::getInstance()->hasPermission('user/application/stacktraces')) { $this->addElement( 'checkbox', 'show_stacktraces', - array( + [ 'value' => $this->getDefaultShowStacktraces(), 'label' => $this->translate('Show Stacktraces'), 'description' => $this->translate('Set whether to show an exception\'s stacktrace.') - ) + ] ); } $this->addElement( 'checkbox', 'show_benchmark', - array( + [ 'label' => $this->translate('Use benchmark') - ) + ] ); $this->addElement( 'checkbox', 'auto_refresh', - array( + [ 'required' => false, 'autosubmit' => true, 'label' => $this->translate('Enable auto refresh'), @@ -351,7 +351,7 @@ class PreferenceForm extends Form 'This option allows you to enable or to disable the global page content auto refresh' ), 'value' => 1 - ) + ] ); if (isset($formData['auto_refresh']) && $formData['auto_refresh']) { @@ -378,59 +378,59 @@ class PreferenceForm extends Form $this->addElement( 'number', 'default_page_size', - array( + [ 'label' => $this->translate('Default page size'), 'description' => $this->translate('Default number of items per page for list views'), 'placeholder' => 25, 'min' => 25, 'step' => 1 - ) + ] ); if ($this->store) { $this->addElement( 'submit', 'btn_submit', - array( + [ 'ignore' => true, 'label' => $this->translate('Save to the Preferences'), - 'decorators' => array('ViewHelper'), + 'decorators' => ['ViewHelper'], 'class' => 'btn-primary' - ) + ] ); } $this->addElement( 'submit', 'btn_submit_session', - array( + [ 'ignore' => true, 'label' => $this->translate('Save for the current Session'), - 'decorators' => array('ViewHelper') - ) + 'decorators' => ['ViewHelper'] + ] ); $this->setAttrib('data-progress-element', 'preferences-progress'); $this->addElement( 'note', 'preferences-progress', - array( - 'decorators' => array( + [ + 'decorators' => [ 'ViewHelper', - array('Spinner', array('id' => 'preferences-progress')) - ) - ) + ['Spinner', ['id' => 'preferences-progress']] + ] + ] ); $this->addDisplayGroup( - array('btn_submit', 'btn_submit_session', 'preferences-progress'), + ['btn_submit', 'btn_submit_session', 'preferences-progress'], 'submit_buttons', - array( - 'decorators' => array( + [ + 'decorators' => [ 'FormElements', - array('HtmlTag', array('tag' => 'div', 'class' => 'control-group form-controls')) - ) - ) + ['HtmlTag', ['tag' => 'div', 'class' => 'control-group form-controls']] + ] + ] ); } diff --git a/application/forms/Security/RoleForm.php b/application/forms/Security/RoleForm.php index ea64fd0cb..804b93a98 100644 --- a/application/forms/Security/RoleForm.php +++ b/application/forms/Security/RoleForm.php @@ -62,7 +62,7 @@ class RoleForm extends RepositoryForm return parent::filterName($value, $allowBrackets) . '_element'; } - public function createInsertElements(array $formData = array()) + public function createInsertElements(array $formData = []) { $this->addElement( 'text',