Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Caching Loader Test #3970

Open
wants to merge 32 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
181ac72
use reset registry
tn3rb Jul 22, 2022
7392e01
add InterminableInterface
tn3rb Jul 21, 2022
aab2e31
add InterminableInterface + typing + formatting
tn3rb Jul 21, 2022
8bdfd2f
fix method calls
tn3rb Jul 21, 2022
279213d
set default value
tn3rb Jul 28, 2022
9a83816
sort and de-dupe FQCN arrays
tn3rb Jul 21, 2022
aded9bb
improve add() and typings
tn3rb Jul 21, 2022
f1fc874
don't reset Interminable. improve reset()
tn3rb Jul 28, 2022
c91b110
add/improve typings
tn3rb Jul 21, 2022
28654c2
add import
tn3rb Jul 28, 2022
923db7b
clear stack b4 adding more
tn3rb Jul 21, 2022
badeef8
fix typings
tn3rb Jul 28, 2022
aa36849
fix return type
tn3rb Jul 28, 2022
cee0a09
fix duplicate asset handles
tn3rb Jul 21, 2022
b692edf
fix another duplicate handle
tn3rb Jul 28, 2022
5e0dae2
improved reset & addon caching
tn3rb Jul 28, 2022
099cb4b
set DRS from config
tn3rb Jul 28, 2022
cd3ea8b
fix & format tests
tn3rb Jul 28, 2022
c11ef3a
refactor/extract validator logic
tn3rb Jul 14, 2022
db62bff
extend LoaderFactory
tn3rb Jul 14, 2022
dc5501d
another whoops! fix types
tn3rb Jul 14, 2022
5328275
get EmailValidationService manually
tn3rb Jul 18, 2022
8c58b66
don't need < 5.6 helper
tn3rb Jul 18, 2022
24e8476
use constant + formatting
tn3rb Jul 20, 2022
2f17663
use constant (and correct data type)
tn3rb Jul 20, 2022
1fe817d
use constants
tn3rb Jul 20, 2022
804b047
add prop, get, & set for EmailValidationService
tn3rb Jul 20, 2022
925c8b7
fix typings & format
tn3rb Jul 28, 2022
f15609e
reset activation for test
tn3rb Jul 28, 2022
239f58f
fix test, use new session
tn3rb Jul 28, 2022
4556b6b
reset PMM
tn3rb Jul 28, 2022
60c3edb
fix linting
tn3rb Jul 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion admin_pages/messages/Messages_Admin_Page.core.php
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ public function load_scripts_styles_settings()
[],
EVENT_ESPRESSO_VERSION
);
wp_enqueue_style('ee-text-links');
wp_enqueue_style('ee-text-links-css');
wp_enqueue_style('ee-message-settings');
wp_enqueue_script('ee-messages-settings');
}
Expand Down
5 changes: 3 additions & 2 deletions admin_pages/payments/Payments_Admin_Page.core.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ public function load_scripts_styles()
{
// styles
wp_enqueue_style('espresso-ui-theme');
wp_enqueue_style('ee-text-links-css');
wp_register_style(
'espresso_payments',
EE_PAYMENTS_ASSETS_URL . 'ee-payments.css',
Expand All @@ -250,7 +251,7 @@ public function load_scripts_styles()
);
// scripts
wp_enqueue_script('ee_admin_js');
wp_enqueue_script('ee-text-links');
wp_enqueue_script('ee-text-links-js');
wp_enqueue_script(
'espresso_payments',
EE_PAYMENTS_ASSETS_URL . 'espresso_payments_admin.js',
Expand All @@ -264,7 +265,7 @@ public function load_scripts_styles()
public function load_scripts_styles_default()
{
wp_enqueue_style('espresso_payments');
wp_enqueue_style('ee-text-links');
wp_enqueue_style('ee-text-links-css');
}


Expand Down
3 changes: 3 additions & 0 deletions core/EE_Dependency_Map.core.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,9 @@ protected function _register_core_dependencies()
'EventEspresso\core\services\session\SessionStartHandler' => EE_Dependency_Map::load_from_cache,
'EE_Encryption' => EE_Dependency_Map::load_from_cache,
],
'EventEspresso\core\services\session\SessionStartHandler' => [
'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
],
'EE_Cart' => [
'EE_Session' => EE_Dependency_Map::load_from_cache,
],
Expand Down
153 changes: 117 additions & 36 deletions core/EE_Registry.core.php
Original file line number Diff line number Diff line change
Expand Up @@ -1020,22 +1020,25 @@ public function clear_cached_class(
): bool {
$class_abbreviation = $this->get_class_abbreviation($class_name);
// check if class has already been loaded, and return it if it has been
if (isset($this->{$class_abbreviation})) {
if (isset($this->{$class_abbreviation}) && ! $this->{$class_abbreviation} instanceof InterminableInterface) {
$this->{$class_abbreviation} = null;
return true;
}
$class_name = str_replace('\\', '_', $class_name);
if (isset($this->{$class_name})) {
if (isset($this->{$class_name}) && ! $this->{$class_name} instanceof InterminableInterface) {
$this->{$class_name} = null;
return true;
}
if ($addon && $this->addons->has($class_name)) {
$this->addons->remove($class_name);
return true;
}
$class_name = $this->object_identifier->getIdentifier($class_name, $arguments);
if ($this->LIB->has($class_name)) {
$this->LIB->remove($class_name);
$object_identifier = $this->object_identifier->getIdentifier($class_name, $arguments);
if (
$this->LIB->has($object_identifier)
&& ! $this->LIB->get($object_identifier) instanceof InterminableInterface
) {
$this->LIB->remove($object_identifier);
return true;
}
return false;
Expand Down Expand Up @@ -1382,9 +1385,7 @@ protected function _resolve_dependencies(
$param_class = str_replace(' ', '_', $param_class);
}
// BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime)
$param_class = $this->class_cache->isAlias($param_class, $class_name)
? $this->class_cache->getFqnForAlias($param_class, $class_name)
: $param_class;
$param_class = $this->class_cache->getFqnForAlias($param_class, $class_name);
if (
// param is not even a class
($param_class === null || $this->parameterIsPrimitive($param_class))
Expand Down Expand Up @@ -1498,7 +1499,7 @@ protected function _resolve_dependency(string $class_name, string $param_class,
* in the EE_Dependency_Map::$_class_loaders array,
* including the class prefix, ie: "EE_", "EEM_", "EEH_", etc
* @param array $arguments
* @return object
* @return mixed
*/
public static function factory(string $classname, array $arguments = [])
{
Expand All @@ -1522,6 +1523,10 @@ public static function factory(string $classname, array $arguments = [])
public function getAddon(string $class_name): ?EE_Addon
{
$class_name = str_replace('\\', '_', $class_name);
$addon = $this->_get_cached_class($class_name);
if ($addon) {
return $addon;
}
return $this->addons->{$class_name} ?? null;
}

Expand Down Expand Up @@ -1648,28 +1653,59 @@ public function reset_model(string $model_name): ?EEM_Base
* @return EE_Registry
* @throws EE_Error
* @throws ReflectionException
* @throws InvalidArgumentException
*/
public static function reset(bool $hard = false, bool $reinstantiate = true, bool $reset_models = true): EE_Registry
{
$instance = self::instance();
$instance->_cache_on = true;
// reset some "special" classes
EEH_Activation::reset();
$hard = apply_filters('FHEE__EE_Registry__reset__hard', $hard);
$instance->CFG = EE_Config::reset($hard, $reinstantiate);
$instance->CART = null;
$instance->MRM = null;
// messages reset
EED_Messages::reset();
// handle of objects cached on LIB
foreach (['LIB', 'modules'] as $cache) {
foreach ($instance->{$cache} as $class_name => $class) {
if (self::_reset_and_unset_object($class, $reset_models)) {
unset($instance->{$cache}->{$class_name});
$hard = apply_filters('FHEE__EE_Registry__reset__hard', $hard);
$cached_properties = [
'BUS',
'CART',
'CFG',
'LIB',
'MRM',
'REQ',
'SSN',
'AssetsRegistry',
// 'addons',
// 'models',
'modules',
'shortcodes',
'widgets',
];
foreach ($cached_properties as $cached_property) {
// if (EE_UnitTestCase::$debug) {
// echo "\n\n" . __LINE__ . ') ' . strtoupper($cached_property);
// }
if (
! property_exists(self::$_instance, $cached_property)
|| ! isset(self::$_instance->{$cached_property})
) {
continue;
}
$cached = self::$_instance->{$cached_property};
if (is_array($cached) || $cached instanceof RegistryContainer) {
foreach ($cached as $class_name => $class) {
if (self::_reset_object($class_name, $class, $reset_models, $hard, $reinstantiate)) {
// because unset() doesn't guarantee object destruction
self::$_instance->{$cached_property}->{$class_name} = null;
unset(self::$_instance->{$cached_property}->{$class_name});
}
}
continue;
}
if (is_object($cached)) {
if (self::_reset_object(get_class($cached), $cached, $reset_models, $hard, $reinstantiate)) {
// because unset() doesn't guarantee object destruction
self::$_instance->{$cached_property} = null;
unset(self::$_instance->{$cached_property});
}
}
}
return $instance;
// if (EE_UnitTestCase::$debug) {
// echo "\n\n";
// }
return self::$_instance;
}


Expand All @@ -1678,37 +1714,82 @@ public static function reset(bool $hard = false, bool $reinstantiate = true, boo
* if passed object implements InterminableInterface, then return false,
* to indicate that it should NOT be cleared from the Registry cache
*
* @param $object
* @param bool $reset_models
* @param string $class_name
* @param $object
* @param bool $reset_models
* @param bool $hard
* @param bool $reinstantiate
* @return bool returns true if cached object should be unset
* @throws EE_Error
* @throws ReflectionException
*/
private static function _reset_and_unset_object($object, bool $reset_models): bool
{
private static function _reset_object(
string $class_name,
$object,
bool $reset_models,
bool $hard,
bool $reinstantiate
): bool {
// if (EE_UnitTestCase::$debug) {
// echo "\n\n - reset $class_name";
// }
if (! is_object($object)) {
// if (EE_UnitTestCase::$debug) {
// echo "\n --> not an object";
// }
// don't unset anything that's not an object
return false;
}
if ($object instanceof InterminableInterface) {
// if (EE_UnitTestCase::$debug) {
// echo "\n --> NO (interminable)";
// }
// don't unset anything that's not terminable
return false;
}
if ($object instanceof EED_Module) {
$object::reset();
// if (EE_UnitTestCase::$debug) {
// echo "\n --> NO (module)";
// }
// don't unset modules
return false;
}
if ($object instanceof ResettableInterface) {
// reset some "special" classes
if ($object instanceof EE_Config) {
EE_Config::reset($hard, $reinstantiate);
// if (EE_UnitTestCase::$debug) {
// echo "\n --> NO (config)";
// }
return false;
}
if ($object instanceof EEH_Activation) {
EEH_Activation::reset();
// if (EE_UnitTestCase::$debug) {
// echo "\n --> NO (activation)";
// }
return false;
}
if ($object instanceof EEM_Base) {
if ($reset_models) {
$object->reset();
return true;
self::$_instance->reset_model($class_name);
}
return false;
}
$object->reset();
return true;
}
if (! $object instanceof InterminableInterface) {
return true;
if (method_exists($object, 'reset') && is_callable([$object, 'reset'])) {
// if (EE_UnitTestCase::$debug) {
// echo "\n --> NO (has reset)";
// }
$object->reset();
return false;
}
}
// if (EE_UnitTestCase::$debug) {
// echo "\n --> YES ??? " . get_class($object);
// }
// at least clear object from cache
self::$_instance->clear_cached_class(get_class($object));
return false;
}

Expand Down
Loading