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

chore: silence an error and log it #1131

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 24 additions & 1 deletion common/oatbox/event/EventManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@

namespace oat\oatbox\event;

use common_Logger;
use oat\oatbox\service\ConfigurableService;
use oat\oatbox\service\ServiceNotFoundException;
use Throwable;

/**
* The simple placeholder ServiceManager
Expand Down Expand Up @@ -52,9 +54,18 @@ public function trigger($event, $params = [])
$event = is_object($event) ? $event : new GenericEvent($event, $params);

foreach ($this->getListeners($event) as $callback) {
$callbackName = $callback;

if (is_array($callback) && count($callback) == 2) {
list($key, $function) = $callback;
[$key, $function] = $callback;

if (is_object($key)) {
$callbackName = sprintf('%s::%s', get_class($key), $function);
}

if (is_string($key)) {
$callbackName = sprintf('%s::%s', $key, $function);

try {
$service = $container->get($key);
$callback = [$service, $function];
Expand All @@ -64,6 +75,18 @@ public function trigger($event, $params = [])
}
}

if (!is_callable($callback)) {
common_Logger::w(
sprintf(
'Event manager cannot call %s because it is not a callable. '
. 'Notice, that classes registered in DI container cannot be executed during the installation',
$callbackName
)
);

continue;
}

call_user_func($callback, $event);
}
}
Expand Down
30 changes: 17 additions & 13 deletions core/kernel/classes/class.Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -757,24 +757,28 @@ public function equals(core_kernel_classes_Resource $resource): bool
}

/**
* Whenever or not the current resource is
* an instance of the specified class
* Whenever or not the current resource is an instance of the specified class
*
* @access public
* @author Joel Bout, <[email protected]>
* @param Class class
* @return boolean
*/
public function isInstanceOf(core_kernel_classes_Class $class): bool
{
$returnValue = (bool) false;
foreach ($this->getTypes() as $type) {
if ($class->equals($type) || $type->isSubClassOf($class)) {
$returnValue = true;
break;
}
}
return (bool) $returnValue;
return in_array($class->getUri(), $this->getParentClassesIds(), true);
}

public function getRootId(): string
{
$parentClassesIds = $this->getParentClassesIds();

return array_pop($parentClassesIds);
}

/**
* Return the parent class URI of a resource
*/
public function getParentClassId(): ?string
{
return current($this->getParentClassesIds()) ?: null;
}

public function getParentClassesIds(): array
Expand Down
Loading