Create one of Monolog handlers by specifying it name or full class.

@param string $classOrName
@param mixed[] $args
@return HandlerInterface
@throws InvalidArgumentException
974244
public function createHandler($classOrName, $args = [])
    {
        $classes = [
            $classOrName,
            '\\Monolog\\Handler\\' . $classOrName
        ];

        foreach ($classes as $class)
        {
            if (class_exists($class))
            {
                $object = (new ReflectionClass($class))->newInstanceArgs($args);

                return new Handler($object);
            }
        }

        throw new InvalidArgumentException("Monolog handler [$classOrName] does not exist.");
    }
887424
public static function newProxyInstance(string $className, HandlerInterface $handler)
    {
        $reflectionClass = new \ReflectionClass($className);
        $reflectionMethods = $reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC | \ReflectionMethod::IS_PROTECTED);

        // Proxy property
        $id = \uniqid('', false);
        $proxyClassName = \basename(str_replace("\\", '/', $className));
        $proxyClassName = $proxyClassName . '_' . $id;
        $handlerPropertyName = '__handler_' . $id;

        // Base class template
        $template = "class $proxyClassName extends $className {
            private \$$handlerPropertyName;
            public function __construct(\$handler)
            {
                \$this->{$handlerPropertyName} = \$handler;
            }
        ";

        // Methods
        $template .= self::getMethodsTemplate($reflectionMethods, $handlerPropertyName);
        $template .= '}';

        eval($template);
        $newRc = new \ReflectionClass($proxyClassName);

        return $newRc->newInstance($handler);
    }
636048
public function newInstance($className, array $args = array())
    {

        // load the reflection data for the passed class name
        $reflectionClass = $this->getReflectionClass($className);

        // query whether or not the class has a constructor
        if ($reflectionClass->hasMethod($methodName = '__construct') &&
            $reflectionClass->getMethod($methodName)->getParameters() &&
            sizeof($args) > 0
        ) {
            return $reflectionClass->newInstanceArgs($args);
        }

        // return the instance without calling the constructor
        return $reflectionClass->newInstance();
    }
746918
protected function createLoggerInstance($handler, $target)
    {
        $handlerClassName = $handler . 'Handler';

        if (class_exists('\Monolog\Logger') && class_exists('\Monolog\Handler\\' . $handlerClassName)) {
            if (null !== $handlerInstance = $this->createHandlerInstance($handlerClassName, $target)) {
                $this->instance = new \Monolog\Logger('main');
                $this->instance->pushHandler($handlerInstance);
            }

            $this->handler = $handler;
            $this->target = $target;
        }
    }
165247
protected function callOnceBeforeMethodHooks($classInstance, $method, array $args = [])
    {
        $method = self::getCalledMethod($method);

        $onceBeforeMethodName = 'onceBefore'.ucfirst($method);
        if ( ! isset($this->instanceOnceCalledMethods['before'][$onceBeforeMethodName])) {
            if (isset($this->hooks[$onceBeforeMethodName])) {
                foreach ($this->hooks[$onceBeforeMethodName] as $callable) {
                    try {
                        $return = $this->callCallable($classInstance, $callable, $args, $method, false);
                    } catch (CancelPropagationException $e) {
                        break;
                    }

                    if ($return !== null) {
                        return $return;
                    }
                }

                $this->instanceOnceCalledMethods['before'][$onceBeforeMethodName] = true;
            }
        }

        $return = $this->callGlobalOnceBeforeMethodHooks($classInstance, $method, $onceBeforeMethodName);

        if ($return !== null) {
            return $return;
        }
    }
819935
public static function factory(string $className = ''): LogInterface
    {
        static::init();

        $className = '\\'.$className;
        $loggerConfig = \array_key_exists($className, static::$classConfig)
            ? static::$classConfig[$className]
            : static::$classConfig['Default'];
        $loggerClass = '\\MS\\LightFramework\\Log\\Backend\\'.\ucfirst($loggerConfig['backend']);
        $logDestination = $loggerConfig['destination'];
        $logLevel = 0;

        if ($loggerConfig['logDebug'] === true) {
            $logLevel |= static::LOG_DEBUG;
        }
        if ($loggerConfig['logInfo'] === true) {
            $logLevel |= static::LOG_INFO;
        }
        if ($loggerConfig['logWarning'] === true) {
            $logLevel |= static::LOG_WARNING;
        }
        if ($loggerConfig['logError'] === true) {
            $logLevel |= static::LOG_ERROR;
        }

        $logger = new $loggerClass($logDestination, $logLevel);

        // @codeCoverageIgnoreStart
        if (!($logger instanceof LogInterface)) {
            throw new RuntimeException('Log backend class must implement \\MS\\LightFramework\\Log\\LogInterface');
        }
        // @codeCoverageIgnoreEnd

        return $logger;
    }
