HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/vhost/disk-apps/magento.bikenow.co/vendor/laminas/laminas-di/src/ServiceLocator.php
<?php

/**
 * @see       https://github.com/laminas/laminas-di for the canonical source repository
 * @copyright https://github.com/laminas/laminas-di/blob/master/COPYRIGHT.md
 * @license   https://github.com/laminas/laminas-di/blob/master/LICENSE.md New BSD License
 */

namespace Laminas\Di;

use Closure;

/**
 * Simple service locator implementation capable of using closures to generate instances
 */
class ServiceLocator implements ServiceLocatorInterface
{
    /**
     * Map of service names to methods
     *
     * As an example, you might define a getter method "getFoo", and map it to
     * the service name "foo":
     *
     * <code>
     * protected $map = array('foo' => 'getFoo');
     * </code>
     *
     * When encountered, the return value of that method will be used.
     *
     * Methods mapped in this way may expect a single, array argument, the
     * $params passed to {@link get()}, if any.
     *
     * @var array
     */
    protected $map = [];

    /**
     * Registered services and cached values
     *
     * @var array
     */
    protected $services = [];

    /**
     * {@inheritDoc}
     */
    public function set($name, $service)
    {
        $this->services[$name] = $service;

        return $this;
    }

    /**
     * Can the locator return the named instance?
     *
     * @param string $name
     * @return bool
     */
    public function has($name)
    {
        if (! isset($this->services[$name])
            && ! isset($this->map[$name])
        ) {
            return false;
        }

        return true;
    }

    /**
     * Retrieve a registered service
     *
     * Tests first if a value is registered for the service, and, if so,
     * returns it.
     *
     * If the value returned is a non-object callback or closure, the return
     * value is retrieved, stored, and returned. Parameters passed to the method
     * are passed to the callback, but only on the first retrieval.
     *
     * If the service requested matches a method in the method map, the return
     * value of that method is returned. Parameters are passed to the matching
     * method.
     *
     * @param  string $name
     * @param  array  $params
     * @return mixed
     */
    public function get($name, array $params = [])
    {
        if (!isset($this->services[$name])) {
            if (!isset($this->map[$name])) {
                return;
            }
            $method = $this->map[$name];

            return $this->$method($params);
        }

        $service = $this->services[$name];
        if ($service instanceof Closure
            || (!is_object($service) && is_callable($service))
        ) {
            $this->services[$name] = $service = call_user_func_array($service, $params);
        }

        return $service;
    }
}