<?php

namespace Illuminate\Encryption;

use RuntimeException;
use Illuminate\Support\ServiceProvider;

class EncryptionServiceProvider extends ServiceProvider
{// Eccryption Service Provider extends Services Provider
    /**
     * Register the service provider.
     *
     * @return void
     *
     * @throws \RuntimeException
     */
    public function register()
    {// register this function
        $this->app->singleton('encrypter', function ($app) {
            $config = $app->make('config')->get('app');// who is app to make and get

            $key = $config['key'];// set config key

            $cipher = $config['cipher'];// set config cipher

            if (Encrypter::supported($key, $cipher)) {//determine is support this way
                return new Encrypter($key, $cipher);
            } elseif (McryptEncrypter::supported($key, $cipher)) {
                return new McryptEncrypter($key, $cipher);
            } else {
                throw new RuntimeException('No supported encrypter found. The cipher and / or key length are invalid.');
            }
        });// i hate this function, too simple
    }
}