<commit_before><?php namespace Aedart\Scaffold\Resolvers;

use Aedart\Scaffold\Exceptions\ForbiddenException;
use Aedart\Scaffold\Providers\ScaffoldServiceProvider;
use Illuminate\Container\Container;
use Illuminate\Contracts\Config\Repository;
use Illuminate\Support\Facades\App;

/**
 * IoC Service Container (Wrapper)
 *
 * This class acts first and foremost as a wrapper for Laravel's
 * service container. Secondly, additional application logic has
 * been added, in regards to resolving instances from specifiable
 * configuration repositories.
 *
 * @see \Illuminate\Contracts\Container\Container
 *
 * @author <NAME> <<EMAIL>>
 * @package Aedart\Scaffold\Resolvers
 */
class IoC
{
    /**
     * Instance of this resolver
     *
     * @var self
     */
    private static $instance;

    /**
     * IoC Service Container instance
     *
     * @var \Illuminate\Contracts\Container\Container
     */
    protected $container;

    /**
     * Get the resolver instance
     *
     * @return self
     */
    static public function getInstance()
    {
        if(null === static::$instance){
            static::$instance = new static();
        }

        return static::$instance;
    }

    /**
     * Boot the IoC (Alias for the getInstance method)
     *
     * @see getInstance()
     *
     * @return IoC
     */
    static public function boot()
    {
        return self::getInstance();
    }

    /**
     * IoC constructor.
     */
    private function __construct()
    {
        $this->setupContainer();
        $this->registerServiceProviders();
    }

    /**
     * Force destroy the container
     *
     * WARNING: Avoid using this, unless you really need to
     * destroy the IoC!
     */
    public function destroy()
    {
        $this->container = null;

        App::setFacadeApplication(null);

        self::$instance = null;
    }

    /**
     * Initialise the IoC Service Container
     */
    protected function setupContainer(){
        // Only set the application on the Facade
        // if there is none yet set
        if(is_null(App::getFacadeApplication())){
            App::setFacadeApplication(new Container());
        }

        $this->container = App::getFacadeApplication();

        $this->container->singleton('app', $this->container);
    }

    /**
     * Register this application's service providers
     */
    public function registerServiceProviders()
    {
        $defaultServiceProvider = new ScaffoldServiceProvider($this->container());
        $defaultServiceProvider->register();
    }

    /**
     * Resolve a given instance based on the concrete instance
     * that is found in the configuration. If there is no
     * instance that can be resolved from the config, then a
     * default instance is attempted to be resolved
     *
     * @param string $entry Configuration or instance identifier
     * @param Repository $config
     *
     * @return mixed
     */
    public function resolveFromConfig($entry, Repository $config)
    {
        if($config->has($entry)){
            $instance = $config->get($entry);
            return new $instance;
        }

        return $this->container()->make($entry);
    }

    /**
     * Get the IoC Service Container instance
     *
     * @return \Illuminate\Contracts\Container\Container
     */
    public function container()<commit_msg>Add make method<commit_after><?php namespace Aedart\Scaffold\Resolvers;

use Aedart\Scaffold\Exceptions\ForbiddenException;
use Aedart\Scaffold\Providers\ScaffoldServiceProvider;
use Illuminate\Container\Container;
use Illuminate\Contracts\Config\Repository;
use Illuminate\Support\Facades\App;

/**
 * IoC Service Container (Wrapper)
 *
 * This class acts first and foremost as a wrapper for Laravel's
 * service container. Secondly, additional application logic has
 * been added, in regards to resolving instances from specifiable
 * configuration repositories.
 *
 * @see \Illuminate\Contracts\Container\Container
 *
 * @author <NAME> <<EMAIL>>
 * @package Aedart\Scaffold\Resolvers
 */
class IoC
{
    /**
     * Instance of this resolver
     *
     * @var self
     */
    private static $instance;

    /**
     * IoC Service Container instance
     *
     * @var \Illuminate\Contracts\Container\Container
     */
    protected $container;

    /**
     * Get the resolver instance
     *
     * @return self
     */
    static public function getInstance()
    {
        if(null === static::$instance){
            static::$instance = new static();
        }

        return static::$instance;
    }

    /**
     * Boot the IoC (Alias for the getInstance method)
     *
     * @see getInstance()
     *
     * @return IoC
     */
    static public function boot()
    {
        return self::getInstance();
    }

    /**
     * IoC constructor.
     */
    private function __construct()
    {
        $this->setupContainer();
        $this->registerServiceProviders();
    }

    /**
     * Force destroy the container
     *
     * WARNING: Avoid using this, unless you really need to
     * destroy the IoC!
     */
    public function destroy()
    {
        $this->container = null;

        App::setFacadeApplication(null);

        self::$instance = null;
    }

    /**
     * Initialise the IoC Service Container
     */
    protected function setupContainer(){
        // Only set the application on the Facade
        // if there is none yet set
        if(is_null(App::getFacadeApplication())){
            App::setFacadeApplication(new Container());
        }

        $this->container = App::getFacadeApplication();

        $this->container->singleton('app', $this->container);
    }

    /**
     * Register this application's service providers
     */
    public function registerServiceProviders()
    {
        $defaultServiceProvider = new ScaffoldServiceProvider($this->container());
        $defaultServiceProvider->register();
    }

    /**
     * Resolve a given instance based on the concrete instance
     * that is found in the configuration. If there is no
     * instance that can be resolved from the config, then a
     * default instance is attempted to be resolved
     *
     * @param string $entry Configuration or instance identifier
     * @param Repository $config
     *
     * @return mixed
     */
    public function resolveFromConfig($entry, Repository $config)
    {
        if($config->has($entry)){
            $instance = $config->get($entry);
            return new $instance;
        }

        return $this->container()->make($entry);
    }

    /**
     * Alias for Container::make
     *
     * @param string $concrete
     * @param array $parameters
     *
     * @see \Illuminate\Contracts\Container\Container::make()
     *
     * @return mixed
     */
    public function make($concrete, array $parameters = [])
    {
        return $this->container()->make($concrete, $parameters);
    }

    /**
     * Get the IoC Service Container instance
     *
     * @return \Illuminate\Contracts\Container\Container
     */
    public function container()
{'fraction_non_alphanumeric': 0.10944570135746606, 'fraction_numerical': 0.0, 'mean_word_length': 2.3489583333333335, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 37, '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': '6472912', 'n_tokens_mistral': 1899, 'n_tokens_neox': 1893, 'n_words': 522}