<commit_before><?php
/**
 * Webiny Framework (http://www.webiny.com/framework)
 *
 * @copyright Copyright Webiny LTD
 */
namespace Webiny\Component\ServiceManager;

use Webiny\Component\Config\ConfigObject;
use Webiny\Component\StdLib\SingletonTrait;
use Webiny\Component\StdLib\StdLibTrait;
use Webiny\Component\StdLib\StdObject\ArrayObject\ArrayObject;

/**
 * ServiceManager is the main class for working with services.
 * @package         Webiny\Component\ServiceManager
 */
class ServiceManager
{
    use StdLibTrait, SingletonTrait;

    private $compiledConfig;

    /**
     * @var ArrayObject
     */
    private $instantiatedServices;

    /**
     * @var ArrayObject
     */
    private $registeredServices;
    private $parameters;
    private $taggedServices;
    private $references;

    /**
     * Get service instance by given name nad optional arguments
     *
     * @param string $serviceName Requested service name
     *
     * @throws ServiceManagerException
     * @return object
     */
    public function getService($serviceName)
    {
        $serviceName = $this->str($serviceName)->trimLeft("@")->val();
        if (!$this->registeredServices->keyExists($serviceName)) {
            throw new ServiceManagerException(ServiceManagerException::SERVICE_DEFINITION_NOT_FOUND, [$serviceName]);
        }
        if (!$this->instantiatedServices->keyExists($serviceName)) {
            $this->instantiateService($serviceName);
        }

        return $this->instantiatedServices->key($serviceName);
    }

    /**
     * Get multiple services by tag
     *
     * @param string      $tag Tag to use for services filter
     * @param null|string $forceType (Optional) Return only services which are instances of $forceType
     *
     * @return array
     */
    public function getServicesByTag($tag, $forceType = null)
    {
        $services = [];
        foreach ($this->taggedServices->key($tag, [], true) as $serviceName) {
            $service = $this->getService($serviceName);<commit_msg>Fixed bug with service instantiation of `Scope: prototype` services.<commit_after><?php
/**
 * Webiny Framework (http://www.webiny.com/framework)
 *
 * @copyright Copyright Webiny LTD
 */

namespace Webiny\Component\ServiceManager;

use Webiny\Component\Config\ConfigObject;
use Webiny\Component\StdLib\SingletonTrait;
use Webiny\Component\StdLib\StdLibTrait;
use Webiny\Component\StdLib\StdObject\ArrayObject\ArrayObject;

/**
 * ServiceManager is the main class for working with services.
 * @package         Webiny\Component\ServiceManager
 */
class ServiceManager
{
    use StdLibTrait, SingletonTrait;

    private $compiledConfig;

    /**
     * @var ArrayObject
     */
    private $instantiatedServices;

    /**
     * @var ArrayObject
     */
    private $registeredServices;
    private $parameters;
    private $taggedServices;
    private $references;

    /**
     * Get service instance by given name nad optional arguments
     *
     * @param string $serviceName Requested service name
     *
     * @throws ServiceManagerException
     * @return object
     */
    public function getService($serviceName)
    {
        $serviceName = $this->str($serviceName)->trimLeft("@")->val();
        if (!$this->registeredServices->keyExists($serviceName)) {
            throw new ServiceManagerException(ServiceManagerException::SERVICE_DEFINITION_NOT_FOUND, [$serviceName]);
        }

        // Instantiate new service or get existing service instance
        if (!$this->instantiatedServices->keyExists($serviceName)) {
            $service = $this->instantiateService($serviceName);
        } else {
            $service = $this->instantiatedServices->key($serviceName);
        }

        return $service;
    }

    /**
     * Get multiple services by tag
     *
     * @param string      $tag Tag to use for services filter
     * @param null|string $forceType (Optional) Return only services which are instances of $forceType
     *
     * @return array
     */
    public function getServicesByTag($tag, $forceType = null)
    {
        $services = [];
        foreach ($this->taggedServices->key($tag, [], true) as $serviceName) {
            $service = $this->getService($serviceName);
{'fraction_non_alphanumeric': 0.11252955082742316, 'fraction_numerical': 0.0, 'mean_word_length': 2.980244590780809, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1082848', 'n_tokens_mistral': 1158, 'n_tokens_neox': 1145, 'n_words': 271}