<commit_before><?php

namespace Perfumer\Component\Container;

use Interop\Container\ContainerInterface;
use Perfumer\Component\Container\Exception\BundleException;
use Perfumer\Component\Container\Exception\ContainerException;
use Perfumer\Component\Container\Storage\ArrayStorage;
use Perfumer\Component\Container\Storage\AbstractStorage;
use Perfumer\Helper\Arr;

class Container implements ContainerInterface
{
    /**
     * @var array
     */
    protected $configurators = [];

    /**
     * @var array
     */
    protected $definitions = [];

    /**
     * @var array
     */
    protected $bundles = [];

    /**
     * @var array
     */
    protected $resources = [];

    /**
     * @var array
     */
    protected $shared = [];

    /**
     * @var array
     */
    protected $storages = [];

    /**
     * Container constructor.
     */
    public function __construct()
    {
        $this->registerStorage('array', new ArrayStorage());
    }

    /**
     * get
     * Get service instance.
     *
     * @param string $name
     * @param array $parameters
     * @return mixed
     * @access public
     * @uses \ReflectionClass
     * @throws ContainerException
     */
    public function get($name, array $parameters = [])
    {
        // Shared services are preserved through whole request
        if (isset($this->shared[$name])) {
            return $this->shared[$name];
        }

        if (!$this->has($name)) {
            throw new ContainerException('No definition found for service "' . $name . '".');
        }

        $definition = $this->definitions[$name];

        // Alias is a link to another definition
        if (isset($definition['alias'])) {
            return $this->get($definition['alias']);
        }

        // "Init" directive is a callable that returns instance of service
        if (isset($definition['init']) && is_callable($definition['init'])) {
            $service_class = $definition['init']($this, $parameters);
        } else {
            $arguments = [];

            // Array of arguments which are given to constructor method
            if (isset($definition['arguments'])) {
                $arguments = $this->resolveArrayOfArguments($definition['arguments'], $parameters);
            }

            // Service is made by static method
            if (isset($definition['static'])) {
                $service_class = call_user_func_array([$definition['class'], $definition['static']], $arguments);

                if ($service_class === false) {
                    throw new ContainerException('Class "' . $definition['class'] . '" for service "' . $name . '" was not found.');
                }
            } else {
                // Service is made by normal constructor
                try {
                    $reflection_class = new \ReflectionClass($definition['class']);
                } catch (\ReflectionException $e) {
                    throw new ContainerException('Class "' . $definition['class'] . '" for service "' . $name . '" was not found.');
                }

                $service_class = $reflection_class->newInstanceArgs($arguments);
            }
        }

        // "After" directive is a callable that is called after instantiation of service object
        if (isset($definition['after']) && is_callable($definition['after'])) {
            $definition['after']($this, $service_class, $parameters);
        }

        // Preserve shared service
        if (isset($definition['shared']) && $definition['shared'] === true) {
            $this->shared[$name] = $service_class;
        }

        return $service_class;
    }

    /**
     * @param string $id
     * @return bool
     */
    public function has($id)
    {
        return isset($this->definitions[$id]);
    }
<commit_msg>Init and after directives are any valid call_user_func arguments<commit_after><?php

namespace Perfumer\Component\Container;

use Interop\Container\ContainerInterface;
use Perfumer\Component\Container\Exception\BundleException;
use Perfumer\Component\Container\Exception\ContainerException;
use Perfumer\Component\Container\Storage\ArrayStorage;
use Perfumer\Component\Container\Storage\AbstractStorage;
use Perfumer\Helper\Arr;

class Container implements ContainerInterface
{
    /**
     * @var array
     */
    protected $configurators = [];

    /**
     * @var array
     */
    protected $definitions = [];

    /**
     * @var array
     */
    protected $bundles = [];

    /**
     * @var array
     */
    protected $resources = [];

    /**
     * @var array
     */
    protected $shared = [];

    /**
     * @var array
     */
    protected $storages = [];

    /**
     * Container constructor.
     */
    public function __construct()
    {
        $this->registerStorage('array', new ArrayStorage());
    }

    /**
     * get
     * Get service instance.
     *
     * @param string $name
     * @param array $parameters
     * @return mixed
     * @access public
     * @uses \ReflectionClass
     * @throws ContainerException
     */
    public function get($name, array $parameters = [])
    {
        // Shared services are preserved through whole request
        if (isset($this->shared[$name])) {
            return $this->shared[$name];
        }

        if (!$this->has($name)) {
            throw new ContainerException('No definition found for service "' . $name . '".');
        }

        $definition = $this->definitions[$name];

        // Alias is a link to another definition
        if (isset($definition['alias'])) {
            return $this->get($definition['alias']);
        }

        // "Init" directive is a function that returns instance of service
        if (isset($definition['init'])) {
            $service_class = call_user_func($definition['init'], $this, $parameters);

            if ($service_class === false) {
                throw new ContainerException('"Init" directive for service "' . $name . '" did not produced any object.');
            }
        } else {
            $arguments = [];

            // Array of arguments which are given to constructor method
            if (isset($definition['arguments'])) {
                $arguments = $this->resolveArrayOfArguments($definition['arguments'], $parameters);
            }

            // Service is made by static method
            if (isset($definition['static'])) {
                $service_class = call_user_func_array([$definition['class'], $definition['static']], $arguments);

                if ($service_class === false) {
                    throw new ContainerException('Class "' . $definition['class'] . '" for service "' . $name . '" was not found.');
                }
            } else {
                // Service is made by normal constructor
                try {
                    $reflection_class = new \ReflectionClass($definition['class']);
                } catch (\ReflectionException $e) {
                    throw new ContainerException('Class "' . $definition['class'] . '" for service "' . $name . '" was not found.');
                }

                $service_class = $reflection_class->newInstanceArgs($arguments);
            }
        }

        // "After" directive is a function that is called after instantiation of service object
        if (isset($definition['after'])) {
            call_user_func($definition['after'], $this, $service_class, $parameters);
        }

        // Preserve shared service
        if (isset($definition['shared']) && $definition['shared'] === true) {
            $this->shared[$name] = $service_class;
        }

        return $service_class;
    }

    /**
     * @param string $id
     * @return bool
     */
    public function has($id)
    {
        return isset($this->definitions[$id]);
    }

{'fraction_non_alphanumeric': 0.13664357197844496, 'fraction_numerical': 0.0, 'mean_word_length': 2.050880626223092, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4491630', 'n_tokens_mistral': 1992, 'n_tokens_neox': 1934, 'n_words': 485}