458394
public function getAssetHandler($className)
    {
        if (false === array_key_exists($className, $this->instances)) {
            if (false === class_exists($className)) {
                throw ClassNotFoundException::wrongAssetHandlerClassName($className);
            }

            $instance = GeneralUtility::makeInstance($className, $this);

            if (false === $instance instanceof AbstractAssetHandler) {
                throw InvalidArgumentTypeException::wrongAssetHandlerType(get_class($instance));
            }

            $this->instances[$className] = $instance;
        }

        return $this->instances[$className];
    }
244129
protected function handleCallback($callback, array $args = [])
    {
        $response = null;

        // Check if $callback is a closure.
        if ($callback instanceof \Closure || is_array($callback)) {
            $response = call_user_func($callback, $args);
        } elseif (is_string($callback)) {
            if (false !== strpos($callback, '@') || class_exists($callback)) {
                // We use a "ClassName@method" syntax.
                // Let's get a class instance and call its method.
                $callbackArray = $this->handleClassCallback($callback);
                $response = call_user_func($callbackArray, $args);
            } else {
                // Used as a classic callback function.
                $response = call_user_func($callback, $args);
            }
        }

        return $response;
    }
909445
public function trigger($name, ...$args)
    {
        //we should deal with strings
        //then callables respectively
        //to allow overriding
        if (is_string($name)) {
            //is it a protocol?
            if (strpos($name, '://') !== false) {
                return $this->triggerProtocol($name, ...$args);
            }

            //they can call a class
            if (strpos($name, '@') !== false) {
                return $this->triggerController($name, ...$args);
            }

            //unless it's a static call
            if (strpos($name, '::') !== false && is_callable($name)) {
                call_user_func_array($name, $args);
                return $this;
            }

            return $this->triggerEvent($name, ...$args);
        }

        if (is_callable($name)) {
            if ($name instanceof Closure) {
                $name = $this->bindCallback($name);
            }

            call_user_func_array($name, $args);
        }

        //we can only deal with callable and strings
        //we don't want to throw an error
        //because it could just be a pseudo
        //placeholder
        return $this;
    }
211071
private static function createOnBlockHandler(LoggerInterface $logger): callable
    {
        return static function(int $blockInterval) use ($logger): void
        {
            $trace     = \debug_backtrace();
            $traceData = ['info' => []];

            /** skip first since it's always the current method */
            \array_shift($trace);
            /** the call_user_func call is also skipped */
            \array_shift($trace);

            $i = 0;

            while (isset($trace[$i]['class']))
            {
                /** @noinspection SlowArrayOperationsInLoopInspection */
                $traceData['info'] = \array_merge(
                    $traceData['info'],
                    [
                        'file'     => $trace[$i - 1]['file'] ?? null,
                        'line'     => $trace[$i - 1]['line'] ?? null,
                        'class'    => $trace[$i]['class'] ?? null,
                        'function' => $trace[$i]['function'] ?? null,
                    ]
                );

                $i++;
            }

            $traceData['lockTime'] = 0 !== $blockInterval ? $blockInterval / 1000 : 0;

            $logger->error('A lock event loop has been detected. Blocking time: {lockTime} seconds', $traceData);

            unset($traceData, $trace, $i);
        };
    }
115346
public static function create($classname, $args = null, $filter = null, $override = null) {
		//obtain provider list for this class
		$profile = Profiler::getClassProfile($classname);
		$providers = $profile->providers;
		
		if (empty($providers)) {
			throw new \RuntimeException("Class $classname does not have any provider associated with it");
		}

		//create new container and register all providers
		$container = new Container();
		
		foreach ($providers as $provider) {
			$providerInstance = self::getProvider($provider);
			$providerInstance->register($container);
		}

		return self::createWith($classname, $container, $args, $filter, $override);
	}
