From 7dc35c2e37cbf16b677965b56584f006c8f1a72f Mon Sep 17 00:00:00 2001 From: Tom Elliott Date: Fri, 4 Sep 2026 14:18:32 -0500 Subject: [PATCH] Name the class at the call site instead of fetching it by string fogproject retired the literal `getClass('X')` in favour of a plain `new` (its ADR 0043), and this is the same sweep here: 163 sites across 49 files. The reason is that getClass() is declared `@return object|mixed`, so nothing can check what you then do with the result and no editor can follow it to a definition -- converting core's 459 sites surfaced 90 PHPStan errors on a baseline that reported zero, every one a pre-existing annotation that had drifted from its body. It was never a substitution seam either: FOGBase::qualify() consults core's map before the plugins', which ADR 0013 says is what stops a plugin answering a core name. Fully qualified rather than imported, because tests/core-references-are-qualified.test.php refuses a bare core name outright -- this tree is fetched on its own and cannot assume a fogproject checkout is anywhere nearby. getClass() with a VARIABLE is untouched. That is the one shape `new` cannot express, and it is what the function is for now; two sites use it. tests/getclass-literals.test.php is the new gate. It refuses a literal getClass() while still allowing the props form and 'ReflectionClass', neither of which has a `new` equivalent, and it was verified by reintroducing a literal and watching it go red. THE HARNESS NEEDED A REAL CHANGE, and it is the interesting part of this commit. tests/stubs/fog-stubs.php answered Hook::getClass() from a registry keyed by short name, so a test could write `Hook::$classes['LocationAssociationManager'] = $manager` and then assert on $manager->batches, because the plugin was handed that very object. A plain `new` resolves for real and cannot hand back somebody else's instance. So StubProxy forwards every call into the registered fixture, and an autoloader materialises any unloaded FOG class as a subclass of it. The registry keeps working unchanged and no test's assertions moved. Three tests read the source as text and pinned the old spelling; they were updated to the new one rather than loosened to accept both. The two NtfyHandler sites are worth noting because they nearly went wrong: they are FOUR-argument calls, and getClass()'s third named parameter is $props, so an arity rule that skips "three or more" reads them as the properties form and an argument-copying rule that takes only the second argument silently drops two. Both were caught by this gate before the sweep landed. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01684dJC9hw1jY4KjzV81BLC --- .gitignore | 1 + capone/src/Hooks/AddBootMenuItem.php | 4 +- capone/src/Hooks/AddCaponeAPI.php | 6 +- capone/src/Managers/CaponeManager.php | 2 +- capone/src/Pages/CaponeManagement.php | 8 +- helloworld/src/Pages/HelloWorldManagement.php | 6 +- ldap/src/Hooks/LDAPPluginHook.php | 2 +- ldap/src/Items/LDAP.php | 2 +- ldap/src/Items/LDAPGroup.php | 2 +- ldap/src/Managers/LDAPManager.php | 24 +-- ldap/src/Pages/LDAPGroupManagement.php | 6 +- ldap/src/Pages/LDAPManagement.php | 8 +- location/src/Hooks/AddLocationAPI.php | 4 +- location/src/Hooks/AddLocationHost.php | 20 +- location/src/Hooks/AddLocationImport.php | 6 +- location/src/Hooks/AddLocationMenuItem.php | 2 +- location/src/Hooks/LocationChangeItems.php | 6 +- .../src/Hooks/LocationDeleteMassItems.php | 2 +- location/src/Managers/LocationManager.php | 4 +- location/src/Pages/LocationManagement.php | 22 +-- ntfy/src/Pages/NtfyManagement.php | 10 +- ntfy/src/Util/NtfyExtends.php | 6 +- oidc/src/Hooks/AddOIDCRoutes.php | 2 +- oidc/src/Items/OIDCGroup.php | 2 +- oidc/src/Managers/OIDCManager.php | 20 +- oidc/src/Pages/OIDCGroupManagement.php | 6 +- oidc/src/Pages/OIDCManagement.php | 6 +- oidc/src/Util/OIDCFlow.php | 20 +- ou/src/Hooks/AddOUHost.php | 16 +- ou/src/Hooks/OUChangeItems.php | 2 +- ou/src/Managers/OUManager.php | 4 +- ou/src/Pages/OUManagement.php | 6 +- pushbullet/src/Pages/PushbulletManagement.php | 9 +- pushbullet/src/Util/PushbulletExtends.php | 5 +- slack/src/Events/ImageComplete_Slack.php | 2 +- slack/src/Events/ImageFail_Slack.php | 2 +- slack/src/Events/LoginFailure_Slack.php | 2 +- slack/src/Events/SnapinComplete_Slack.php | 2 +- slack/src/Events/SnapinTaskComplete_Slack.php | 2 +- slack/src/Hooks/AddSlackAPI.php | 12 +- slack/src/Items/Slack.php | 10 +- slack/src/Pages/SlackManagement.php | 6 +- subnetgroup/src/Hooks/AddSubnetGroupAPI.php | 2 +- .../src/Pages/SubnetGroupManagement.php | 14 +- .../src/Pages/TaskstateeditManagement.php | 10 +- .../src/Pages/TasktypeeditManagement.php | 12 +- tests/getclass-literals.test.php | 173 ++++++++++++++++++ tests/oidc-flow-safety.test.php | 4 +- tests/oidc-single-logout.test.php | 5 +- tests/stubs/fog-stubs.php | 128 +++++++++++++ windowskey/src/Hooks/AddWindowsKeyImage.php | 6 +- windowskey/src/Managers/WindowsKeyManager.php | 4 +- windowskey/src/Pages/WindowsKeyManagement.php | 10 +- .../src/Pages/WOLBroadcastManagement.php | 6 +- 54 files changed, 475 insertions(+), 188 deletions(-) create mode 100644 .gitignore create mode 100644 tests/getclass-literals.test.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..964eedb --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.php-cs-fixer.cache diff --git a/capone/src/Hooks/AddBootMenuItem.php b/capone/src/Hooks/AddBootMenuItem.php index 75c75e7..45c9f84 100644 --- a/capone/src/Hooks/AddBootMenuItem.php +++ b/capone/src/Hooks/AddBootMenuItem.php @@ -72,10 +72,10 @@ public function addBootMenuItem() if (!$dmi) { return; } - $exists = self::getClass('PXEMenuOptionsManager') + $exists = (new \FOG\Managers\PXEMenuOptionsManager()) ->exists('fog.capone', '', 'name'); $args = trim("mode=capone shutdown=$shutdown"); - $entry = self::getClass('PXEMenuOptions') + $entry = (new \FOG\Items\PXEMenuOptions()) ->set('name', 'fog.capone') ->load('name'); if (!$exists) { diff --git a/capone/src/Hooks/AddCaponeAPI.php b/capone/src/Hooks/AddCaponeAPI.php index 8270fc3..319702f 100644 --- a/capone/src/Hooks/AddCaponeAPI.php +++ b/capone/src/Hooks/AddCaponeAPI.php @@ -99,7 +99,7 @@ public function customizeDT($arguments) return; } $arguments['columns'] = []; - foreach (self::getClass('CaponeManager') + foreach ((new \FOG\Plugins\Capone\Managers\CaponeManager()) ->getColumns() as $common => &$real ) { switch ($common) { @@ -139,7 +139,7 @@ public function customizeDT($arguments) . 'sub=edit&id=' . $d . '">' - . self::getClass('Image', $d)->get('name') + . (new \FOG\Items\Image($d))->get('name') . ''; } ]; @@ -152,7 +152,7 @@ public function customizeDT($arguments) } unset($real); } - foreach (self::getClass('OSManager') + foreach ((new \FOG\Managers\OSManager()) ->getColumns() as $common => &$real ) { $arguments['columns'][] = [ diff --git a/capone/src/Managers/CaponeManager.php b/capone/src/Managers/CaponeManager.php index 43837fb..b4cc790 100644 --- a/capone/src/Managers/CaponeManager.php +++ b/capone/src/Managers/CaponeManager.php @@ -124,7 +124,7 @@ public function seedSettings() $category ] ]; - $SettingManager = self::getClass('SettingManager'); + $SettingManager = new \FOG\Managers\SettingManager(); $toInsert = []; foreach ($settings as $setting) { if (!$SettingManager->exists($setting[0], '', 'name')) { diff --git a/capone/src/Pages/CaponeManagement.php b/capone/src/Pages/CaponeManagement.php index 79aad10..2b17907 100644 --- a/capone/src/Pages/CaponeManagement.php +++ b/capone/src/Pages/CaponeManagement.php @@ -63,7 +63,7 @@ protected function _addFields() { $image = filter_input(INPUT_POST, 'image'); $key = filter_input(INPUT_POST, 'key'); - $imageSelector = self::getClass('ImageManager') + $imageSelector = (new \FOG\Managers\ImageManager()) ->buildSelectBox($image); $labelClass = 'col-sm-3 col-form-label'; @@ -149,7 +149,7 @@ function (&$serverFault) { _('The image associated does not have a valid OS!') ); } - $Capone = self::getClass('Capone') + $Capone = (new \FOG\Plugins\Capone\Items\Capone()) ->set('imageID', $imageID) ->set('osID', $osID) ->set('key', $key); @@ -180,7 +180,7 @@ public function caponeGeneral() filter_input(INPUT_POST, 'key') ?: $this->obj->get('key') ); - $imageSelector = self::getClass('ImageManager') + $imageSelector = (new \FOG\Managers\ImageManager()) ->buildSelectBox($image); $labelClass = 'col-sm-3 col-form-label'; @@ -348,7 +348,7 @@ public function globalsettings() $actionType ); - $dmiSelector = self::getClass('DMIKeyManager')->buildSelectBox( + $dmiSelector = (new \FOG\Managers\DMIKeyManager())->buildSelectBox( $dmifield, // Match 'dmifield', // Name of form element 'name', // Sort by diff --git a/helloworld/src/Pages/HelloWorldManagement.php b/helloworld/src/Pages/HelloWorldManagement.php index 38de70a..0a884fa 100644 --- a/helloworld/src/Pages/HelloWorldManagement.php +++ b/helloworld/src/Pages/HelloWorldManagement.php @@ -153,14 +153,14 @@ function (&$serverFault) { if (empty($name)) { throw new \Exception(_('Please enter a name')); } - $exists = self::getClass('HelloWorldManager') + $exists = (new \FOG\Plugins\HelloWorld\Managers\HelloWorldManager()) ->exists($name); if ($exists) { throw new \Exception( _('An entry already exists with this name!') ); } - $HelloWorld = self::getClass('HelloWorld') + $HelloWorld = (new \FOG\Plugins\HelloWorld\Items\HelloWorld()) ->set('name', $name) ->set('description', $description); if (!$HelloWorld->save()) { @@ -278,7 +278,7 @@ public function helloworldGeneralPost() if (empty($name)) { throw new \Exception(_('Please enter a name')); } - $exists = self::getClass('HelloWorldManager') + $exists = (new \FOG\Plugins\HelloWorld\Managers\HelloWorldManager()) ->exists($name); if ($name != $this->obj->get('name') && $exists diff --git a/ldap/src/Hooks/LDAPPluginHook.php b/ldap/src/Hooks/LDAPPluginHook.php index 578d4a1..c8c3284 100644 --- a/ldap/src/Hooks/LDAPPluginHook.php +++ b/ldap/src/Hooks/LDAPPluginHook.php @@ -188,7 +188,7 @@ public function checkAddUser($arguments) $displayName = ''; $ldapAPI = 0; foreach ($items as $ldap) { - $LDAP = self::getClass('LDAP', $ldap->id); + $LDAP = new \FOG\Plugins\LDAP\Items\LDAP($ldap->id); $matched = $LDAP->authLDAP($user, $pass); if (false === $matched) { continue; diff --git a/ldap/src/Items/LDAP.php b/ldap/src/Items/LDAP.php index 9874efd..96f7a2b 100644 --- a/ldap/src/Items/LDAP.php +++ b/ldap/src/Items/LDAP.php @@ -1124,7 +1124,7 @@ public function destroy($key = 'id') 'id' ); foreach ($groupIds as $groupId) { - self::getClass('LDAPGroup', (int)$groupId)->destroy(); + (new \FOG\Plugins\LDAP\Items\LDAPGroup((int)$groupId))->destroy(); } } return parent::destroy($key); diff --git a/ldap/src/Items/LDAPGroup.php b/ldap/src/Items/LDAPGroup.php index 23655f8..1699230 100644 --- a/ldap/src/Items/LDAPGroup.php +++ b/ldap/src/Items/LDAPGroup.php @@ -106,7 +106,7 @@ public static function serverLinkCell($serverID) if (!$serverID) { return \FOG\Router\Route::EMPTY_CELL; } - $name = self::getClass('LDAP', $serverID)->get('name'); + $name = (new \FOG\Plugins\LDAP\Items\LDAP($serverID))->get('name'); // A group outliving its server should still list, not fatal. if (!$name) { return \FOG\Router\Route::EMPTY_CELL; diff --git a/ldap/src/Managers/LDAPManager.php b/ldap/src/Managers/LDAPManager.php index da3aa39..7431cd7 100644 --- a/ldap/src/Managers/LDAPManager.php +++ b/ldap/src/Managers/LDAPManager.php @@ -274,7 +274,7 @@ public function seedSettings() $category ] ]; - $SettingManager = self::getClass('SettingManager'); + $SettingManager = new \FOG\Managers\SettingManager(); $toInsert = []; foreach ($settings as $setting) { if (!$SettingManager->exists($setting[0], '', 'name')) { @@ -754,16 +754,16 @@ function () { // Rewriting a step that anyone has already applied is invisible // to them. Only ever append. function () { - return self::getClass('LDAPGroupManager')->install(); + return (new \FOG\Plugins\LDAP\Managers\LDAPGroupManager())->install(); }, // 6 function () { - return self::getClass('LDAPGroupRoleAssociationManager') + return (new \FOG\Plugins\LDAP\Managers\LDAPGroupRoleAssociationManager()) ->install(); }, // 7 function () { - return self::getClass('LDAPGroupUserGroupAssociationManager') + return (new \FOG\Plugins\LDAP\Managers\LDAPGroupUserGroupAssociationManager()) ->install(); }, // 8 @@ -782,16 +782,16 @@ function () { // outrun the copy. // 10 function () { - return self::getClass('LDAPGroupManager')->install(); + return (new \FOG\Plugins\LDAP\Managers\LDAPGroupManager())->install(); }, // 11 function () { - return self::getClass('LDAPGroupRoleAssociationManager') + return (new \FOG\Plugins\LDAP\Managers\LDAPGroupRoleAssociationManager()) ->install(); }, // 12 function () { - return self::getClass('LDAPGroupUserGroupAssociationManager') + return (new \FOG\Plugins\LDAP\Managers\LDAPGroupUserGroupAssociationManager()) ->install(); }, // 13 @@ -814,7 +814,7 @@ function () { 'DROP TABLE IF EXISTS `LDAPGroupMap`', // 17 function () { - return self::getClass('LDAPUserGrantManager')->install(); + return (new \FOG\Plugins\LDAP\Managers\LDAPUserGrantManager())->install(); }, // 18 function () { @@ -1009,10 +1009,10 @@ public function uninstall() // Associations first, then the groups they point at: dropping the // groups first would leave association rows referencing ids that no // longer exist if either drop failed part way. - self::getClass('LDAPUserGrantManager')->uninstall(); - self::getClass('LDAPGroupRoleAssociationManager')->uninstall(); - self::getClass('LDAPGroupUserGroupAssociationManager')->uninstall(); - self::getClass('LDAPGroupManager')->uninstall(); + (new \FOG\Plugins\LDAP\Managers\LDAPUserGrantManager())->uninstall(); + (new \FOG\Plugins\LDAP\Managers\LDAPGroupRoleAssociationManager())->uninstall(); + (new \FOG\Plugins\LDAP\Managers\LDAPGroupUserGroupAssociationManager())->uninstall(); + (new \FOG\Plugins\LDAP\Managers\LDAPGroupManager())->uninstall(); return parent::uninstall(); } } diff --git a/ldap/src/Pages/LDAPGroupManagement.php b/ldap/src/Pages/LDAPGroupManagement.php index d6e0ef2..e3d3347 100644 --- a/ldap/src/Pages/LDAPGroupManagement.php +++ b/ldap/src/Pages/LDAPGroupManagement.php @@ -172,7 +172,7 @@ function (&$serverFault) { _('That group is already defined for this server!') ); } - $LDAPGroup = self::getClass('LDAPGroup') + $LDAPGroup = (new \FOG\Plugins\LDAP\Items\LDAPGroup()) ->set('name', $name) ->set('serverID', $serverID); if (!$LDAPGroup->save()) { @@ -602,7 +602,7 @@ private static function _ownerID() public function getRoleFeedList() { return $this->_feedList( - self::getClass('Role', self::_ownerID()), + new \FOG\Items\Role(self::_ownerID()), 'ldapgrouproleassociation', 'ldapGroupRoleAssoc', '`ldapGroupRoleAssoc`.`lgraGroupID`', @@ -618,7 +618,7 @@ public function getRoleFeedList() public function getUserGroupFeedList() { return $this->_feedList( - self::getClass('UserGroup', self::_ownerID()), + new \FOG\Items\UserGroup(self::_ownerID()), 'ldapgroupusergroupassociation', 'ldapGroupUserGroupAssoc', '`ldapGroupUserGroupAssoc`.`lgugGroupID`', diff --git a/ldap/src/Pages/LDAPManagement.php b/ldap/src/Pages/LDAPManagement.php index 693a637..3cb5d0f 100644 --- a/ldap/src/Pages/LDAPManagement.php +++ b/ldap/src/Pages/LDAPManagement.php @@ -720,14 +720,14 @@ function (&$serverFault) { // these to reach an LDAPS directory on this server's terms. $tls = self::_tlsFromPost(); $nested = self::_nestedFromPost($tls); - $exists = self::getClass('LDAPManager') + $exists = (new \FOG\Plugins\LDAP\Managers\LDAPManager()) ->exists($ldap); if ($exists) { throw new \Exception( _('An LDAP server already exists with this name!') ); } - $LDAP = self::getClass('LDAP') + $LDAP = (new \FOG\Plugins\LDAP\Items\LDAP()) ->set('name', $ldap) ->set('description', $description) ->set('address', $address) @@ -1217,7 +1217,7 @@ public function ldapGeneral() [ 'fields' => &$fields, 'buttons' => &$buttons, - 'LDAP' => self::getClass('LDAP') + 'LDAP' => new \FOG\Plugins\LDAP\Items\LDAP() ] ); $rendered = self::formFields($fields); @@ -1317,7 +1317,7 @@ public function ldapGeneralPost() // reach an LDAPS directory on this server's terms. $tls = self::_tlsFromPost(); $nested = self::_nestedFromPost($tls); - $exists = self::getClass('LDAPManager') + $exists = (new \FOG\Plugins\LDAP\Managers\LDAPManager()) ->exists($ldap); if ($ldap != $this->obj->get('name') && $exists diff --git a/location/src/Hooks/AddLocationAPI.php b/location/src/Hooks/AddLocationAPI.php index 3c4f56e..6fba38e 100644 --- a/location/src/Hooks/AddLocationAPI.php +++ b/location/src/Hooks/AddLocationAPI.php @@ -168,7 +168,7 @@ public function addPluginItems($arguments) if ($locID < 1) { break; } - $location = \FOG\Router\Route::getClass('location', $locID); + $location = new \FOG\Plugins\Location\Items\Location($locID); if (!$location->isValid()) { break; } @@ -209,7 +209,7 @@ public function addPluginItems($arguments) } $hosts = []; foreach ($hostIDs as $hid) { - $host = \FOG\Router\Route::getClass('host', $hid); + $host = new \FOG\Items\Host($hid); if (!$host->isValid()) { continue; } diff --git a/location/src/Hooks/AddLocationHost.php b/location/src/Hooks/AddLocationHost.php index d29a263..8493029 100644 --- a/location/src/Hooks/AddLocationHost.php +++ b/location/src/Hooks/AddLocationHost.php @@ -113,7 +113,7 @@ public function hostLocation($obj) (int)filter_input(INPUT_POST, 'location') ?: $location ); - $locationSelector = self::getClass('LocationManager') + $locationSelector = (new \FOG\Plugins\Location\Managers\LocationManager()) ->buildSelectBox($locationID, 'location'); $fields = [ @@ -203,7 +203,7 @@ public function hostLocationPost($obj) 'locationassociation', ['hostID' => $hosts] ); - if (self::getClass('Location', $locationID)->isValid()) { + if ((new \FOG\Plugins\Location\Items\Location($locationID))->isValid()) { foreach ((array)$hosts as $ind => &$hostID) { $insert_values[] = [$hostID, $locationID]; unset($hostID); @@ -211,7 +211,7 @@ public function hostLocationPost($obj) } } if (count($insert_values) > 0) { - self::getClass('LocationAssociationManager') + (new \FOG\Plugins\Location\Managers\LocationAssociationManager()) ->insertBatch( $insert_fields, $insert_values @@ -235,10 +235,10 @@ public function hostAddLocationRegister($arguments) return; } $locationID = (int)($_POST['location'] ?? 0); - if (!self::getClass('Location', $locationID)->isValid()) { + if (!(new \FOG\Plugins\Location\Items\Location($locationID))->isValid()) { return; } - self::getClass('LocationAssociationManager') + (new \FOG\Plugins\Location\Managers\LocationAssociationManager()) ->insertBatch( ['hostID', 'locationID'], [[$obj->get('id'), $locationID]] @@ -305,7 +305,7 @@ public function hostAddLocationField($arguments) return; } $locationID = (int)filter_input(INPUT_POST, 'location'); - $locationSelector = self::getClass('LocationManager') + $locationSelector = (new \FOG\Plugins\Location\Managers\LocationManager()) ->buildSelectBox($locationID, 'location'); $arguments['fields'][ @@ -349,7 +349,7 @@ public function massEditFields($arguments) $arguments['fields']['location'] = [ 'label' => _('Host Location'), - 'input' => self::getClass('LocationManager')->buildSelectBox( + 'input' => (new \FOG\Plugins\Location\Managers\LocationManager())->buildSelectBox( '', 'value[location]', 'name', @@ -391,7 +391,7 @@ private function _sharedLocation(array $hostIDs) )['location']; if (!empty($info['uniform']) && '' !== (string)$info['value']) { - $item = self::getClass('Location', (int)$info['value']); + $item = new \FOG\Plugins\Location\Items\Location((int)$info['value']); if ($item->isValid()) { $info['value'] = $item->get('name'); } @@ -440,7 +440,7 @@ function ($id) { // an instruction to clear: silently turning it into one would // strip the location off every selected host. if ($itemID < 1 - || !self::getClass('Location', $itemID)->isValid() + || !(new \FOG\Plugins\Location\Items\Location($itemID))->isValid() ) { throw new \Exception(_('Invalid Location selected')); } @@ -460,7 +460,7 @@ function ($id) { foreach ($hostIDs as $hostID) { $insert_values[] = [$hostID, $itemID]; } - self::getClass('LocationAssociationManager') + (new \FOG\Plugins\Location\Managers\LocationAssociationManager()) ->insertBatch(['hostID', 'locationID'], $insert_values); } } diff --git a/location/src/Hooks/AddLocationImport.php b/location/src/Hooks/AddLocationImport.php index c71eae1..49a1bd0 100644 --- a/location/src/Hooks/AddLocationImport.php +++ b/location/src/Hooks/AddLocationImport.php @@ -145,7 +145,7 @@ public function getLocationNames($host) ); $names = []; foreach ((array)$locationIDs as $locationID) { - $Location = self::getClass('Location', $locationID); + $Location = new \FOG\Plugins\Location\Items\Location($locationID); if ($Location->isValid()) { $names[] = $Location->get('name'); } @@ -173,8 +173,8 @@ public function applyLocation($host, $ids) ['hostID' => $hostID] ); $locationID = array_shift($ids); - if (self::getClass('Location', $locationID)->isValid()) { - self::getClass('LocationAssociationManager') + if ((new \FOG\Plugins\Location\Items\Location($locationID))->isValid()) { + (new \FOG\Plugins\Location\Managers\LocationAssociationManager()) ->insertBatch( ['hostID', 'locationID'], [[$hostID, $locationID]] diff --git a/location/src/Hooks/AddLocationMenuItem.php b/location/src/Hooks/AddLocationMenuItem.php index 76b7f49..0a5bbb9 100644 --- a/location/src/Hooks/AddLocationMenuItem.php +++ b/location/src/Hooks/AddLocationMenuItem.php @@ -124,7 +124,7 @@ public function menuData($arguments) if (self::getSetting('FOG_SNAPIN_LOCATION_SEND_ENABLED') !== null) { return; } - $Setting = self::getClass('Setting') + $Setting = (new \FOG\Items\Setting()) ->set( 'name', 'FOG_SNAPIN_LOCATION_SEND_ENABLED' diff --git a/location/src/Hooks/LocationChangeItems.php b/location/src/Hooks/LocationChangeItems.php index 950749b..5ae6d94 100644 --- a/location/src/Hooks/LocationChangeItems.php +++ b/location/src/Hooks/LocationChangeItems.php @@ -108,7 +108,7 @@ public function storageNodeSetting($arguments) $TaskType = $arguments['TaskType'] ?? null; $method = false; foreach ($LocationAssocs as &$LocationAssoc) { - $Location = self::getClass('Location', $LocationAssoc->locationID); + $Location = new \FOG\Plugins\Location\Items\Location($LocationAssoc->locationID); if (!$Location->isValid()) { continue; } @@ -165,7 +165,7 @@ public function storageGroupSetting($arguments) ['hostID' => $arguments['Host']->get('id')] ); foreach ($LocationAssocs as &$LocationAssoc) { - $StorageGroup = self::getClass('Location', $LocationAssoc->locationID) + $StorageGroup = (new \FOG\Plugins\Location\Items\Location($LocationAssoc->locationID)) ->getStorageGroup(); // Inverted since it was written: this skipped the groups it // should have answered with and offered up only invalid ones, @@ -197,7 +197,7 @@ public function bootItemSettings($arguments) ['hostID' => $arguments['Host']->get('id')] ); foreach ($LocationAssocs as &$LocationAssoc) { - $Location = self::getClass('Location', $LocationAssoc->locationID); + $Location = new \FOG\Plugins\Location\Items\Location($LocationAssoc->locationID); if (!$Location->get('tftp')) { continue; } diff --git a/location/src/Hooks/LocationDeleteMassItems.php b/location/src/Hooks/LocationDeleteMassItems.php index 1a1e4cb..9deab83 100644 --- a/location/src/Hooks/LocationDeleteMassItems.php +++ b/location/src/Hooks/LocationDeleteMassItems.php @@ -102,7 +102,7 @@ public function deletemassitems($arguments) // between deploying this code and running the schema updater // has the column and not the foreign key, and there this is // the only thing doing the work. - self::getClass('LocationManager')->update( + (new \FOG\Plugins\Location\Managers\LocationManager())->update( ['storagenodeID' => $arguments['itemIDs']], '', ['storagenodeID' => null] diff --git a/location/src/Managers/LocationManager.php b/location/src/Managers/LocationManager.php index 39aa62d..d866942 100644 --- a/location/src/Managers/LocationManager.php +++ b/location/src/Managers/LocationManager.php @@ -130,7 +130,7 @@ public function schema() // 0 $this->createSql(), // 1 - self::getClass('LocationAssociationManager')->createSql(), + (new \FOG\Plugins\Location\Managers\LocationAssociationManager())->createSql(), // 2 - retire the bogus UNIQUE (lStorageGroupID, lStorageNodeID). // See createSql() for what it was doing: silently overwriting an // existing location instead of creating a second one in the same @@ -267,7 +267,7 @@ public function uninstall() 'setting', ['name' => 'FOG_SNAPIN_LOCATION_SEND_ENABLED'] ); - self::getClass('LocationAssociationManager')->uninstall(); + (new \FOG\Plugins\Location\Managers\LocationAssociationManager())->uninstall(); return parent::uninstall(); } /** diff --git a/location/src/Pages/LocationManagement.php b/location/src/Pages/LocationManagement.php index f65212b..9124d73 100644 --- a/location/src/Pages/LocationManagement.php +++ b/location/src/Pages/LocationManagement.php @@ -70,11 +70,11 @@ protected function _addFields() $storagegroup = filter_input(INPUT_POST, 'storagegroup'); $storagenode = filter_input(INPUT_POST, 'storagenode'); $storagenodeprotocol = filter_input(INPUT_POST, 'storagenodeprotocol'); - $storagegroupSelector = self::getClass('StorageGroupManager') + $storagegroupSelector = (new \FOG\Managers\StorageGroupManager()) ->buildSelectBox($storagegroup); - $storagenodeSelector = self::getClass('StorageNodeManager') + $storagenodeSelector = (new \FOG\Managers\StorageNodeManager()) ->buildSelectBox($storagenode); - $storagenodeProtocolSelector = self::getClass('LocationManager') + $storagenodeProtocolSelector = (new \FOG\Plugins\Location\Managers\LocationManager()) ->buildProtocolSelectBox($storagenodeprotocol); $labelClass = 'col-sm-3 col-form-label'; @@ -195,7 +195,7 @@ function (&$serverFault) { filter_input(INPUT_POST, 'storagenodeprotocol') ); $bootfrom = (int)isset($_POST['bootfrom']); - $exists = self::getClass('LocationManager') + $exists = (new \FOG\Plugins\Location\Managers\LocationManager()) ->exists($location); if ($exists) { throw new \Exception( @@ -208,10 +208,10 @@ function (&$serverFault) { ); } if ($storagenode) { - $storagegroup = self::getClass('StorageNode', $storagenode) + $storagegroup = (new \FOG\Items\StorageNode($storagenode)) ->get('storagegroupID'); } - $Location = self::getClass('Location') + $Location = (new \FOG\Plugins\Location\Items\Location()) ->set('name', $location) ->set('storagegroupID', $storagegroup) ->set('storagenodeID', $storagenode) @@ -252,11 +252,11 @@ public function locationGeneral() filter_input(INPUT_POST, 'storagenodeprotocol') ?: $this->obj->get('protocol') ); - $storagegroupSelector = self::getClass('StorageGroupManager') + $storagegroupSelector = (new \FOG\Managers\StorageGroupManager()) ->buildSelectBox($storagegroup); - $storagenodeSelector = self::getClass('StorageNodeManager') + $storagenodeSelector = (new \FOG\Managers\StorageNodeManager()) ->buildSelectBox($storagenode); - $storagenodeProtocolSelector = self::getCLass('LocationManager') + $storagenodeProtocolSelector = (new \FOG\Plugins\Location\Managers\LocationManager()) ->buildProtocolSelectBox($storagenodeprotocol); $bootfrom = ( isset($_POST['bootfrom']) ? @@ -398,7 +398,7 @@ public function locationGeneralPost() ); $bootfrom = (int)isset($_POST['bootfrom']); - $exists = self::getClass('LocationManager') + $exists = (new \FOG\Plugins\Location\Managers\LocationManager()) ->exists($location); if ($location != $this->obj->get('name') && $exists @@ -413,7 +413,7 @@ public function locationGeneralPost() ); } if ($storagenode) { - $storagegroup = self::getClass('StorageNode', $storagenode) + $storagegroup = (new \FOG\Items\StorageNode($storagenode)) ->get('storagegroupID'); } $this->obj diff --git a/ntfy/src/Pages/NtfyManagement.php b/ntfy/src/Pages/NtfyManagement.php index 3adeb30..c4aa2b2 100644 --- a/ntfy/src/Pages/NtfyManagement.php +++ b/ntfy/src/Pages/NtfyManagement.php @@ -166,12 +166,12 @@ function (&$serverFault) { _('A server URL and topic endpoint are required') ); } - $existing = self::getClass('NtfyManager') + $existing = (new \FOG\Plugins\Ntfy\Managers\NtfyManager()) ->exists($topicEndpoint, 0, 'topicEndpoint'); if ($existing) { throw new \Exception(_('Topic already linked')); } - $Ntfy = self::getClass('Ntfy') + $Ntfy = (new \FOG\Plugins\Ntfy\Items\Ntfy()) ->set('serverURL', $serverURL) ->set('topicEndpoint', $topicEndpoint) ->set('credentials', $credentials); @@ -179,12 +179,12 @@ function (&$serverFault) { $serverFault = true; throw new \Exception(_('Add ntfy topic failed!')); } - self::getClass( - 'NtfyHandler', + $handler = new \FOG\Plugins\Ntfy\Util\NtfyHandler( $serverURL, $topicEndpoint, $credentials - )->pushNote( + ); + $handler->pushNote( 'FOG', _('Topic linked') ); diff --git a/ntfy/src/Util/NtfyExtends.php b/ntfy/src/Util/NtfyExtends.php index 139ed4a..3174a87 100644 --- a/ntfy/src/Util/NtfyExtends.php +++ b/ntfy/src/Util/NtfyExtends.php @@ -97,12 +97,12 @@ public function __construct() ltrim($Ntfy->topicEndpoint, '/') ); try { - $response = self::getClass( - 'NtfyHandler', + $handler = new \FOG\Plugins\Ntfy\Util\NtfyHandler( $Ntfy->serverURL, $Ntfy->topicEndpoint, $Ntfy->credentials - )->pushNote( + ); + $response = $handler->pushNote( $title, _(self::$message) ); diff --git a/oidc/src/Hooks/AddOIDCRoutes.php b/oidc/src/Hooks/AddOIDCRoutes.php index 7af1a5f..ad7fed9 100644 --- a/oidc/src/Hooks/AddOIDCRoutes.php +++ b/oidc/src/Hooks/AddOIDCRoutes.php @@ -113,7 +113,7 @@ public function loginButtons($arguments) { $ids = \FOG\Router\Route::getIds('oidc', ['enabled' => [1]]); foreach ((array)$ids as $id) { - $provider = self::getClass('OIDC', $id); + $provider = new \FOG\Plugins\OIDC\Items\OIDC($id); if (!$provider->isValid()) { continue; } diff --git a/oidc/src/Items/OIDCGroup.php b/oidc/src/Items/OIDCGroup.php index 261aa2e..7eb17d7 100644 --- a/oidc/src/Items/OIDCGroup.php +++ b/oidc/src/Items/OIDCGroup.php @@ -101,7 +101,7 @@ public static function providerLinkCell($providerID) if (!$providerID) { return \FOG\Router\Route::EMPTY_CELL; } - $name = self::getClass('OIDC', $providerID)->get('name'); + $name = (new \FOG\Plugins\OIDC\Items\OIDC($providerID))->get('name'); // A group outliving its provider should still list, not fatal. if (!$name) { return \FOG\Router\Route::EMPTY_CELL; diff --git a/oidc/src/Managers/OIDCManager.php b/oidc/src/Managers/OIDCManager.php index 3a1bb4d..3b67fad 100644 --- a/oidc/src/Managers/OIDCManager.php +++ b/oidc/src/Managers/OIDCManager.php @@ -198,27 +198,27 @@ public function schema() $this->createSql(), // 1 - the provider-subject to FOG-user links. function () { - return self::getClass('OIDCIdentityManager')->install(); + return (new \FOG\Plugins\OIDC\Managers\OIDCIdentityManager())->install(); }, // 2 - the group claim values an admin maps. function () { - return self::getClass('OIDCGroupManager')->install(); + return (new \FOG\Plugins\OIDC\Managers\OIDCGroupManager())->install(); }, // 3 - what a group grants: roles. function () { - return self::getClass('OIDCGroupRoleAssociationManager') + return (new \FOG\Plugins\OIDC\Managers\OIDCGroupRoleAssociationManager()) ->install(); }, // 4 - what a group grants: user groups. function () { - return self::getClass('OIDCGroupUserGroupAssociationManager') + return (new \FOG\Plugins\OIDC\Managers\OIDCGroupUserGroupAssociationManager()) ->install(); }, // 5 - the record of what this plugin granted each user, which is // what lets a later sign in take a grant back without touching // anything an admin assigned by hand. function () { - return self::getClass('OIDCUserGrantManager')->install(); + return (new \FOG\Plugins\OIDC\Managers\OIDCUserGrantManager())->install(); }, // 6 - RP-initiated logout, per provider (#15). Appended rather // than folded into step 0, because installdb() SKIPS the first @@ -360,11 +360,11 @@ public function install() */ public function uninstall() { - self::getClass('OIDCIdentityManager')->uninstall(); - self::getClass('OIDCGroupRoleAssociationManager')->uninstall(); - self::getClass('OIDCGroupUserGroupAssociationManager')->uninstall(); - self::getClass('OIDCGroupManager')->uninstall(); - self::getClass('OIDCUserGrantManager')->uninstall(); + (new \FOG\Plugins\OIDC\Managers\OIDCIdentityManager())->uninstall(); + (new \FOG\Plugins\OIDC\Managers\OIDCGroupRoleAssociationManager())->uninstall(); + (new \FOG\Plugins\OIDC\Managers\OIDCGroupUserGroupAssociationManager())->uninstall(); + (new \FOG\Plugins\OIDC\Managers\OIDCGroupManager())->uninstall(); + (new \FOG\Plugins\OIDC\Managers\OIDCUserGrantManager())->uninstall(); return parent::uninstall(); } } diff --git a/oidc/src/Pages/OIDCGroupManagement.php b/oidc/src/Pages/OIDCGroupManagement.php index 7558a74..13b93e9 100644 --- a/oidc/src/Pages/OIDCGroupManagement.php +++ b/oidc/src/Pages/OIDCGroupManagement.php @@ -172,7 +172,7 @@ function (&$serverFault) { _('That group is already defined for this provider!') ); } - $OIDCGroup = self::getClass('OIDCGroup') + $OIDCGroup = (new \FOG\Plugins\OIDC\Items\OIDCGroup()) ->set('name', $name) ->set('providerID', $providerID); if (!$OIDCGroup->save()) { @@ -609,7 +609,7 @@ private static function _ownerID() public function getRoleFeedList() { return $this->_feedList( - self::getClass('Role', self::_ownerID()), + new \FOG\Items\Role(self::_ownerID()), 'oidcgrouproleassociation', 'oidcGroupRoleAssoc', '`oidcGroupRoleAssoc`.`ograGroupID`', @@ -625,7 +625,7 @@ public function getRoleFeedList() public function getUserGroupFeedList() { return $this->_feedList( - self::getClass('UserGroup', self::_ownerID()), + new \FOG\Items\UserGroup(self::_ownerID()), 'oidcgroupusergroupassociation', 'oidcGroupUserGroupAssoc', '`oidcGroupUserGroupAssoc`.`ogugGroupID`', diff --git a/oidc/src/Pages/OIDCManagement.php b/oidc/src/Pages/OIDCManagement.php index 1c3457e..61cc75a 100644 --- a/oidc/src/Pages/OIDCManagement.php +++ b/oidc/src/Pages/OIDCManagement.php @@ -256,12 +256,12 @@ function (&$serverFault) { if ('' === $name) { throw new \Exception(_('Please enter a name')); } - if (self::getClass('OIDCManager')->exists($name)) { + if ((new \FOG\Plugins\OIDC\Managers\OIDCManager())->exists($name)) { throw new \Exception( _('A provider already exists with this name!') ); } - $OIDC = self::getClass('OIDC') + $OIDC = (new \FOG\Plugins\OIDC\Items\OIDC()) ->set('name', $name) ->set( 'description', @@ -609,7 +609,7 @@ public function oidcGeneralPost() throw new \Exception(_('Please enter a name')); } if ($name != $this->obj->get('name') - && self::getClass('OIDCManager')->exists($name) + && (new \FOG\Plugins\OIDC\Managers\OIDCManager())->exists($name) ) { throw new \Exception( _('A provider already exists with this name!') diff --git a/oidc/src/Util/OIDCFlow.php b/oidc/src/Util/OIDCFlow.php index b9945f6..2dee751 100644 --- a/oidc/src/Util/OIDCFlow.php +++ b/oidc/src/Util/OIDCFlow.php @@ -236,7 +236,7 @@ public static function callback() */ self::_session(); $_SESSION = []; - self::$FOGUser = self::getClass('User', 0); + self::$FOGUser = new \FOG\Items\User(0); // Provenance, not decoration: an audit has to be able to tell // this session from a password one, and the break-glass rules @@ -375,7 +375,7 @@ public static function loginRedirectUrl() if ($id < 1) { return ''; } - $provider = self::getClass('OIDC', $id); + $provider = new \FOG\Plugins\OIDC\Items\OIDC($id); if (!$provider->isValid() || '1' !== (string)$provider->get('enabled') || '1' !== (string)$provider->get('autoRedirect') @@ -411,7 +411,7 @@ public static function logoutUrl() if (!is_array($stored) || empty($stored['endpoint'])) { return ''; } - $provider = self::getClass('OIDC', (int)($stored['provider'] ?? 0)); + $provider = new \FOG\Plugins\OIDC\Items\OIDC((int)($stored['provider'] ?? 0)); if (!$provider->isValid() || '1' !== (string)$provider->get('enabled') || '1' !== (string)$provider->get('singleLogout') @@ -459,7 +459,7 @@ private static function _session() */ private static function _enabledProvider($id) { - $provider = self::getClass('OIDC', (int)$id); + $provider = new \FOG\Plugins\OIDC\Items\OIDC((int)$id); if (!$provider->isValid()) { throw new \Exception(_('Unknown identity provider')); } @@ -662,7 +662,7 @@ private static function _resolveUser($provider, array $claims) } $linkedId = OIDCIdentity::userIdFor($provider->get('id'), $subject); - $byName = self::getClass('User') + $byName = (new \FOG\Items\User()) ->set('name', $username) ->load('name'); $namedId = $byName->isValid() ? (int)$byName->get('id') : 0; @@ -690,7 +690,7 @@ private static function _resolveUser($provider, array $claims) _('This identity is linked to a different FOG account') ); } - $user = self::getClass('User', $linkedId); + $user = new \FOG\Items\User($linkedId); if (!$user->isValid()) { throw new \Exception( _('The FOG account for this identity no longer exists') @@ -723,7 +723,7 @@ private static function _resolveUser($provider, array $claims) * unable to use a local password, and taking password login away * from an account an admin created is the opposite of break-glass. */ - self::getClass('OIDCIdentity') + (new \FOG\Plugins\OIDC\Items\OIDCIdentity()) ->set('name', $username) ->set('providerId', $provider->get('id')) ->set('subject', $subject) @@ -826,7 +826,7 @@ private static function _refreshProfile($provider, array $claims, $user) */ private static function _provisionUser($provider, array $claims, $username) { - $user = self::getClass('User') + $user = (new \FOG\Items\User()) ->set('name', $username) ->set('display', trim((string)($claims['name'] ?? '')) ?: $username) ->set('authsource', OIDC::AUTH_SOURCE) @@ -840,7 +840,7 @@ private static function _provisionUser($provider, array $claims, $username) } // After the save: the link needs the id, which does not exist until // then. - self::getClass('OIDCIdentity') + (new \FOG\Plugins\OIDC\Items\OIDCIdentity()) ->set('name', $username) ->set('providerId', $provider->get('id')) ->set('subject', (string)$claims['sub']) @@ -1210,7 +1210,7 @@ private static function _post($url, $body) */ private static function _http($url, $method, $body) { - $requests = self::getClass('FOGURLRequests'); + $requests = new \FOG\Net\FOGURLRequests(); $status = 0; $response = $requests->process( $url, diff --git a/ou/src/Hooks/AddOUHost.php b/ou/src/Hooks/AddOUHost.php index f6e450d..6387063 100644 --- a/ou/src/Hooks/AddOUHost.php +++ b/ou/src/Hooks/AddOUHost.php @@ -113,7 +113,7 @@ public function hostOU($obj) (int)filter_input(INPUT_POST, 'ou') ?: $ou ); - $ouSelector = self::getClass('OUManager') + $ouSelector = (new \FOG\Plugins\OU\Managers\OUManager()) ->buildSelectBox($ouID, 'ou'); $fields = [ @@ -212,7 +212,7 @@ public function hostOUPost($obj) } } if (count($insert_values) > 0) { - self::getClass('OUAssociationManager') + (new \FOG\Plugins\OU\Managers\OUAssociationManager()) ->insertBatch( $insert_fields, $insert_values @@ -239,7 +239,7 @@ public function hostAddOURegister($arguments) if ($ouID < 1) { return; } - self::getClass('OUAssociationManager') + (new \FOG\Plugins\OU\Managers\OUAssociationManager()) ->insertBatch( ['hostID', 'ouID'], [[$obj->get('id'), $ouID]] @@ -306,7 +306,7 @@ public function hostAddOUField($arguments) return; } $ouID = (int)filter_input(INPUT_POST, 'ou'); - $ouSelector = self::getClass('OUManager') + $ouSelector = (new \FOG\Plugins\OU\Managers\OUManager()) ->buildSelectBox($ouID, 'ou'); $arguments['fields'][ @@ -350,7 +350,7 @@ public function massEditFields($arguments) $arguments['fields']['ou'] = [ 'label' => _('Host OU'), - 'input' => self::getClass('OUManager')->buildSelectBox( + 'input' => (new \FOG\Plugins\OU\Managers\OUManager())->buildSelectBox( '', 'value[ou]', 'name', @@ -392,7 +392,7 @@ private function _sharedOU(array $hostIDs) )['ou']; if (!empty($info['uniform']) && '' !== (string)$info['value']) { - $item = self::getClass('OU', (int)$info['value']); + $item = new \FOG\Plugins\OU\Items\OU((int)$info['value']); if ($item->isValid()) { $info['value'] = $item->get('name'); } @@ -441,7 +441,7 @@ function ($id) { // an instruction to clear: silently turning it into one would // strip the ou off every selected host. if ($itemID < 1 - || !self::getClass('OU', $itemID)->isValid() + || !(new \FOG\Plugins\OU\Items\OU($itemID))->isValid() ) { throw new \Exception(_('Invalid OU selected')); } @@ -461,7 +461,7 @@ function ($id) { foreach ($hostIDs as $hostID) { $insert_values[] = [$hostID, $itemID]; } - self::getClass('OUAssociationManager') + (new \FOG\Plugins\OU\Managers\OUAssociationManager()) ->insertBatch(['hostID', 'ouID'], $insert_values); } } diff --git a/ou/src/Hooks/OUChangeItems.php b/ou/src/Hooks/OUChangeItems.php index 96f7861..77a2bd6 100644 --- a/ou/src/Hooks/OUChangeItems.php +++ b/ou/src/Hooks/OUChangeItems.php @@ -96,7 +96,7 @@ public function changeADItems($arguments) // left behind by a deleted OU would end the whole check-in with a // 404 the client reads as a transport failure, rather than skip // one association. - $OU = self::getClass('OU', $OUAssoc->ouID); + $OU = new \FOG\Plugins\OU\Items\OU($OUAssoc->ouID); if (!$OU->isValid()) { continue; } diff --git a/ou/src/Managers/OUManager.php b/ou/src/Managers/OUManager.php index 58231b1..c0f300b 100644 --- a/ou/src/Managers/OUManager.php +++ b/ou/src/Managers/OUManager.php @@ -96,7 +96,7 @@ public function schema() // 0 $this->createSql(), // 1 - self::getClass('OUAssociationManager')->createSql(), + (new \FOG\Plugins\OU\Managers\OUAssociationManager())->createSql(), // 2 - the plugin's foreign keys. // // fogproject ADR 0031 decision 8: sweep, then add. ADD CONSTRAINT @@ -155,7 +155,7 @@ public function install() public function uninstall() { $res = true; - self::getClass('OUAssociationManager')->uninstall(); + (new \FOG\Plugins\OU\Managers\OUAssociationManager())->uninstall(); return parent::uninstall(); } } diff --git a/ou/src/Pages/OUManagement.php b/ou/src/Pages/OUManagement.php index 7ebad75..71b96f2 100644 --- a/ou/src/Pages/OUManagement.php +++ b/ou/src/Pages/OUManagement.php @@ -155,14 +155,14 @@ function (&$serverFault) { $oudn = trim( filter_input(INPUT_POST, 'oudn') ); - $exists = self::getClass('OUManager') + $exists = (new \FOG\Plugins\OU\Managers\OUManager()) ->exists($ou); if ($exists) { throw new \Exception( _('An ou already exists with this name!') ); } - $OU = self::getClass('OU') + $OU = (new \FOG\Plugins\OU\Items\OU()) ->set('name', $ou) ->set('description', $description) ->set('ou', $oudn); @@ -298,7 +298,7 @@ public function ouGeneralPost() filter_input(INPUT_POST, 'oudn') ); - $exists = self::getClass('OUManager') + $exists = (new \FOG\Plugins\OU\Managers\OUManager()) ->exists($ou); if ($ou != $this->obj->get('name') && $exists diff --git a/pushbullet/src/Pages/PushbulletManagement.php b/pushbullet/src/Pages/PushbulletManagement.php index dbd4976..af12695 100644 --- a/pushbullet/src/Pages/PushbulletManagement.php +++ b/pushbullet/src/Pages/PushbulletManagement.php @@ -121,16 +121,13 @@ function (&$serverFault) { $token = trim( filter_input(INPUT_POST, 'apiToken') ); - $exists = self::getClass('PushbulletManager') + $exists = (new \FOG\Plugins\Pushbullet\Managers\PushbulletManager()) ->exists($token, '', 'token'); if ($exists) { throw new \Exception(_('Account already linked')); } - $userInfo = self::getClass( - 'PushbulletHandler', - $token - )->getUserInformation(); - $Pushbullet = self::getClass('Pushbullet') + $userInfo = (new \FOG\Plugins\Pushbullet\Util\PushbulletHandler($token))->getUserInformation(); + $Pushbullet = (new \FOG\Plugins\Pushbullet\Items\Pushbullet()) ->set('token', $token) ->set('name', $userInfo->name) ->set('email', $userInfo->email); diff --git a/pushbullet/src/Util/PushbulletExtends.php b/pushbullet/src/Util/PushbulletExtends.php index 8a17cf2..dc5e1cf 100644 --- a/pushbullet/src/Util/PushbulletExtends.php +++ b/pushbullet/src/Util/PushbulletExtends.php @@ -91,10 +91,7 @@ public function __construct() _(self::$shortdesc) ) ); - self::getClass( - 'PushbulletHandler', - $Pushbullet->token - )->pushNote( + (new \FOG\Plugins\Pushbullet\Util\PushbulletHandler($Pushbullet->token))->pushNote( '', $title, _(self::$message) diff --git a/slack/src/Events/ImageComplete_Slack.php b/slack/src/Events/ImageComplete_Slack.php index 417f8ac..839650e 100644 --- a/slack/src/Events/ImageComplete_Slack.php +++ b/slack/src/Events/ImageComplete_Slack.php @@ -85,7 +85,7 @@ public function onEvent($event, $data) $image ) ]; - self::getClass('Slack', $Slack->id)->call('chat.postMessage', $args); + (new \FOG\Plugins\Slack\Items\Slack($Slack->id))->call('chat.postMessage', $args); } } } diff --git a/slack/src/Events/ImageFail_Slack.php b/slack/src/Events/ImageFail_Slack.php index 96f3733..a1d50ae 100644 --- a/slack/src/Events/ImageFail_Slack.php +++ b/slack/src/Events/ImageFail_Slack.php @@ -80,7 +80,7 @@ public function onEvent($event, $data) $reason ) ]; - self::getClass('Slack', $Slack->id)->call('chat.postMessage', $args); + (new \FOG\Plugins\Slack\Items\Slack($Slack->id))->call('chat.postMessage', $args); } } } diff --git a/slack/src/Events/LoginFailure_Slack.php b/slack/src/Events/LoginFailure_Slack.php index b65f2bc..689db81 100644 --- a/slack/src/Events/LoginFailure_Slack.php +++ b/slack/src/Events/LoginFailure_Slack.php @@ -68,7 +68,7 @@ public function onEvent($event, $data) $ip ) ]; - self::getClass('Slack', $Slack->id)->call('chat.postMessage', $args); + (new \FOG\Plugins\Slack\Items\Slack($Slack->id))->call('chat.postMessage', $args); unset($Slack); } } diff --git a/slack/src/Events/SnapinComplete_Slack.php b/slack/src/Events/SnapinComplete_Slack.php index 302d5ad..8d8dc5a 100644 --- a/slack/src/Events/SnapinComplete_Slack.php +++ b/slack/src/Events/SnapinComplete_Slack.php @@ -65,7 +65,7 @@ public function onEvent($event, $data) _('has completed snapin tasking') ) ]; - self::getClass('Slack', $Slack->id)->call('chat.postMessage', $args); + (new \FOG\Plugins\Slack\Items\Slack($Slack->id))->call('chat.postMessage', $args); } } } diff --git a/slack/src/Events/SnapinTaskComplete_Slack.php b/slack/src/Events/SnapinTaskComplete_Slack.php index 1abc6b8..59afec1 100644 --- a/slack/src/Events/SnapinTaskComplete_Slack.php +++ b/slack/src/Events/SnapinTaskComplete_Slack.php @@ -72,7 +72,7 @@ public function onEvent($event, $data) $statuscode ) ]; - self::getClass('Slack', $Slack->id)->call('chat.postMessage', $args); + (new \FOG\Plugins\Slack\Items\Slack($Slack->id))->call('chat.postMessage', $args); } } } diff --git a/slack/src/Hooks/AddSlackAPI.php b/slack/src/Hooks/AddSlackAPI.php index 0d8b399..6081180 100644 --- a/slack/src/Hooks/AddSlackAPI.php +++ b/slack/src/Hooks/AddSlackAPI.php @@ -99,7 +99,7 @@ public function customizeDT($arguments) return; } $arguments['columns'] = []; - foreach (self::getClass('SlackManager') + foreach ((new \FOG\Plugins\Slack\Managers\SlackManager()) ->getColumns() as $common => $real ) { switch ($common) { @@ -115,10 +115,7 @@ public function customizeDT($arguments) 'db' => $real, 'dt' => $common, 'formatter' => function ($d, $row) { - $team = self::getClass( - 'Slack', - $d - )->call('auth.test'); + $team = (new \FOG\Plugins\Slack\Items\Slack($d))->call('auth.test'); return $team['team']; } ]; @@ -128,10 +125,7 @@ public function customizeDT($arguments) 'db' => $real, 'dt' => $common, 'formatter' => function ($d, $row) { - $team = self::getClass( - 'Slack', - $row['sID'] - )->call('auth.test'); + $team = (new \FOG\Plugins\Slack\Items\Slack($row['sID']))->call('auth.test'); return $team['user']; ; } diff --git a/slack/src/Items/Slack.php b/slack/src/Items/Slack.php index 405d441..87ae684 100644 --- a/slack/src/Items/Slack.php +++ b/slack/src/Items/Slack.php @@ -104,10 +104,7 @@ public function getUsers() */ public function verifyToken() { - $testAuth = self::getClass( - 'SlackHandler', - $this->get('token') - )->call('auth.test'); + $testAuth = (new \FOG\Plugins\Slack\Util\SlackHandler($this->get('token')))->call('auth.test'); return (bool)$testAuth['ok']; } /** @@ -130,9 +127,6 @@ public function call($method, $args = []) $args['as_user'] = true; } } - return self::getClass( - 'SlackHandler', - $this->get('token') - )->call($method, $args); + return (new \FOG\Plugins\Slack\Util\SlackHandler($this->get('token')))->call($method, $args); } } diff --git a/slack/src/Pages/SlackManagement.php b/slack/src/Pages/SlackManagement.php index a2c273c..873adeb 100644 --- a/slack/src/Pages/SlackManagement.php +++ b/slack/src/Pages/SlackManagement.php @@ -147,7 +147,7 @@ function (&$serverFault) { _('Please start user/channel with @/# respectively') ); } - $Slack = self::getClass('Slack') + $Slack = (new \FOG\Plugins\Slack\Items\Slack()) ->set('token', $token) ->set('name', $user); if (!$Slack->verifyToken()) { @@ -172,9 +172,9 @@ function (&$serverFault) { throw new \Exception(_('Channel not found')); } } - $exists = self::getClass('SlackManager') + $exists = (new \FOG\Plugins\Slack\Managers\SlackManager()) ->exists($token, '', 'token'); - $exists2 = self::getClass('SlackManager') + $exists2 = (new \FOG\Plugins\Slack\Managers\SlackManager()) ->exists($usersend); if ($exists || $exists2) { throw new \Exception( diff --git a/subnetgroup/src/Hooks/AddSubnetGroupAPI.php b/subnetgroup/src/Hooks/AddSubnetGroupAPI.php index ed1face..62de8ab 100644 --- a/subnetgroup/src/Hooks/AddSubnetGroupAPI.php +++ b/subnetgroup/src/Hooks/AddSubnetGroupAPI.php @@ -81,7 +81,7 @@ public function customizeDT($arguments) 'dt' => 'group', 'removeFromQuery' => true, 'formatter' => function ($d, $row) use ($arguments) { - return self::getClass('group', $row['sgGroupID'])->get(); + return (new \FOG\Items\Group($row['sgGroupID']))->get(); } ]; } diff --git a/subnetgroup/src/Pages/SubnetGroupManagement.php b/subnetgroup/src/Pages/SubnetGroupManagement.php index 7c4c970..8a8df9f 100644 --- a/subnetgroup/src/Pages/SubnetGroupManagement.php +++ b/subnetgroup/src/Pages/SubnetGroupManagement.php @@ -64,7 +64,7 @@ protected function _addFields() $subnetgroup = filter_input(INPUT_POST, 'subnetgroup'); $description = filter_input(INPUT_POST, 'description'); $group = filter_input(INPUT_POST, 'group'); - $groupSelector = self::getClass('GroupManager')->buildSelectBox($group); + $groupSelector = (new \FOG\Managers\GroupManager())->buildSelectBox($group); $subnets = filter_input(INPUT_POST, 'subnets'); $labelClass = 'col-sm-3 col-form-label'; @@ -176,7 +176,7 @@ function (&$serverFault) { $subnets, $subnetsFound ); - $exists = self::getClass('SubnetGroupManager') + $exists = (new \FOG\Plugins\SubnetGroup\Managers\SubnetGroupManager()) ->exists($subnetgroup); if ($exists) { throw new \Exception( @@ -188,7 +188,7 @@ function (&$serverFault) { _('A group must be selected.') ); } - $gexists = self::getClass('SubnetGroupManager') + $gexists = (new \FOG\Plugins\SubnetGroup\Managers\SubnetGroupManager()) ->exists($group, '', 'groupID'); if ($gexists) { throw new \Exception( @@ -203,7 +203,7 @@ function (&$serverFault) { ); } $subnets = implode(', ', $subnetsFound[0]); - $SubnetGroup = self::getClass('SubnetGroup') + $SubnetGroup = (new \FOG\Plugins\SubnetGroup\Items\SubnetGroup()) ->set('name', $subnetgroup) ->set('description', $description) ->set('groupID', $group) @@ -235,7 +235,7 @@ public function subnetgroupGeneral() filter_input(INPUT_POST, 'group') ?: $this->obj->get('groupID') ); - $groupSelector = self::getClass('GroupManager')->buildSelectBox($group); + $groupSelector = (new \FOG\Managers\GroupManager())->buildSelectBox($group); $subnets = ( filter_input(INPUT_POST, 'subnets') ?: $this->obj->get('subnets') @@ -356,7 +356,7 @@ public function subnetgroupGeneralPost() . "(( )*,( )*([0-9]{1,3}\.){3}[0-9]{1,3}(\/([0-9]|[1-2][0-9]|3[0-2]))+)" . "*$/"; - $exists = self::getClass('SubnetGroupManager') + $exists = (new \FOG\Plugins\SubnetGroup\Managers\SubnetGroupManager()) ->exists($subnetgroup); if ($subnetgroup != $this->obj->get('name') && $exists @@ -370,7 +370,7 @@ public function subnetgroupGeneralPost() _('A group must be selected.') ); } - $gexists = self::getClass('SubnetGroupManager') + $gexists = (new \FOG\Plugins\SubnetGroup\Managers\SubnetGroupManager()) ->exists($group, '', 'groupID'); if ($group != $this->obj->get('groupID') && $gexists diff --git a/taskstateedit/src/Pages/TaskstateeditManagement.php b/taskstateedit/src/Pages/TaskstateeditManagement.php index 5c49e67..559873f 100644 --- a/taskstateedit/src/Pages/TaskstateeditManagement.php +++ b/taskstateedit/src/Pages/TaskstateeditManagement.php @@ -61,7 +61,7 @@ protected function _addFields() $description = filter_input(INPUT_POST, 'description'); $icon = filter_input(INPUT_POST, 'icon'); $additional = filter_input(INPUT_POST, 'additional'); - $iconSel = self::getClass('TaskType')->iconlist($icon); + $iconSel = (new \FOG\Items\TaskType())->iconlist($icon); $labelClass = 'col-sm-3 col-form-label'; @@ -163,14 +163,14 @@ function (&$serverFault) { filter_input(INPUT_POST, 'additional') ); $iconval = $icon . ' ' . $additional; - $exists = self::getClass('TaskStateManager') + $exists = (new \FOG\Managers\TaskStateManager()) ->exists($taskstate); if ($exists) { throw new \Exception( _('A task state already exists with this name!') ); } - $TaskState = self::getClass('TaskState') + $TaskState = (new \FOG\Items\TaskState()) ->set('name', $taskstate) ->set('description', $description) ->set('icon', $iconval); @@ -209,7 +209,7 @@ public function taskstateGeneral() filter_input(INPUT_POST, 'additional') ?: implode(' ', (array)$iconarr) ); - $iconSel = self::getClass('TaskType')->iconlist($icon); + $iconSel = (new \FOG\Items\TaskType())->iconlist($icon); $labelClass = 'col-sm-3 col-form-label'; @@ -323,7 +323,7 @@ public function taskstateGeneralPost() ); $iconval = $icon . ' ' . $additional; - $exists = self::getClass('TaskTypeManager') + $exists = (new \FOG\Managers\TaskTypeManager()) ->exists($taskstate); if ($taskstate != $this->obj->get('name') && $exists diff --git a/tasktypeedit/src/Pages/TasktypeeditManagement.php b/tasktypeedit/src/Pages/TasktypeeditManagement.php index 4159f88..335c744 100644 --- a/tasktypeedit/src/Pages/TasktypeeditManagement.php +++ b/tasktypeedit/src/Pages/TasktypeeditManagement.php @@ -83,7 +83,7 @@ protected function _addFields() $accessTypes, $access ); - $iconSel = self::getClass('TaskType')->iconlist($icon); + $iconSel = (new \FOG\Items\TaskType())->iconlist($icon); unset($accessTypes); $labelClass = 'col-sm-3 col-form-label'; @@ -255,14 +255,14 @@ function (&$serverFault) { filter_input(INPUT_POST, 'access') ); $advanced = isset($_POST['advanced']); - $exists = self::getClass('TaskTypeManager') + $exists = (new \FOG\Managers\TaskTypeManager()) ->exists($tasktype); if ($exists) { throw new \Exception( _('A task type already exists with this name!') ); } - $TaskType = self::getClass('TaskType') + $TaskType = (new \FOG\Items\TaskType()) ->set('name', $tasktype) ->set('description', $description) ->set('icon', $icon) @@ -338,7 +338,7 @@ public function tasktypeGeneral() $accessTypes, $access ); - $iconSel = self::getClass('TaskType')->iconlist($icon); + $iconSel = (new \FOG\Items\TaskType())->iconlist($icon); unset($accessTypes); $labelClass = 'col-sm-3 col-form-label'; @@ -460,7 +460,7 @@ public function tasktypeGeneral() [ 'fields' => &$fields, 'buttons' => &$buttons, - 'TaskType' => self::getClass('TaskType') + 'TaskType' => new \FOG\Items\TaskType() ] ); $rendered = self::formFields($fields); @@ -522,7 +522,7 @@ public function tasktypeGeneralPost() ); $advanced = isset($_POST['advanced']); - $exists = self::getClass('TaskTypeManager') + $exists = (new \FOG\Managers\TaskTypeManager()) ->exists($tasktype); if ($tasktype != $this->obj->get('name') && $exists diff --git a/tests/getclass-literals.test.php b/tests/getclass-literals.test.php new file mode 100644 index 0000000..246306f --- /dev/null +++ b/tests/getclass-literals.test.php @@ -0,0 +1,173 @@ += 0 + && is_array($tokens[$p]) + && T_WHITESPACE === $tokens[$p][0] + ) { + $p--; + } + if ($p < 0 + || !is_array($tokens[$p]) + || T_DOUBLE_COLON !== $tokens[$p][0] + ) { + continue; + } + $j = $i + 1; + while ($j < $count + && is_array($tokens[$j]) + && T_WHITESPACE === $tokens[$j][0] + ) { + $j++; + } + if (!isset($tokens[$j]) || '(' !== $tokens[$j]) { + continue; + } + $k = $j + 1; + while ($k < $count + && is_array($tokens[$k]) + && T_WHITESPACE === $tokens[$k][0] + ) { + $k++; + } + if (!isset($tokens[$k]) + || !is_array($tokens[$k]) + || T_CONSTANT_ENCAPSED_STRING !== $tokens[$k][0] + ) { + // A variable. This is what getClass() is for. + continue; + } + $name = trim($tokens[$k][1], "'\""); + if ('reflectionclass' === strtolower($name)) { + continue; + } + // Count the arguments; a third one asks for the default properties. + $depth = 0; + $argc = 1; + $third = ''; + for ($m = $j; $m < $count; $m++) { + $tok = $tokens[$m]; + if (is_string($tok) && false !== strpos('([{', $tok)) { + $depth++; + continue; + } + if (is_string($tok) && false !== strpos(')]}', $tok)) { + if (0 === --$depth) { + break; + } + continue; + } + if (1 === $depth && ',' === $tok) { + $argc++; + continue; + } + if (3 === $argc && is_array($tok) && T_WHITESPACE !== $tok[0]) { + $third .= $tok[1]; + } + } + if (3 === $argc && 'true' === strtolower(trim($third))) { + continue; + } + $banned[] = [$name, $file . ':' . $token[2]]; + } +} + +$fail = false; + +if ($scanned < MIN_FILES) { + fwrite( + STDERR, + "FAIL: only $scanned file(s) scanned, expected at least " + . MIN_FILES . ". The scan is not scanning.\n" + ); + $fail = true; +} + +if ($banned !== []) { + fwrite( + STDERR, + 'FAIL: ' . count($banned) . " literal getClass() call(s):\n" + ); + foreach ($banned as list($name, $where)) { + fwrite( + STDERR, + " $where: getClass('$name') -- write a fully qualified new\n" + ); + } + $fail = true; +} + +if ($fail) { + exit(1); +} + +echo "ok: no literal getClass() in $scanned file(s)\n"; +exit(0); diff --git a/tests/oidc-flow-safety.test.php b/tests/oidc-flow-safety.test.php index b8a5b37..e4b2b05 100644 --- a/tests/oidc-flow-safety.test.php +++ b/tests/oidc-flow-safety.test.php @@ -258,7 +258,7 @@ function methodBody($src, $method) fail('OIDCFlow::_resolveUser() is missing'); } else { $flat = preg_replace('#\s+#', '', $resolve); - if (false === strpos($flat, "getClass('User')")) { + if (false === strpos($flat, 'new\\FOG\\Items\\User(')) { fail('OIDCFlow::_resolveUser() no longer looks the account up'); } // Searched in the un-flattened body: collapsing whitespace would also @@ -344,7 +344,7 @@ function methodBody($src, $method) * account who completes a sign-in as another silently keeps the first -- * and the account they land in is not the one just vouched for. */ -if (false === strpos($flatFlow, 'self::$FOGUser=self::getClass(\'User\',0)')) { +if (false === strpos($flatFlow, 'self::$FOGUser=new\\FOG\\Items\\User(0)')) { fail( 'the flow does not clear the identity loaded at boot before' . ' establishing the new session; establishSession() would keep the' diff --git a/tests/oidc-single-logout.test.php b/tests/oidc-single-logout.test.php index d23ff1a..6645c24 100644 --- a/tests/oidc-single-logout.test.php +++ b/tests/oidc-single-logout.test.php @@ -160,7 +160,10 @@ function methodBody($s, $needle) * already run. The LDAP plugin carries repair steps for exactly this. */ $alterAt = strpos($mgr, 'ALTERTABLE`OIDCProviders`ADDCOLUMN`opSingleLogout`'); -$grantAt = strpos($mgr, "getClass('OIDCUserGrantManager')->install()"); +$grantAt = strpos( + $mgr, + '\\FOG\\Plugins\\OIDC\\Managers\\OIDCUserGrantManager())->install()' +); if (false !== $alterAt && false !== $grantAt && $alterAt > $grantAt) { ok('the step is appended after the existing ones'); } else { diff --git a/tests/stubs/fog-stubs.php b/tests/stubs/fog-stubs.php index afa1904..578431a 100644 --- a/tests/stubs/fog-stubs.php +++ b/tests/stubs/fog-stubs.php @@ -227,6 +227,104 @@ public static function checkAuthAndCSRF() { } } + /** + * A stand-in that FORWARDS to whatever Hook::$classes has registered. + * + * Hook::getClass() above answers a name from that registry, and for a + * long time that was the only way a plugin reached a collaborator -- so a + * test could write `Hook::$classes['LocationAssociationManager'] = + * $manager` and then assert on $manager->batches, because the plugin was + * handed that very object. + * + * Plugins now write `new \FOG\Plugins\Location\Managers\ + * LocationAssociationManager()` (fogproject ADR 0043), which PHP resolves + * for real and which cannot hand back somebody else's instance. So the + * autoloader at the foot of this file materialises the missing class as a + * subclass of THIS, whose every method forwards into the registered + * fixture. The registry keeps working unchanged, and so does every test + * that asserts on the object it registered. + * + * Unregistered, it is just a StubItem -- the permissive default + * getClass() had. + */ + class StubProxy extends StubItem + { + /** + * The registered fixture, or null when there is none. + * + * @var StubItem|null + */ + private $_target; + /** + * Resolves the fixture registered for this class's short name. + * + * @param mixed $id the id + */ + public function __construct($id = null) + { + parent::__construct($id); + $name = static::class; + $short = substr($name, strrpos($name, '\\') + 1); + $fixture = isset(Hook::$classes[$short]) + ? Hook::$classes[$short] + : null; + if (is_callable($fixture)) { + $fixture = $fixture($id); + } + $this->_target = $fixture instanceof StubItem ? $fixture : null; + } + /** + * Whether the record exists. + * + * @return bool + */ + public function isValid() + { + return null === $this->_target + ? parent::isValid() + : $this->_target->isValid(); + } + /** + * Read a value. + * + * @param string $key the key + * + * @return mixed + */ + public function get($key) + { + return null === $this->_target + ? parent::get($key) + : $this->_target->get($key); + } + /** + * Records the batch against the fixture, so the test can see it. + * + * @param array $fields the columns + * @param array $values the rows + * + * @return void + */ + public function insertBatch($fields, $values) + { + if (null === $this->_target) { + parent::insertBatch($fields, $values); + return; + } + $this->_target->insertBatch($fields, $values); + } + /** + * Returns a select box a form can render. + * + * @return string + */ + public function buildSelectBox(...$args) + { + return null === $this->_target + ? parent::buildSelectBox(...$args) + : $this->_target->buildSelectBox(...$args); + } + } /** * A stand-in model that exists, has a name, and records writes. */ @@ -373,3 +471,33 @@ public static function hint($info) } } } + + +namespace { + /* + * Materialise any FOG class a test did not declare itself. + * + * Scoped to the FOG\ prefix and registered last, so it can only answer a + * name nothing else could: a plugin file the test require_once'd has + * already declared its own classes and never reaches here. What reaches + * here is the collaborator that file NAMES but the test never loaded, + * which is exactly what Hook::getClass() used to cover. + * + * eval() rather than class_alias() because the proxy has to know its own + * short name to find its fixture, and an alias reports the name of the + * class it aliases, not the name it was reached by. + */ + spl_autoload_register( + function ($class) { + if (0 !== strpos($class, 'FOG\\')) { + return; + } + $cut = strrpos($class, '\\'); + eval( + 'namespace ' . substr($class, 0, $cut) . ';' + . ' class ' . substr($class, $cut + 1) + . ' extends \\FOG\\Base\\StubProxy {}' + ); + } + ); +} diff --git a/windowskey/src/Hooks/AddWindowsKeyImage.php b/windowskey/src/Hooks/AddWindowsKeyImage.php index e61b2ec..890080a 100644 --- a/windowskey/src/Hooks/AddWindowsKeyImage.php +++ b/windowskey/src/Hooks/AddWindowsKeyImage.php @@ -97,7 +97,7 @@ public function imageWindowskey($obj) { $keyID = (int)filter_input(INPUT_POST, 'windowskey'); // Image keys - $windowskeySelector = self::getClass('WindowsKeyManager') + $windowskeySelector = (new \FOG\Plugins\WindowsKey\Managers\WindowsKeyManager()) ->buildSelectBox($keyID, 'windowskey'); $fields = [ @@ -194,7 +194,7 @@ public function imageWindowskeyPost($obj) } } if (count($insert_values) > 0) { - self::getClass('WindowsKeyAssociationManager') + (new \FOG\Plugins\WindowsKey\Managers\WindowsKeyAssociationManager()) ->insertBatch( $insert_fields, $insert_values @@ -262,7 +262,7 @@ public function imageAddKeyField($arguments) return; } $keyID = (int)filter_input(INPUT_POST, 'windowskey'); - $keySelector = self::getClass('WindowsKeyManager') + $keySelector = (new \FOG\Plugins\WindowsKey\Managers\WindowsKeyManager()) ->buildSelectBox($keyID, 'windowskey'); $arguments['fields'][ diff --git a/windowskey/src/Managers/WindowsKeyManager.php b/windowskey/src/Managers/WindowsKeyManager.php index 5c7c8c1..91c26af 100644 --- a/windowskey/src/Managers/WindowsKeyManager.php +++ b/windowskey/src/Managers/WindowsKeyManager.php @@ -109,7 +109,7 @@ public function schema() // 0 $this->createSql(), // 1 - self::getClass('WindowsKeyAssociationManager')->createSql(), + (new \FOG\Plugins\WindowsKey\Managers\WindowsKeyAssociationManager())->createSql(), // 2 - retire UNIQUE (wkKey); see createSql() for why it could not // hold. It sat at position 0, hence `index0`. applyUpdates() // tolerates 1091, which is what a fresh install -- built from the @@ -179,7 +179,7 @@ public function install() */ public function uninstall() { - self::getClass('WindowsKeyAssociationManager')->uninstall(); + (new \FOG\Plugins\WindowsKey\Managers\WindowsKeyAssociationManager())->uninstall(); return parent::uninstall(); } } diff --git a/windowskey/src/Pages/WindowsKeyManagement.php b/windowskey/src/Pages/WindowsKeyManagement.php index b5f573a..b0cf101 100644 --- a/windowskey/src/Pages/WindowsKeyManagement.php +++ b/windowskey/src/Pages/WindowsKeyManagement.php @@ -154,7 +154,7 @@ function (&$serverFault) { trim(filter_input(INPUT_POST, 'key')), '' ); - $exists = self::getClass('WindowsKeyManager') + $exists = (new \FOG\Plugins\WindowsKey\Managers\WindowsKeyManager()) ->exists($windowskey); if ($exists) { throw new \Exception( @@ -168,14 +168,14 @@ function (&$serverFault) { // so a blank one should never reach here, and a blank is not a // meaningful duplicate of another blank anyway. if ($key !== '' - && self::getClass('WindowsKeyManager') + && (new \FOG\Plugins\WindowsKey\Managers\WindowsKeyManager()) ->exists($key, 0, 'key') ) { throw new \Exception( _('A Windows Key already exists with this product key!') ); } - $WindowsKey = self::getClass('WindowsKey') + $WindowsKey = (new \FOG\Plugins\WindowsKey\Items\WindowsKey()) ->set('name', $windowskey) ->set('description', $description) ->set('key', $key); @@ -330,7 +330,7 @@ public function windowsKeyGeneralPost() $this->obj->get('key') ); - $exists = self::getClass('WindowsKeyManager') + $exists = (new \FOG\Plugins\WindowsKey\Managers\WindowsKeyManager()) ->exists($windowskey); if ($windowskey != $this->obj->get('name') && $exists @@ -344,7 +344,7 @@ public function windowsKeyGeneralPost() // exists() excludes this row by id, so re-saving an unchanged key is // not mistaken for a duplicate. if ($key !== '' - && self::getClass('WindowsKeyManager') + && (new \FOG\Plugins\WindowsKey\Managers\WindowsKeyManager()) ->exists($key, $this->obj->get('id'), 'key') ) { throw new \Exception( diff --git a/wolbroadcast/src/Pages/WOLBroadcastManagement.php b/wolbroadcast/src/Pages/WOLBroadcastManagement.php index 8257b75..64c0e31 100644 --- a/wolbroadcast/src/Pages/WOLBroadcastManagement.php +++ b/wolbroadcast/src/Pages/WOLBroadcastManagement.php @@ -157,14 +157,14 @@ function (&$serverFault) { $broadcast = trim( filter_input(INPUT_POST, 'broadcast') ); - $exists = self::getClass('WOLBroadcastManager') + $exists = (new \FOG\Plugins\WOLBroadcast\Managers\WolbroadcastManager()) ->exists($wolbroadcast); if ($exists) { throw new \Exception( _('A broadcast already exists with this name!') ); } - $WOLBroadcast = self::getClass('WOLBroadcast') + $WOLBroadcast = (new \FOG\Plugins\WOLBroadcast\Items\Wolbroadcast()) ->set('name', $wolbroadcast) ->set('description', $description) ->set('broadcast', $broadcast); @@ -304,7 +304,7 @@ public function wolbroadcastGeneralPost() filter_input(INPUT_POST, 'broadcast') ); - $exists = self::getClass('WOLBroadcastManager') + $exists = (new \FOG\Plugins\WOLBroadcast\Managers\WolbroadcastManager()) ->exists($wolbroadcast); if ($wolbroadcast != $this->obj->get('name') && $exists