<commit_before><?php

namespace Bolt\Extension;

use Bolt\Filesystem\Exception\IncludeFileException;
use Bolt\Filesystem\FilesystemInterface;
use Bolt\Filesystem\Handler\JsonFile;
use Bolt\Logger\FlashLoggerInterface;
use Cocur\Slugify\Slugify;

/**
 * Class to manage loading of extensions.
 *
 * @author <NAME> <<EMAIL>>
 */
class Manager
{
    /** @var ResolvedExtension[] */
    protected $extensions = [];
    /** @var string[] */
    protected $map = [];
    /** @var array */
    protected $autoload;

    /** @var FilesystemInterface */
    private $filesystem;
    /** @var FlashLoggerInterface */
    private $flashLogger;

    /**
     * Constructor.
     *
     * @param FilesystemInterface  $filesystem
     * @param FlashLoggerInterface $flashLogger
     */
    public function __construct(FilesystemInterface $filesystem, FlashLoggerInterface $flashLogger)
    {
        $this->filesystem = $filesystem;
        $this->flashLogger = $flashLogger;
    }

    /**
     * Load a collection of extension classes.
     */
    public function load()
    {
        /** @var JsonFile $autoloadJson */
        $autoloadJson = $this->filesystem->get('vendor/autoload.json');
        if (!$autoloadJson->exists()) {
            return;
        }

        try {
            $this->filesystem->includeFile('vendor/autoload.php');
        } catch (IncludeFileException $e) {
            return;
        }

        $this->autoload = (array) $autoloadJson->parse();
        foreach ($this->autoload as $loader) {
            $composerName = $loader['name'];
            if (class_exists($loader['class'])) {
                /** @var ExtensionInterface $class */
                $class = new $loader['class']();
                if ($class instanceof ExtensionInterface) {
                    $phpName = $class->getName();
                    $this->map[$phpName] = $composerName;
                    $this->extensions[$composerName] = new ResolvedExtension($class);
                } else {
                    $this->flashLogger->error(sprintf('Extension package %s base class %s does not implement \\Bolt\\Extension\\ExtensionInterface and has been skipped.', $loader['name'], $loader['class']));
                }
            } else {<commit_msg>Cope with no extensions/vendor/ directory<commit_after><?php

namespace Bolt\Extension;

use Bolt\Filesystem\Exception\FileNotFoundException;
use Bolt\Filesystem\Exception\IncludeFileException;
use Bolt\Filesystem\FilesystemInterface;
use Bolt\Filesystem\Handler\JsonFile;
use Bolt\Logger\FlashLoggerInterface;
use Cocur\Slugify\Slugify;

/**
 * Class to manage loading of extensions.
 *
 * @author <NAME> <<EMAIL>>
 */
class Manager
{
    /** @var ResolvedExtension[] */
    protected $extensions = [];
    /** @var string[] */
    protected $map = [];
    /** @var array */
    protected $autoload;

    /** @var FilesystemInterface */
    private $filesystem;
    /** @var FlashLoggerInterface */
    private $flashLogger;

    /**
     * Constructor.
     *
     * @param FilesystemInterface  $filesystem
     * @param FlashLoggerInterface $flashLogger
     */
    public function __construct(FilesystemInterface $filesystem, FlashLoggerInterface $flashLogger)
    {
        $this->filesystem = $filesystem;
        $this->flashLogger = $flashLogger;
    }

    /**
     * Load a collection of extension classes.
     */
    public function load()
    {
        try {
            /** @var JsonFile $autoloadJson */
            $autoloadJson = $this->filesystem->get('vendor/autoload.json');
            $this->filesystem->includeFile('vendor/autoload.php');
        } catch (FileNotFoundException $e) {
            return;
        } catch (IncludeFileException $e) {
            return;
        }

        $this->autoload = (array) $autoloadJson->parse();
        foreach ($this->autoload as $loader) {
            $composerName = $loader['name'];
            if (class_exists($loader['class'])) {
                /** @var ExtensionInterface $class */
                $class = new $loader['class']();
                if ($class instanceof ExtensionInterface) {
                    $phpName = $class->getName();
                    $this->map[$phpName] = $composerName;
                    $this->extensions[$composerName] = new ResolvedExtension($class);
                } else {
                    $this->flashLogger->error(sprintf('Extension package %s base class %s does not implement \\Bolt\\Extension\\ExtensionInterface and has been skipped.', $loader['name'], $loader['class']));
                }
            } else {
{'fraction_non_alphanumeric': 0.135678391959799, 'fraction_numerical': 0.0, 'mean_word_length': 2.3101952277657265, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 38, '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': '5254543', 'n_tokens_mistral': 1253, 'n_tokens_neox': 1228, 'n_words': 267}