473835
public function createEvent($eventName, $class, array $args)
    {
        if ( ! is_string($eventName)) {
            $exception = array(
                'message' => '"exception_invalid_argument_provided_for_event_name',
                'parameters' => array(
                    '%className%' => get_class($this),
                ),
            );
            throw new InvalidArgumentException(json_encode($exception));
        }

        if ( ! class_exists($class)) {
            $exception = array(
                'message' => 'exception_invalid_class_name_for_createEvent',
                'parameters' => array(
                    '%argumentClass%' => get_class($this),
                    '%className%' => get_class($this),
                ),
            );
            throw new InvalidArgumentException(json_encode($exception));
        }

        // When the event already exists, it is recreated
        $event = $this->fetchEvent($eventName);
        if (null !== $event) {unset($this->events[$eventName]);}

        $event = new $class();
        if (! $event instanceof Event) {
            $exception = array(
                'message' => 'exception_invalid_class_instance_for_createEvent',
                'parameters' => array(
                    '%argumentClass%' => get_class($this),
                    '%className%' => get_class($this),
                ),
            );
            throw new InvalidArgumentTypeException(json_encode($exception));
        }

        $this->events[$eventName] = $event;

        $numberOfArgs = count($args);
        if ($numberOfArgs == 0) return $this;

        $methods = array_slice($this->methods, 0, $numberOfArgs);
        $callables = array_combine($methods, $args);

        // Valorizes the event's methods
        foreach ($callables as $method => $arg) {
            call_user_func(array($event, $method), $arg);
        }

        return $this;
    }
654544
protected function _InstantiateObject($Alias, $ClassName, $Args = NULL) {
      if(is_null($Args)) $Args = array();
      $Result = NULL;

      // Instantiate the object with the correct arguments.
      // This odd looking case statement is purely for speed optimization.
      switch(count($Args)) {
         case 0:
            $Result = new $ClassName; break;
         case 1:
            $Result = new $ClassName($Args[0]); break;
         case 2:
            $Result = new $ClassName($Args[0], $Args[1]); break;
         case 3:
            $Result = new $ClassName($Args[0], $Args[1], $Args[2]); break;
         case 4:
            $Result = new $ClassName($Args[0], $Args[1], $Args[2], $Args[3]); break;
         case 5:
            $Result = new $ClassName($Args[0], $Args[1], $Args[2], $Args[3], $Args[4]); break;
         case 6:
            $Result = new $ClassName($Args[0], $Args[1], $Args[2], $Args[3], $Args[4], $Args[5]); break;
         case 7:
            $Result = new $ClassName($Args[0], $Args[1], $Args[2], $Args[3], $Args[4], $Args[5], $Args[6]); break;
         case 8:
            $Result = new $ClassName($Args[0], $Args[1], $Args[2], $Args[3], $Args[4], $Args[5], $Args[6], $Args[7]); break;
         default:
            throw new Exception();
      }

      $this->_SetDependancies($Alias, $Result);
      return $Result;
   }
