<commit_before><?php

/*
 * This file is part of flagrow/upload.
 *
 * Copyright (c) Flagrow.
 *
 * http://flagrow.github.io
 *
 * For the full copyright and license information, please view the license.md
 * file that was distributed with this source code.
 */


namespace Flagrow\Upload\Providers;

use Flagrow\Upload\Adapters;
use Flagrow\Upload\Commands\UploadHandler;
use Flagrow\Upload\Contracts\UploadAdapter;
use Flagrow\Upload\Helpers\Settings;
use Flarum\Core\Command\UploadAvatarHandler;
use Illuminate\Container\Container;
use Illuminate\Support\ServiceProvider;
use League\Flysystem\Adapter as FlyAdapters;
use League\Flysystem\Filesystem;
use League\Flysystem\FilesystemInterface;

class StorageServiceProvider extends ServiceProvider
{

    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        /** @var Settings $settings */
        $settings = $this->app->make(Settings::class);

        /** @var UploadAdapter $uploadAdapter */
        $uploadAdapter = function (Container $app) {
            return $this->instantiateUploadAdapter($app);
        };

        $this->app->when(UploadHandler::class)
            ->needs(UploadAdapter::class)
            ->give($uploadAdapter);

        if ($settings->get('overrideAvatarUpload')) {
            $this->app->when(UploadAvatarHandler::class)
                ->needs(FilesystemInterface::class)
                ->give($uploadAdapter->getFilesystem());
        }
    }

    /**
     * Sets the upload adapter for the specific preferred service.
     *
     * @param          $app
     * @return FilesystemInterface
     */
    protected function instantiateUploadAdapter(Container $app)
    {
        $settings = $app->make(Settings::class);

        switch ($settings->get('uploadMethod', 'local')) {
            default:
                return $this->local($settings);
        }
    }

    protected function local(Settings $settings)
    {
        return new Adapters\Local(
            new Filesystem(
                new FlyAdapters\Local(public_path('assets/files')),
                $settings->get('local', [])
            )
        );
    }
}<commit_msg>trying to get the right adapter bound into the avatar upload mechanism<commit_after><?php

/*
 * This file is part of flagrow/upload.
 *
 * Copyright (c) Flagrow.
 *
 * http://flagrow.github.io
 *
 * For the full copyright and license information, please view the license.md
 * file that was distributed with this source code.
 */


namespace Flagrow\Upload\Providers;

use Flagrow\Upload\Adapters;
use Flagrow\Upload\Commands\UploadHandler;
use Flagrow\Upload\Contracts\UploadAdapter;
use Flagrow\Upload\Helpers\Settings;
use Flarum\Core\Command\UploadAvatarHandler;
use Illuminate\Container\Container;
use Illuminate\Support\ServiceProvider;
use League\Flysystem\Adapter as FlyAdapters;
use League\Flysystem\AdapterInterface;
use League\Flysystem\Filesystem;
use League\Flysystem\FilesystemInterface;

class StorageServiceProvider extends ServiceProvider
{

    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        /** @var Settings $settings */
        $settings = $this->app->make(Settings::class);

        /** @var UploadAdapter $uploadAdapter */
        $uploadAdapter = function (Container $app) {
            return $this->instantiateUploadAdapter($app);
        };

        $this->app->when(UploadHandler::class)
            ->needs(UploadAdapter::class)
            ->give($uploadAdapter);

        if ($settings->get('overrideAvatarUpload')) {
            $this->app->when(UploadAvatarHandler::class)
                ->needs(FilesystemInterface::class)
                ->give($uploadAdapter()->getFilesystem());
        }
    }

    /**
     * Sets the upload adapter for the specific preferred service.
     *
     * @param          $app
     * @return FilesystemInterface
     */
    protected function instantiateUploadAdapter(Container $app)
    {
        $settings = $app->make(Settings::class);

        switch ($settings->get('uploadMethod', 'local')) {
            default:
                $app->bind(AdapterInterface::class, function () {
                    new FlyAdapters\Local(public_path('assets/files'));
                });

                return $this->local($app, $settings);
        }
    }

    protected function local(Container $app, Settings $settings)
    {
        return new Adapters\Local(
            new Filesystem(
                $app->make(AdapterInterface::class),
                $settings->get('local', [])
            )
        );
    }
}
{'fraction_non_alphanumeric': 0.11876075731497418, 'fraction_numerical': 0.0, 'mean_word_length': 2.5007530120481927, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, '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': '919517', 'n_tokens_mistral': 1263, 'n_tokens_neox': 1215, 'n_words': 271}