<commit_before><?php
/******************************************************************************
 * php-src - A library that handles creation of objects and management of 
 * global services to help you refactor your legacy code base.
 *
 * Copyright (c) 2014 <NAME> <<EMAIL>>
 *
 * This software is licensed under The MIT License. You should have received 
 * a copy of the along with the code.
 */

namespace Lechimp\Src;

use Closure;
use InvalidArgumentException;

/**
 * Source for services and new objects.
 *
 * Never keep a reference to a Src-object that was not requested
 * from the source object via $src->service("Src").
 *
 */
class Src {
    /**
     * Request or register a constructor for a service.
     *
     * A service is an object that only exists once in the process. It is
     * initialized on the first request for the service and is only initialized
     * once. 
     *
     * If second argument is omitted, requests a service. If second argument is
     * set, expects a closure that takes the source itself as the first argument.
     *
     * Returns the service if second argument is omitted. Returns an updated
     * version of itself is second argument is used, where the update is non
     * destructive to the previous version of the source. This makes it possible
     * to give the source to someone else without worrying that he modifies it
     * in an odd way.
     *
     * @param   string          $name
     * @param   Closure|null    $construct 
     * @throws  Exceptions/UnknownService
     * @throws  Exceptions/UnresolvableDependency
     * @throws  InvalidArgumentException    When $name == "Src"
     * @return  mixed
     */
    public function service($name, Closure $construct = null) {
        assert(is_string($name));

        if ($name == "Src") {
            throw new InvalidArgumentException("The name 'Src' is reserved.");
        }

        if ($construct) {
            return $this->registerService($name, $construct);
        }
        else {
            return $this->requestService($name);
        }
    }

    /**
     * Register a constructor for a class.
     *
     * On construction with build , gives src and parameters to 
     * 
     * @param   string          $name
     * @param   Closure         $construct
     * @return  Src<commit_msg>only throw error on registration of constructor for 'Src', not on request as well<commit_after><?php
/******************************************************************************
 * php-src - A library that handles creation of objects and management of 
 * global services to help you refactor your legacy code base.
 *
 * Copyright (c) 2014 <NAME> <<EMAIL>>
 *
 * This software is licensed under The MIT License. You should have received 
 * a copy of the along with the code.
 */

namespace Lechimp\Src;

use Closure;
use InvalidArgumentException;

/**
 * Source for services and new objects.
 *
 * Never keep a reference to a Src-object that was not requested
 * from the source object via $src->service("Src").
 *
 */
class Src {
    /**
     * Request or register a constructor for a service.
     *
     * A service is an object that only exists once in the process. It is
     * initialized on the first request for the service and is only initialized
     * once. 
     *
     * If second argument is omitted, requests a service. If second argument is
     * set, expects a closure that takes the source itself as the first argument.
     *
     * Returns the service if second argument is omitted. Returns an updated
     * version of itself is second argument is used, where the update is non
     * destructive to the previous version of the source. This makes it possible
     * to give the source to someone else without worrying that he modifies it
     * in an odd way.
     *
     * @param   string          $name
     * @param   Closure|null    $construct 
     * @throws  Exceptions/UnknownService
     * @throws  Exceptions/UnresolvableDependency
     * @throws  InvalidArgumentException    When $name == "Src"
     * @return  mixed
     */
    public function service($name, Closure $construct = null) {
        assert(is_string($name));

        if ($construct && $name == "Src") {
            throw new InvalidArgumentException("The name 'Src' is reserved.");
        }

        if ($construct) {
            return $this->registerService($name, $construct);
        }
        else {
            return $this->requestService($name);
        }
    }

    /**
     * Register a constructor for a class.
     *
     * On construction with build , gives src and parameters to 
     * 
     * @param   string          $name
     * @param   Closure         $construct
     * @return  Src
{'fraction_non_alphanumeric': 0.10913705583756345, 'fraction_numerical': 0.001692047377326565, 'mean_word_length': 2.4823269513991164, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, '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': '559110', 'n_tokens_mistral': 1211, 'n_tokens_neox': 1156, 'n_words': 525}