1308656
public function loadClassMetadata(LoadClassMetadataEventArgs $args) {
		/**
		 * @var \Doctrine\ORM\Mapping\ClassMetadataInfo $classMetadata
		 */
		$classMetadata = $args->getClassMetadata();
		
		// Do not re-apply the prefix in an inheritance hierarchy.
		if($classMetadata->isInheritanceTypeSingleTable() && !$classMetadata->isRootEntity()) {
			return;
		}
		
		$prefix = $classMetadata->namespace;
		if(!preg_match('/([^\\\\]+)Bundle/i', $classMetadata->namespace, $prefix)) {
			return;
		}

		$prefix = strtolower($prefix[1]) . '_';
		
		$classMetadata->setPrimaryTable(array(
			'name' => $prefix . $classMetadata->getTableName() 
		));

		if($args->getEntityManager()->getConnection()->getDatabasePlatform() instanceof SqlitePlatform && array_key_exists('indexes', $classMetadata->table)) {
			$indexes = array();
			foreach($classMetadata->table['indexes'] as $name => $params) {
				$indexes[$prefix . $classMetadata->getTableName() . '_' . $name] = $params;
			}
			$classMetadata->table['indexes'] = $indexes;
		}
		
		foreach($classMetadata->getAssociationMappings() as $fieldName => $mapping) {
			if($mapping['type'] == \Doctrine\ORM\Mapping\ClassMetadataInfo::MANY_TO_MANY && isset($classMetadata->associationMappings[$fieldName]['joinTable']['name'])) {
				if(isset($classMetadata->associationMappings[$fieldName]['joinTable']['prefixed']) && $classMetadata->associationMappings[$fieldName]['joinTable']['prefixed']) {
					continue;
				}
				
				$mappedTableName = $classMetadata->associationMappings[$fieldName]['joinTable']['name'];
				$classMetadata->associationMappings[$fieldName]['joinTable']['name'] = $prefix . $mappedTableName;
				$classMetadata->associationMappings[$fieldName]['joinTable']['prefixed'] = true;
			}
		}
	}
32377
public function loadClassMetadata(LoadClassMetadataEventArgs $args)
    {
        $classMetadata = $args->getClassMetadata();

        if (!($classMetadata instanceof \Doctrine\ORM\Mapping\ClassMetadataInfo)) {
            return;
        }

        // Do not re-apply the prefix in an inheritance hierarchy.
        if ($classMetadata->isInheritanceTypeSingleTable() && !$classMetadata->isRootEntity()) {
            return;
        }

        $prefix = $this->config->getDbPrefix();

        if (strpos($classMetadata->namespace, 'XTAIN\Bundle\JoomlaBundle') === 0) {
            $classMetadata->setPrimaryTable([
                'name' => $prefix . $classMetadata->getTableName()
            ]);

            foreach ($classMetadata->getAssociationMappings() as $fieldName => $mapping) {
                if ($mapping['type'] == \Doctrine\ORM\Mapping\ClassMetadataInfo::MANY_TO_MANY
                    && isset($classMetadata->associationMappings[$fieldName]['joinTable']['name'])) {
                    $mappedTableName = $classMetadata->associationMappings[$fieldName]['joinTable']['name'];
                    $classMetadata->associationMappings[$fieldName]['joinTable']['name'] = $prefix . $mappedTableName;
                }
            }
        }
    }
320982
public function triggerEvent($event, $args = [])
    {
        if (!is_string($event) && !$event instanceof Event) {
            throw new \InvalidArgumentException(sprintf(
                '%s::%s only allow Event object or string.',
                get_called_class(),
                __FUNCTION__
            ));
        }

        if (!($event instanceof Event)) {
            if (isset($this->events[$event])) {
                $event = $this->events[$event];
            } else {
                $event = new Event($event);
            }
        }

        $event->mergeArguments($args);

        $listeners = [];

        if (isset($this->listeners[$event->getName()])) {
            foreach ($this->listeners[$event->getName()] as $listener) {
                if ($event->isStopped()) {
                    return $event;
                }

                if (!is_callable($listener)) {
                    $listener = [$listener, $event->getName()];
                }

                if (!is_callable($listener)) {
                    continue;
                }

                $listener($event);

                if ($this->debug) {
                    $listeners[] = $listener;
                }
            }
        }

        if ($this->debug) {
            $executedListeners = [];

            foreach ($listeners as $listener) {
                if ($listener instanceof \Closure) {
                    $ref = new \ReflectionFunction($listener);

                    $listener = ['{Closure}: ' . $ref->getFileName() . ' - Line: ' . $ref->getStartLine()];
                }

                if (is_object($listener[0])) {
                    $listener[0] = get_class($listener[0]);
                }

                $executedListeners[] = $listener;
            }

            $this->collector[] = [
                'event' => $event->getName(),
                'listeners' => $executedListeners,
            ];
        }

        return $event;
    }
28377
private void handleArgLogger(final Deque<String> args) {
        if (loggerClassname != null) {
            throw new BuildException("Only one logger class may be specified.");
        }
        loggerClassname = args.pop();
        if (loggerClassname == null) {
            throw new BuildException("You must specify a classname when using the -logger argument");
        }
    }