<commit_before><?php namespace Fructify\Services;
////////////////////////////////////////////////////////////////////////////////
//             ___________                     __   __  _____
//             \_   _____/______ __ __   _____/  |_|__|/ ____\__ __
//              |    __) \_  __ \  |  \_/ ___\   __\  \   __<   |  |
//              |     \   |  | \/  |  /\  \___|  | |  ||  |  \___  |
//              \___  /   |__|  |____/  \___  >__| |__||__|  / ____|
//                  \/                      \/               \/
// -----------------------------------------------------------------------------
//                          https://github.com/fructify
//
//          Designed and Developed by <NAME> <<EMAIL> @="<EMAIL>" />
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////

use Fructify\Contracts\IKernel;
use Fructify\Contracts\IRouter;
use Interop\Container\ContainerInterface as IContainer;
use Dflydev\Symfony\FinderFactoryInterface as IFinderFactory;

class Kernel implements IKernel
{
    /**
     * @Inject
     * @var IContainer
     */
    private $container;

    /**
     * @Inject
     * @var IFinderFactory
     */
    private $finder;

    /**
     * @Inject("config")
     * @var StdClass
     */
    private $config;

    /** @inheritdoc */
    public function boot()
    {
        // Where are our hooks located?
        $parentHooks = $this->config->paths->theme->parent->hooks;
        $childHooks = $this->config->paths->theme->child->hooks;

        // Loop through our hook files
        foreach ($this->finder->create()->files()->name('*.php')->in($parentHooks) as $file)
        {
            if ($this->childHasHooks())
            {
                // Only register one of our hooks if the child theme
                // does not have the same hook file.
                if (!file_exists(str_replace($parentHooks, $childHooks, $file)))
                {
                    $this->registerHook($file);
                }
            }
            else
            {
                $this->registerHook($file);
            }
        }

        // Now lets loop through the child theme hooks
        if ($this->childHasHooks())
        {
            foreach ($this->finder->create()->files()->name('*.php')->in($childHooks) as $file)
            {
                $this->registerHook($file);
            }
        }
    }

    /** @inheritdoc */
    public function hasChildTheme()
    {
        return
        (
            $this->config->paths->theme->parent->root
            !=
            $this->config->paths->theme->child->root
        );
    }

    /** @inheritdoc */
    public function childHasHooks()
    {
        if (!$this->hasChildTheme()) return false;

        return is_dir($this->config->paths->theme->child->hooks);
    }

    /** @inheritdoc */
    public function childHasRoutes()
    {
        if (!$this->hasChildTheme()) return false;

        return is_dir($this->config->paths->theme->child->routes);
    }

    /** @inheritdoc */
    public function childHasViews()
    {
        if (!$this->hasChildTheme()) return false;

        return is_dir($this->config->paths->theme->child->views);
    }

    private function registerHook($file)
    {Finder::create()

        // Unbind the closure from this class.
        // ie: Make it so in the included file ```$this``` is undefined.
        $unBoundClosure = $closure->bindTo(null);

        // Call the closure, it can return the actual hook closure.
        // This is so hooks may have dependecies injected into them.
        // Sometimes though, hooks are super simple and don't require
        // any dependecies in which case they do not need to return a
        // closure and can add their hooks directly.
        $hookClosure = call_user_func($unBoundClosure);

        // Now use the container to call the hook closure.
        // php-di will inject dependecies as needed.
        if ($hookClosure instanceof \Closure)
        {<commit_msg>WTF seriously... not sure how that happened.<commit_after><?php namespace Fructify\Services;
////////////////////////////////////////////////////////////////////////////////
//             ___________                     __   __  _____
//             \_   _____/______ __ __   _____/  |_|__|/ ____\__ __
//              |    __) \_  __ \  |  \_/ ___\   __\  \   __<   |  |
//              |     \   |  | \/  |  /\  \___|  | |  ||  |  \___  |
//              \___  /   |__|  |____/  \___  >__| |__||__|  / ____|
//                  \/                      \/               \/
// -----------------------------------------------------------------------------
//                          https://github.com/fructify
//
//          Designed and Developed by <NAME> <<EMAIL> @="bj<EMAIL>" />
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////

use Fructify\Contracts\IKernel;
use Fructify\Contracts\IRouter;
use Interop\Container\ContainerInterface as IContainer;
use Dflydev\Symfony\FinderFactoryInterface as IFinderFactory;

class Kernel implements IKernel
{
    /**
     * @Inject
     * @var IContainer
     */
    private $container;

    /**
     * @Inject
     * @var IFinderFactory
     */
    private $finder;

    /**
     * @Inject("config")
     * @var StdClass
     */
    private $config;

    /** @inheritdoc */
    public function boot()
    {
        // Where are our hooks located?
        $parentHooks = $this->config->paths->theme->parent->hooks;
        $childHooks = $this->config->paths->theme->child->hooks;

        // Loop through our hook files
        foreach ($this->finder->create()->files()->name('*.php')->in($parentHooks) as $file)
        {
            if ($this->childHasHooks())
            {
                // Only register one of our hooks if the child theme
                // does not have the same hook file.
                if (!file_exists(str_replace($parentHooks, $childHooks, $file)))
                {
                    $this->registerHook($file);
                }
            }
            else
            {
                $this->registerHook($file);
            }
        }

        // Now lets loop through the child theme hooks
        if ($this->childHasHooks())
        {
            foreach ($this->finder->create()->files()->name('*.php')->in($childHooks) as $file)
            {
                $this->registerHook($file);
            }
        }
    }

    /** @inheritdoc */
    public function hasChildTheme()
    {
        return
        (
            $this->config->paths->theme->parent->root
            !=
            $this->config->paths->theme->child->root
        );
    }

    /** @inheritdoc */
    public function childHasHooks()
    {
        if (!$this->hasChildTheme()) return false;

        return is_dir($this->config->paths->theme->child->hooks);
    }

    /** @inheritdoc */
    public function childHasRoutes()
    {
        if (!$this->hasChildTheme()) return false;

        return is_dir($this->config->paths->theme->child->routes);
    }

    /** @inheritdoc */
    public function childHasViews()
    {
        if (!$this->hasChildTheme()) return false;

        return is_dir($this->config->paths->theme->child->views);
    }

    private function registerHook($file)
    {
        // Create a closure that will include the hook file.
        $closure = function() use ($file) { return require($file); };

        // Unbind the closure from this class.
        // ie: Make it so in the included file ```$this``` is undefined.
        $unBoundClosure = $closure->bindTo(null);

        // Call the closure, it can return the actual hook closure.
        // This is so hooks may have dependecies injected into them.
        // Sometimes though, hooks are super simple and don't require
        // any dependecies in which case they do not need to return a
        // closure and can add their hooks directly.
        $hookClosure = call_user_func($unBoundClosure);

        // Now use the container to call the hook closure.
        // php-di will inject dependecies as needed.
        if ($hookClosure instanceof \Closure)
        {
{'fraction_non_alphanumeric': 0.2028653985071033, 'fraction_numerical': 0.0, 'mean_word_length': 1.2953854655982315, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 121, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6851680', 'n_tokens_mistral': 2212, 'n_tokens_neox': 2145, 'n_words': 488}