diff --git a/config/app.php b/config/app.php index 4ba2ad7f91..c4d3537fc2 100644 --- a/config/app.php +++ b/config/app.php @@ -231,7 +231,6 @@ */ 'key' => env('APP_KEY'), - 'cipher' => 'AES-256-CBC', /* @@ -249,7 +248,7 @@ // 'Illuminate\Html\HtmlServiceProvider', // Example - 'System\ServiceProvider', + System\ServiceProvider::class, ]), /* @@ -284,9 +283,6 @@ */ 'aliases' => array_merge(include(base_path('modules/system/aliases.php')), [ - // 'Str' => 'Illuminate\Support\Str', // Example - ]), - ]; diff --git a/config/auth.php b/config/auth.php index 8dc13b61c7..846e31a593 100644 --- a/config/auth.php +++ b/config/auth.php @@ -1,8 +1,8 @@ [ + /* |-------------------------------------------------------------------------- | Enable throttling of Backend authentication attempts @@ -11,7 +11,8 @@ | If set to true, users will be given a limited number of attempts to sign | in to the Backend before being blocked for a specified number of minutes. | - */ + */ + 'enabled' => true, /* @@ -21,7 +22,8 @@ | | Number of failed attempts allowed while trying to authenticate a user. | - */ + */ + 'attemptLimit' => 5, /* @@ -32,8 +34,8 @@ | The number of minutes to suspend further attempts on authentication once | the attempt limit is reached. | - */ + */ + 'suspensionTime' => 15, ], - ]; diff --git a/config/broadcasting.php b/config/broadcasting.php index 542f5f1de3..948f010a11 100644 --- a/config/broadcasting.php +++ b/config/broadcasting.php @@ -29,39 +29,32 @@ */ 'connections' => [ - 'pusher' => [ - 'app_id' => env('PUSHER_APP_ID'), + 'app_id' => env('PUSHER_APP_ID'), 'client_options' => [ // Guzzle client options: https://docs.guzzlephp.org/en/stable/request-options.html ], - 'driver' => 'pusher', - 'key' => env('PUSHER_APP_KEY'), - 'options' => [ + 'driver' => 'pusher', + 'key' => env('PUSHER_APP_KEY'), + 'options' => [ 'cluster' => env('PUSHER_APP_CLUSTER'), - 'useTLS' => true, + 'useTLS' => true, ], - 'secret' => env('PUSHER_APP_SECRET'), + 'secret' => env('PUSHER_APP_SECRET'), ], - 'ably' => [ 'driver' => 'ably', - 'key' => env('ABLY_KEY'), + 'key' => env('ABLY_KEY'), ], - 'redis' => [ 'connection' => 'default', - 'driver' => 'redis', + 'driver' => 'redis', ], - 'log' => [ 'driver' => 'log', ], - 'null' => [ 'driver' => 'null', ], - ], - ]; diff --git a/config/cache.php b/config/cache.php index e2bba31603..c689a4ba53 100644 --- a/config/cache.php +++ b/config/cache.php @@ -35,31 +35,26 @@ */ 'stores' => [ - 'apc' => [ 'driver' => 'apc', ], - 'array' => [ - 'driver' => 'array', + 'driver' => 'array', 'serialize' => false, ], - 'database' => [ - 'connection' => null, - 'driver' => 'database', + 'connection' => null, + 'driver' => 'database', 'lock_connection' => null, - 'table' => 'cache', + 'table' => 'cache', ], - 'file' => [ 'driver' => 'file', - 'path' => storage_path('framework/cache'), + 'path' => storage_path('framework/cache'), ], - 'memcached' => [ - 'driver' => 'memcached', - 'options' => [ + 'driver' => 'memcached', + 'options' => [ // Memcached::OPT_CONNECT_TIMEOUT => 2000, ], 'persistent_id' => env('MEMCACHED_PERSISTENT_ID'), @@ -67,7 +62,7 @@ env('MEMCACHED_USERNAME'), env('MEMCACHED_PASSWORD'), ], - 'servers' => [ + 'servers' => [ [ 'host' => env('MEMCACHED_HOST', '127.0.0.1'), 'port' => env('MEMCACHED_PORT', 11211), @@ -75,26 +70,22 @@ ], ], ], - 'redis' => [ - 'connection' => 'cache', - 'driver' => 'redis', + 'connection' => 'cache', + 'driver' => 'redis', 'lock_connection' => 'default', ], - 'dynamodb' => [ - 'driver' => 'dynamodb', + 'driver' => 'dynamodb', 'endpoint' => env('DYNAMODB_ENDPOINT'), - 'key' => env('AWS_ACCESS_KEY_ID'), - 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), - 'secret' => env('AWS_SECRET_ACCESS_KEY'), - 'table' => env('DYNAMODB_CACHE_TABLE', 'cache'), + 'key' => env('AWS_ACCESS_KEY_ID'), + 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), + 'secret' => env('AWS_SECRET_ACCESS_KEY'), + 'table' => env('DYNAMODB_CACHE_TABLE', 'cache'), ], - 'octane' => [ 'driver' => 'octane', ], - ], /* @@ -108,7 +99,7 @@ | */ - 'prefix' => env('CACHE_PREFIX', str_slug(env('APP_NAME', 'winter'), '_').'_cache'), + 'prefix' => env('CACHE_PREFIX', str_slug(env('APP_NAME', 'winter'), '_') . '_cache'), /* |-------------------------------------------------------------------------- @@ -145,5 +136,4 @@ */ 'disableRequestCache' => null, - ]; diff --git a/config/cms.php b/config/cms.php index c906b5c6eb..560491de72 100644 --- a/config/cms.php +++ b/config/cms.php @@ -91,7 +91,7 @@ | */ - 'backendSkin' => 'Backend\Skins\Standard', + 'backendSkin' => \Backend\Skins\Standard::class, /* |-------------------------------------------------------------------------- @@ -117,7 +117,11 @@ | */ - 'loadModules' => ['System', 'Backend', 'Cms'], + 'loadModules' => [ + 'System', + 'Backend', + 'Cms', + ], /* |-------------------------------------------------------------------------- @@ -312,26 +316,22 @@ */ 'storage' => [ - 'uploads' => [ - 'disk' => 'local', - 'folder' => 'uploads', - 'path' => '/storage/app/uploads', + 'disk' => 'local', + 'folder' => 'uploads', + 'path' => '/storage/app/uploads', 'temporaryUrlTTL' => 3600, ], - 'media' => [ - 'disk' => 'local', + 'disk' => 'local', 'folder' => 'media', - 'path' => '/storage/app/media', + 'path' => '/storage/app/media', ], - 'resized' => [ - 'disk' => 'local', + 'disk' => 'local', 'folder' => 'resized', - 'path' => '/storage/app/resized', + 'path' => '/storage/app/resized', ], - ], /* @@ -371,7 +371,10 @@ | */ - 'defaultMask' => ['file' => null, 'folder' => null], + 'defaultMask' => [ + 'file' => null, + 'folder' => null, + ], /* |-------------------------------------------------------------------------- @@ -466,5 +469,4 @@ */ 'enableBackendServiceWorkers' => false, - ]; diff --git a/config/cookie.php b/config/cookie.php index f286fe5a6b..654d29df81 100644 --- a/config/cookie.php +++ b/config/cookie.php @@ -17,5 +17,4 @@ 'unencryptedCookies' => [ // 'my_cookie', ], - ]; diff --git a/config/database.php b/config/database.php index e597bf084e..f57e26acac 100644 --- a/config/database.php +++ b/config/database.php @@ -31,63 +31,58 @@ */ 'connections' => [ - 'sqlite' => [ - 'database' => env('DB_DATABASE', storage_path('database.sqlite')), - 'driver' => 'sqlite', + 'database' => env('DB_DATABASE', storage_path('database.sqlite')), + 'driver' => 'sqlite', 'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true), - 'prefix' => '', - 'url' => env('DATABASE_URL'), + 'prefix' => '', + 'url' => env('DATABASE_URL'), ], - 'mysql' => [ - 'charset' => 'utf8mb4', - 'collation' => 'utf8mb4_unicode_ci', - 'database' => env('DB_DATABASE', 'winter'), - 'driver' => 'mysql', - 'engine' => 'InnoDB', - 'host' => env('DB_HOST', '127.0.0.1'), - 'options' => extension_loaded('pdo_mysql') ? array_filter([ + 'charset' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'database' => env('DB_DATABASE', 'winter'), + 'driver' => 'mysql', + 'engine' => 'InnoDB', + 'host' => env('DB_HOST', '127.0.0.1'), + 'options' => extension_loaded('pdo_mysql') ? array_filter([ PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), ]) : [], - 'password' => env('DB_PASSWORD', ''), - 'port' => env('DB_PORT', '3306'), - 'prefix' => '', + 'password' => env('DB_PASSWORD', ''), + 'port' => env('DB_PORT', '3306'), + 'prefix' => '', 'prefix_indexes' => true, - 'strict' => true, - 'unix_socket' => env('DB_SOCKET', ''), - 'url' => env('DATABASE_URL'), - 'username' => env('DB_USERNAME', 'winter'), + 'strict' => true, + 'unix_socket' => env('DB_SOCKET', ''), + 'url' => env('DATABASE_URL'), + 'username' => env('DB_USERNAME', 'winter'), ], - 'pgsql' => [ - 'charset' => 'utf8', - 'database' => env('DB_DATABASE', 'winter'), - 'driver' => 'pgsql', - 'host' => env('DB_HOST', '127.0.0.1'), - 'password' => env('DB_PASSWORD', ''), - 'port' => env('DB_PORT', '5432'), - 'prefix' => '', + 'charset' => 'utf8', + 'database' => env('DB_DATABASE', 'winter'), + 'driver' => 'pgsql', + 'host' => env('DB_HOST', '127.0.0.1'), + 'password' => env('DB_PASSWORD', ''), + 'port' => env('DB_PORT', '5432'), + 'prefix' => '', 'prefix_indexes' => true, - 'search_path' => 'public', - 'sslmode' => 'prefer', - 'url' => env('DATABASE_URL'), - 'username' => env('DB_USERNAME', 'winter'), + 'search_path' => 'public', + 'sslmode' => 'prefer', + 'url' => env('DATABASE_URL'), + 'username' => env('DB_USERNAME', 'winter'), ], - 'sqlsrv' => [ - 'charset' => 'utf8', - 'database' => env('DB_DATABASE', 'winter'), - 'driver' => 'sqlsrv', - 'host' => env('DB_HOST', '127.0.0.1'), - 'password' => env('DB_PASSWORD', ''), - 'port' => env('DB_PORT', '1433'), - 'prefix' => '', + 'charset' => 'utf8', + 'database' => env('DB_DATABASE', 'winter'), + 'driver' => 'sqlsrv', + 'host' => env('DB_HOST', '127.0.0.1'), + 'password' => env('DB_PASSWORD', ''), + 'port' => env('DB_PORT', '1433'), + 'prefix' => '', 'prefix_indexes' => true, - 'url' => env('DATABASE_URL'), - 'username' => env('DB_USERNAME', 'winter'), + 'url' => env('DATABASE_URL'), + 'username' => env('DB_USERNAME', 'winter'), ], - ], /* @@ -115,30 +110,24 @@ */ 'redis' => [ - 'client' => env('REDIS_CLIENT', 'phpredis'), - 'options' => [ 'cluster' => env('REDIS_CLUSTER', 'redis'), - 'prefix' => env('REDIS_PREFIX', str_slug(env('APP_NAME', 'winter'), '_').'_database_'), + 'prefix' => env('REDIS_PREFIX', str_slug(env('APP_NAME', 'winter'), '_') . '_database_'), ], - 'default' => [ 'database' => env('REDIS_DB', '0'), - 'host' => env('REDIS_HOST', '127.0.0.1'), + 'host' => env('REDIS_HOST', '127.0.0.1'), 'password' => env('REDIS_PASSWORD'), - 'port' => env('REDIS_PORT', '6379'), - 'url' => env('REDIS_URL'), + 'port' => env('REDIS_PORT', '6379'), + 'url' => env('REDIS_URL'), ], - 'cache' => [ 'database' => env('REDIS_CACHE_DB', '1'), - 'host' => env('REDIS_HOST', '127.0.0.1'), + 'host' => env('REDIS_HOST', '127.0.0.1'), 'password' => env('REDIS_PASSWORD'), - 'port' => env('REDIS_PORT', '6379'), - 'url' => env('REDIS_URL'), + 'port' => env('REDIS_PORT', '6379'), + 'url' => env('REDIS_URL'), ], - ], - ]; diff --git a/config/develop.php b/config/develop.php index 381b56409d..4a30178b51 100644 --- a/config/develop.php +++ b/config/develop.php @@ -42,5 +42,4 @@ */ 'allowDeepSymlinks' => false, - ]; diff --git a/config/environment.php b/config/environment.php index 5249b15bad..caa9f6581c 100644 --- a/config/environment.php +++ b/config/environment.php @@ -27,9 +27,6 @@ */ 'hosts' => [ - 'localhost' => 'dev', - ], - ]; diff --git a/config/filesystems.php b/config/filesystems.php index a85fcc8a9e..7e11f19981 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -29,24 +29,20 @@ */ 'disks' => [ - 'local' => [ 'driver' => 'local', - 'root' => storage_path('app'), - 'url' => '/storage/app', + 'root' => storage_path('app'), + 'url' => '/storage/app', ], - 's3' => [ - 'bucket' => env('AWS_BUCKET'), - 'driver' => 's3', - 'endpoint' => env('AWS_ENDPOINT'), - 'key' => env('AWS_ACCESS_KEY_ID'), - 'region' => env('AWS_DEFAULT_REGION'), - 'secret' => env('AWS_SECRET_ACCESS_KEY'), - 'url' => env('AWS_URL'), + 'bucket' => env('AWS_BUCKET'), + 'driver' => 's3', + 'endpoint' => env('AWS_ENDPOINT'), + 'key' => env('AWS_ACCESS_KEY_ID'), + 'region' => env('AWS_DEFAULT_REGION'), + 'secret' => env('AWS_SECRET_ACCESS_KEY'), + 'url' => env('AWS_URL'), 'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false), ], - ], - ]; diff --git a/config/hashing.php b/config/hashing.php index 616059443b..ad56664fb1 100644 --- a/config/hashing.php +++ b/config/hashing.php @@ -44,9 +44,8 @@ */ 'argon' => [ - 'memory' => 65536, + 'memory' => 65536, 'threads' => 1, - 'time' => 4, + 'time' => 4, ], - ]; diff --git a/config/logging.php b/config/logging.php index e7ea8f3bb6..415941e91c 100644 --- a/config/logging.php +++ b/config/logging.php @@ -45,71 +45,63 @@ 'channels' => [ 'stack' => [ - 'channels' => ['single'], - 'driver' => 'stack', + 'channels' => [ + 'single', + ], + 'driver' => 'stack', 'ignore_exceptions' => false, ], - 'single' => [ 'driver' => 'single', - 'level' => env('LOG_LEVEL', 'debug'), - 'path' => storage_path('logs/system.log'), + 'level' => env('LOG_LEVEL', 'debug'), + 'path' => storage_path('logs/system.log'), ], - 'daily' => [ - 'days' => 14, + 'days' => 14, 'driver' => 'daily', - 'level' => env('LOG_LEVEL', 'debug'), - 'path' => storage_path('logs/system.log'), + 'level' => env('LOG_LEVEL', 'debug'), + 'path' => storage_path('logs/system.log'), ], - 'slack' => [ - 'driver' => 'slack', - 'emoji' => ':boom:', - 'level' => env('LOG_LEVEL', 'critical'), - 'url' => env('LOG_SLACK_WEBHOOK_URL'), + 'driver' => 'slack', + 'emoji' => ':boom:', + 'level' => env('LOG_LEVEL', 'critical'), + 'url' => env('LOG_SLACK_WEBHOOK_URL'), 'username' => 'Winter Log', ], - 'papertrail' => [ - 'driver' => 'monolog', - 'handler' => env('LOG_PAPERTRAIL_HANDLER', \Monolog\Handler\SyslogUdpHandler::class), + 'driver' => 'monolog', + 'handler' => env('LOG_PAPERTRAIL_HANDLER', \Monolog\Handler\SyslogUdpHandler::class), 'handler_with' => [ - 'connectionString' => 'tls://'.env('PAPERTRAIL_URL').':'.env('PAPERTRAIL_PORT'), - 'host' => env('PAPERTRAIL_URL'), - 'port' => env('PAPERTRAIL_PORT'), + 'connectionString' => 'tls://' . env('PAPERTRAIL_URL') . ':' . env('PAPERTRAIL_PORT'), + 'host' => env('PAPERTRAIL_URL'), + 'port' => env('PAPERTRAIL_PORT'), ], - 'level' => env('LOG_LEVEL', 'debug'), + 'level' => env('LOG_LEVEL', 'debug'), ], - 'stderr' => [ - 'driver' => 'monolog', + 'driver' => 'monolog', 'formatter' => env('LOG_STDERR_FORMATTER'), - 'handler' => \Monolog\Handler\StreamHandler::class, - 'level' => env('LOG_LEVEL', 'debug'), - 'with' => [ + 'handler' => \Monolog\Handler\StreamHandler::class, + 'level' => env('LOG_LEVEL', 'debug'), + 'with' => [ 'stream' => 'php://stderr', ], ], - 'syslog' => [ 'driver' => 'syslog', - 'level' => env('LOG_LEVEL', 'debug'), + 'level' => env('LOG_LEVEL', 'debug'), ], - 'errorlog' => [ 'driver' => 'errorlog', - 'level' => env('LOG_LEVEL', 'debug'), + 'level' => env('LOG_LEVEL', 'debug'), ], - 'null' => [ - 'driver' => 'monolog', + 'driver' => 'monolog', 'handler' => \Monolog\Handler\NullHandler::class, ], - 'emergency' => [ 'path' => storage_path('logs/system.log'), ], ], - ]; diff --git a/config/mail.php b/config/mail.php index 25a896d141..03eae82251 100644 --- a/config/mail.php +++ b/config/mail.php @@ -36,42 +36,35 @@ 'mailers' => [ 'smtp' => [ 'encryption' => env('MAIL_ENCRYPTION', 'tls'), - 'host' => env('MAIL_HOST', 'smtp.mailgun.org'), - 'password' => env('MAIL_PASSWORD'), - 'port' => env('MAIL_PORT', 587), - 'timeout' => null, - 'transport' => 'smtp', - 'username' => env('MAIL_USERNAME'), + 'host' => env('MAIL_HOST', 'smtp.mailgun.org'), + 'password' => env('MAIL_PASSWORD'), + 'port' => env('MAIL_PORT', 587), + 'timeout' => null, + 'transport' => 'smtp', + 'username' => env('MAIL_USERNAME'), ], - 'ses' => [ 'transport' => 'ses', ], - 'mailgun' => [ 'transport' => 'mailgun', ], - 'postmark' => [ 'transport' => 'postmark', ], - 'sendmail' => [ - 'path' => env('MAIL_SENDMAIL_PATH', '/usr/sbin/sendmail -t -i'), + 'path' => env('MAIL_SENDMAIL_PATH', '/usr/sbin/sendmail -t -i'), 'transport' => 'sendmail', ], - 'log' => [ - 'channel' => env('MAIL_LOG_CHANNEL'), + 'channel' => env('MAIL_LOG_CHANNEL'), 'transport' => 'log', ], - 'array' => [ 'transport' => 'array', ], - 'failover' => [ - 'mailers' => [ + 'mailers' => [ 'smtp', 'log', ], @@ -92,7 +85,6 @@ 'from' => [ 'address' => env('MAIL_FROM_ADDRESS', 'noreply@example.com'), - 'name' => env('MAIL_FROM_NAME', env('APP_NAME', 'Winter CMS')), + 'name' => env('MAIL_FROM_NAME', env('APP_NAME', 'Winter CMS')), ], - ]; diff --git a/config/queue.php b/config/queue.php index ba40614d70..342b9d650d 100644 --- a/config/queue.php +++ b/config/queue.php @@ -29,48 +29,42 @@ */ 'connections' => [ - 'sync' => [ 'driver' => 'sync', ], - 'database' => [ 'after_commit' => false, - 'driver' => 'database', - 'queue' => 'default', - 'retry_after' => 90, - 'table' => 'jobs', + 'driver' => 'database', + 'queue' => 'default', + 'retry_after' => 90, + 'table' => 'jobs', ], - 'beanstalkd' => [ 'after_commit' => false, - 'block_for' => 0, - 'driver' => 'beanstalkd', - 'host' => 'localhost', - 'queue' => 'default', - 'retry_after' => 90, + 'block_for' => 0, + 'driver' => 'beanstalkd', + 'host' => 'localhost', + 'queue' => 'default', + 'retry_after' => 90, ], - 'sqs' => [ 'after_commit' => false, - 'driver' => 'sqs', - 'key' => env('AWS_ACCESS_KEY_ID'), - 'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'), - 'queue' => env('SQS_QUEUE', 'default'), - 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), - 'secret' => env('AWS_SECRET_ACCESS_KEY'), - 'suffix' => env('SQS_SUFFIX'), + 'driver' => 'sqs', + 'key' => env('AWS_ACCESS_KEY_ID'), + 'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'), + 'queue' => env('SQS_QUEUE', 'default'), + 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), + 'secret' => env('AWS_SECRET_ACCESS_KEY'), + 'suffix' => env('SQS_SUFFIX'), ], - 'redis' => [ 'after_commit' => false, - 'block_for' => null, - 'connection' => 'default', - 'driver' => 'redis', - 'queue' => env('REDIS_QUEUE', 'default'), - 'retry_after' => 90, + 'block_for' => null, + 'connection' => 'default', + 'driver' => 'redis', + 'queue' => env('REDIS_QUEUE', 'default'), + 'retry_after' => 90, ], - ], /* @@ -86,8 +80,7 @@ 'failed' => [ 'database' => env('DB_CONNECTION', 'mysql'), - 'driver' => env('QUEUE_FAILED_DRIVER', 'database-uuids'), - 'table' => 'failed_jobs', + 'driver' => env('QUEUE_FAILED_DRIVER', 'database-uuids'), + 'table' => 'failed_jobs', ], - ]; diff --git a/config/services.php b/config/services.php index 32760c1d49..fd9b6e0161 100644 --- a/config/services.php +++ b/config/services.php @@ -15,19 +15,16 @@ */ 'mailgun' => [ - 'domain' => env('MAILGUN_DOMAIN'), + 'domain' => env('MAILGUN_DOMAIN'), 'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'), - 'secret' => env('MAILGUN_SECRET'), + 'secret' => env('MAILGUN_SECRET'), ], - 'postmark' => [ 'token' => env('POSTMARK_TOKEN'), ], - 'ses' => [ - 'key' => env('AWS_ACCESS_KEY_ID'), + 'key' => env('AWS_ACCESS_KEY_ID'), 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 'secret' => env('AWS_SECRET_ACCESS_KEY'), ], - ]; diff --git a/config/session.php b/config/session.php index 78aac1472e..2137951367 100644 --- a/config/session.php +++ b/config/session.php @@ -30,7 +30,6 @@ */ 'lifetime' => env('SESSION_LIFETIME', 120), - 'expire_on_close' => false, /* @@ -111,7 +110,10 @@ | */ - 'lottery' => [2, 100], + 'lottery' => [ + 2, + 100, + ], /* |-------------------------------------------------------------------------- @@ -124,10 +126,7 @@ | */ - 'cookie' => env( - 'SESSION_COOKIE', - str_slug(env('APP_NAME', 'winter'), '_').'_session' - ), + 'cookie' => env('SESSION_COOKIE', str_slug(env('APP_NAME', 'winter'), '_') . '_session'), /* |-------------------------------------------------------------------------- @@ -214,5 +213,4 @@ */ 'same_site' => 'lax', - ]; diff --git a/config/view.php b/config/view.php index bbbb7327e0..63394f68a5 100644 --- a/config/view.php +++ b/config/view.php @@ -30,9 +30,5 @@ | */ - 'compiled' => env( - 'VIEW_COMPILED_PATH', - realpath(storage_path('framework/views')) - ), - + 'compiled' => env('VIEW_COMPILED_PATH', realpath(storage_path('framework/views'))), ]; diff --git a/modules/system/console/WinterEnv.php b/modules/system/console/WinterEnv.php index 728c99cd40..2cafbe764d 100644 --- a/modules/system/console/WinterEnv.php +++ b/modules/system/console/WinterEnv.php @@ -1,7 +1,9 @@ error('.env file already exists.'); + if ( + file_exists($this->laravel->environmentFilePath()) + && !$this->confirmToProceed() + ) { + return 1; } - $this->overwriteConfig(); + $this->updateEnvFile(); + $this->updateConfigFiles(); $this->info('.env configuration file has been created.'); - } - /** - * Overwrite config file - */ - protected function overwriteConfig() - { - foreach (array_keys($this->config()) as $config) { - $this->config = $config; - - $this->configToEnv(); - } + return 0; } /** - * Replace config values with env() syntax - */ - protected function configToEnv() - { - $content = $this->parseConfigFile(); - - $this->writeToConfigFile($content); - } - - /** - * Parse config file line by line + * Confirm before proceeding with the action. * - * @return string + * This method only asks for confirmation in production. + * + * @param string $warning + * @param \Closure|bool|null $callback + * @return bool */ - protected function parseConfigFile() + public function confirmToProceed($warning = 'Application In Production!', $callback = null) { - $lines = []; - - foreach ($this->lines() as $line) { - $keys = $this->config()[$this->config]; - - $lines[] = $this->parseLine($line, $keys); + if ($this->hasOption('force') && $this->option('force')) { + return true; } - $this->writeToEnv("\n"); - - return implode('', $lines); - } + $this->alert('The .env file already exists. Proceeding may overwrite some values!'); - /** - * @param $keys - * @param $line - * @return mixed - */ - protected function parseLine($line, $keys) - { - $line = $this->replaceConfigLine($line, $keys); + $confirmed = $this->confirm('Do you really wish to run this command?'); - $line = $this->replaceDbConfigLine($line); + if (!$confirmed) { + $this->comment('Command Canceled!'); - return $line; - } - - /** - * @param $line - * @param $keys - * @return mixed - */ - protected function replaceConfigLine($line, $keys) - { - foreach ($keys as $envKey => $configKey) { - $pattern = $this->buildPattern($configKey); - - $callback = $this->buildCallback($envKey, $configKey); - - if (preg_match($pattern, $line)) { - $line = preg_replace_callback($pattern, $callback, $line); - } + return false; } - return $line; + return true; } /** - * @param $line - * @return mixed - */ - protected function replaceDbConfigLine($line) - { - if ($this->config == 'database') { - foreach ($this->dbConfig() as $connection => $settings) { - $this->setCurrentConnection($line, $connection); - - if ($this->connection == $connection) { - $line = $this->replaceConfigLine($line, $settings); - } - } - } - - return $line; - } - - /** - * @param $line - * @param $connection - */ - protected function setCurrentConnection($line, $connection) - { - if (preg_match("/['\"]" . $connection . "['\"]" . "\s*=>/", $line)) { - $this->connection = $connection; - } - } - - /** - * @param $configKey + * Get the full path of a config file + * @param string $config * @return string */ - protected function buildPattern($configKey) + protected function getConfigPath(string $config): string { - return "/['\"]" . $configKey . "['\"]" . "\s*=>\s*[^,\[]+,/"; + return rtrim(App::make('path.config'), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $config . '.php'; } /** - * @param $envKey - * @param $configKey - * @return \Closure + * Set env keys to their config values within the EnvFile object */ - protected function buildCallback($envKey, $configKey) + protected function updateEnvFile(): void { - return function ($matches) use ($envKey, $configKey) { - $value = $this->envValue($configKey); - - $this->saveEnvSettings($envKey, $this->normalizeForEnv($value)); - - // Remove protected values from the config files - if (in_array($envKey, $this->protectedKeys) && !empty($value)) { - $value = ''; - } - - return $this->isEnv($matches[0]) ? $matches[0] : "'$configKey' => env('$envKey', {$this->normalizeForConfig($value)}),"; - }; - } + $env = EnvFile::open($this->laravel->environmentFilePath()); + + foreach ($this->config() as $config => $items) { + foreach ($items as $envKey => $configKey) { + $env->set($envKey, config($config . '.' . $configKey)); + if ($config === 'database' && $envKey === 'DB_CONNECTION') { + $default = config('database.default'); + $dbConfig = $this->dbConfig()[$default] ?? []; + + foreach ($dbConfig as $dbEnvKey => $dbConfigKey) { + $env->set($dbEnvKey, config(join('.', [$config, 'connections', $default, $dbConfigKey]))); + } + } - /** - * @param $key - * @param $value - */ - protected function saveEnvSettings($key, $value) - { - if (! $this->envKeyExists($key)) { - $line = sprintf("%s=%s\n", $key, $value); + if ($config === 'mail' && $envKey === 'MAIL_MAILER') { + $default = config('mail.default'); + $mailConfig = $this->mailConfig()[$default] ?? []; - if ($this->config == 'database' && $key != 'DB_CONNECTION') { - $this->writeDbEnvSettings($line); - } else { - $this->writeToEnv($line); + foreach ($mailConfig as $mailEnvKey => $mailConfigKey) { + $env->set($mailEnvKey, config(join('.', [$config, 'mailers', $default, $mailConfigKey]))); + } + } } - } - } - - /** - * @param $line - */ - protected function writeDbEnvSettings($line) - { - if ($this->connection == config('database.default') || $this->connection == 'redis') { - $this->writeToEnv($line); - } - } - - /** - * @param $configKey - * @return string - */ - protected function envValue($configKey) - { - $value = config("$this->config.$configKey"); - - if ($this->config == 'database') { - $value = $this->databaseConfigValue($configKey); + $env->addEmptyLine(); } - return $value; + $env->write(); } /** - * @param $configKey - * @return string + * Update config files with env function calls */ - protected function databaseConfigValue($configKey) + protected function updateConfigFiles(): void { - if ($configKey == 'default') { - return config('database.default'); - } - - if ($this->connection == 'redis') { - return config("database.redis.default.$configKey"); - } - - return config("database.connections.$this->connection.$configKey"); - } - - /** - * Normalizes a value to be inserted into the .env file - * - * @param $value - * @return string - */ - protected function normalizeForEnv($value) - { - if (is_string($value)) { - if (preg_match('/["\'#]/', $value)) { - return '"' . str_replace('"', '\\"', $value) . '"'; - } else { - return $value; + foreach ($this->config() as $config => $items) { + $arrayFile = ArrayFile::open($this->getConfigPath($config)); + foreach ($items as $envKey => $configKey) { + $arrayFile->set( + $configKey, + $arrayFile->function('env', $this->getKeyValuePair($envKey, $config . '.' . $configKey)) + ); + if ($config === 'database' && $envKey === 'DB_CONNECTION') { + foreach ($this->dbConfig() as $connection => $keys) { + foreach ($keys as $dbEnvKey => $dbConfigKey) { + $path = sprintf('connections.%s.%s', $connection, $dbConfigKey); + $arrayFile->set( + $path, + $arrayFile->function('env', $this->getKeyValuePair($dbEnvKey, $config . '.' . $path)) + ); + } + } + } + if ($config === 'mail' && $envKey === 'MAIL_MAILER') { + foreach ($this->mailConfig() as $mailer => $keys) { + foreach ($keys as $mailEnvKey => $mailConfigKey) { + $path = sprintf('mailers.%s.%s', $mailer, $mailConfigKey); + $arrayFile->set( + $path, + $arrayFile->function('env', $this->getKeyValuePair($mailEnvKey, $config . '.' . $path)) + ); + } + } + } } - } elseif (is_bool($value)) { - return $value ? 'true' : 'false'; - } elseif ($value === null) { - return 'null'; - } - - return $value; - } - - /** - * Normalizes a value to be inserted into config files. - * - * @param $value - * @return string - */ - protected function normalizeForConfig($value) - { - if (is_string($value)) { - return '\'' . addslashes($value) . '\''; + $arrayFile->write(); } - - return $this->normalizeForEnv($value); } /** - * @param $matches - * @return bool + * Returns an array containing the key as the first element and the value + * as the second if the key is not a protected key; otherwise the value + * will be an empty string */ - protected function isEnv($matches) + protected function getKeyValuePair(string $envKey, string $configKey): array { - return strpos($matches, 'env') !== false; - } - - /** - * @param $content - */ - protected function writeToEnv($content) - { - file_put_contents('.env', $content, FILE_APPEND); - } - - /** - * @return string - */ - protected function readEnvFile() - { - return file_exists('.env') ? file_get_contents('.env') : ''; - } - - /** - * @param $content - */ - protected function writeToConfigFile($content) - { - file_put_contents(rtrim(App::make('path.config'), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $this->config . '.php', $content); + $return = [$envKey, in_array($envKey, $this->protectedKeys) ? '' : config($configKey)]; + return $return; } /** + * Returns a map of env keys to php config keys for db configs * @return array */ - protected function lines() - { - return file(rtrim(App::make('path.config'), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $this->config . '.php'); - } - - /** - * @param $key - * @return bool - */ - protected function envKeyExists($key) - { - return strpos($this->readEnvFile(), $key) !== false; - } - - /** - * @return array - */ - protected function config() + protected function config(): array { return [ 'app' => [ @@ -378,27 +216,23 @@ protected function config() 'QUEUE_CONNECTION' => 'default', ], 'mail' => [ - 'MAIL_DRIVER' => 'driver', - 'MAIL_HOST' => 'host', - 'MAIL_PORT' => 'port', - 'MAIL_USERNAME' => 'username', - 'MAIL_PASSWORD' => 'password', - 'MAIL_ENCRYPTION' => 'encryption', + 'MAIL_MAILER' => 'default', ], 'cms' => [ 'ROUTES_CACHE' => 'enableRoutesCache', 'ASSET_CACHE' => 'enableAssetCache', 'LINK_POLICY' => 'linkPolicy', 'ENABLE_CSRF' => 'enableCsrfProtection', - 'DATABASE_TEMPLATES' => 'databaseTemplates' + 'DATABASE_TEMPLATES' => 'databaseTemplates', ], ]; } /** + * Returns a map of env keys to php config keys for db configs * @return array */ - protected function dbConfig() + protected function dbConfig(): array { return [ 'sqlite' => [ @@ -425,4 +259,27 @@ protected function dbConfig() ], ]; } + + /** + * Returns a map of env keys to php config keys for mail configs + * @return array + */ + protected function mailConfig(): array + { + return [ + 'smtp' => [ + 'MAIL_ENCRYPTION' => 'encryption', + 'MAIL_HOST' => 'host', + 'MAIL_PASSWORD' => 'password', + 'MAIL_PORT' => 'port', + 'MAIL_USERNAME' => 'username', + ], + 'sendmail' => [ + 'MAIL_SENDMAIL_PATH' => 'path', + ], + 'log' => [ + 'MAIL_LOG_CHANNEL' => 'channel', + ], + ]; + } } diff --git a/tests/fixtures/config/app.php b/tests/fixtures/config/app.php index 26032b4db7..98d819f130 100644 --- a/tests/fixtures/config/app.php +++ b/tests/fixtures/config/app.php @@ -3,7 +3,7 @@ return [ 'debug' => true, - 'url' => 'https://localhost', + 'url' => 'https://env-test.localhost', 'key' => 'CHANGE_ME!!!!!!!!!!!!!!!!!!!!!!!', 'timezone' => 'UTC', ]; diff --git a/tests/fixtures/config/mail.php b/tests/fixtures/config/mail.php index 281e9dac28..7620ae57ef 100644 --- a/tests/fixtures/config/mail.php +++ b/tests/fixtures/config/mail.php @@ -2,7 +2,7 @@ // Fixture used for `winter:env` unit tests in `tests/unit/system/console/WinterEnvTest.php return [ - 'driver' => 'smtp', + 'default' => 'smtp', 'host' => 'smtp.mailgun.org', 'port' => 587, 'encryption' => 'tls', diff --git a/tests/unit/system/console/WinterEnvTest.php b/tests/unit/system/console/WinterEnvTest.php index 2ef64d2770..c75ad544e2 100644 --- a/tests/unit/system/console/WinterEnvTest.php +++ b/tests/unit/system/console/WinterEnvTest.php @@ -2,7 +2,7 @@ use Winter\Storm\Foundation\Bootstrap\LoadConfiguration; use Symfony\Component\Console\Input\ArrayInput; -use Symfony\Component\Console\Output\NullOutput; +use Symfony\Component\Console\Output\BufferedOutput; use System\Console\WinterEnv; class WinterEnvTest extends TestCase @@ -13,26 +13,34 @@ class WinterEnvTest extends TestCase /** @var string Stores the original config path from the app container */ public static $origConfigPath; + /** @var string Stores the original environment path from the app container */ + public static $origEnvPath; + protected function setUp(): void { parent::setUp(); $this->setUpConfigFixtures(); - $this->stubOutEnvFile(); } public function testCommand() { + $output = new BufferedOutput(); $command = new WinterEnv(); $command->setLaravel($this->app); - $command->run(new ArrayInput([]), new NullOutput); + $result = $command->run(new ArrayInput([]), $output); + + // Ensure that the command actually succeeded + if ($result !== 0) { + throw new \Exception("Command failed: \r\n" . $output->fetch()); + } // Check environment file - $envFile = file_get_contents(base_path('.env')); + $envFile = file_get_contents($this->app->environmentFilePath()); $this->assertStringContainsString('APP_DEBUG=true', $envFile); - $this->assertStringContainsString('APP_URL=https://localhost', $envFile); - $this->assertStringContainsString('DB_CONNECTION=mysql', $envFile); + $this->assertStringContainsString('APP_URL="https://env-test.localhost"', $envFile); + $this->assertStringContainsString('DB_CONNECTION="mysql"', $envFile); $this->assertStringContainsString('DB_DATABASE="data#base"', $envFile); $this->assertStringContainsString('DB_USERNAME="teal\'c"', $envFile); $this->assertStringContainsString('DB_PASSWORD="test\\"quotes\'test"', $envFile); @@ -42,7 +50,7 @@ public function testCommand() $appConfigFile = file_get_contents(storage_path('temp/tests/config/app.php')); $this->assertStringContainsString('\'debug\' => env(\'APP_DEBUG\', true),', $appConfigFile); - $this->assertStringContainsString('\'url\' => env(\'APP_URL\', \'https://localhost\'),', $appConfigFile); + $this->assertStringContainsString('\'url\' => env(\'APP_URL\', \'https://env-test.localhost\'),', $appConfigFile); // Check database.php config file $appConfigFile = file_get_contents(storage_path('temp/tests/config/database.php')); @@ -58,7 +66,6 @@ public function testCommand() protected function tearDown(): void { $this->tearDownConfigFixtures(); - $this->restoreEnvFile(); parent::tearDown(); } @@ -69,6 +76,9 @@ protected function setUpConfigFixtures() if (!is_dir(storage_path('temp/tests/config'))) { mkdir(storage_path('temp/tests/config'), 0777, true); } + if (!is_dir(storage_path('temp/tests/env'))) { + mkdir(storage_path('temp/tests/env'), 0777, true); + } foreach (glob(base_path('tests/fixtures/config/*.php')) as $file) { $path = pathinfo($file); @@ -79,8 +89,10 @@ protected function setUpConfigFixtures() // Store original config path static::$origConfigPath = $this->app->make('path.config'); + static::$origEnvPath = $this->app->environmentPath(); $this->app->instance('path.config', storage_path('temp/tests/config')); + $this->app->useEnvironmentPath(storage_path('temp/tests/env')); // Re-load configuration $configBootstrap = new LoadConfiguration; @@ -95,6 +107,8 @@ protected function tearDownConfigFixtures() unlink($file); } rmdir(storage_path('temp/tests/config')); + unlink(storage_path('temp/tests/env/.env')); + rmdir(storage_path('temp/tests/env')); rmdir(storage_path('temp/tests')); static::$fixturesCopied = false; @@ -103,31 +117,17 @@ protected function tearDownConfigFixtures() // Restore config path if (self::$origConfigPath) { $this->app->instance('path.config', static::$origConfigPath); - static::$origConfigPath = null; } + // Restore environment path + if (self::$origEnvPath) { + $this->app->useEnvironmentPath(static::$origEnvPath); + static::$origEnvPath = null; + } + // Re-load configuration $configBootstrap = new LoadConfiguration; $configBootstrap->bootstrap($this->app); } - - protected function stubOutEnvFile() - { - if (file_exists(base_path('.env.stub'))) { - unlink(base_path('.env.stub')); - } - if (file_exists(base_path('.env'))) { - rename(base_path('.env'), base_path('.env.stub')); - } - } - - protected function restoreEnvFile() - { - unlink(base_path('.env')); - - if (file_exists(base_path('.env.stub'))) { - rename(base_path('.env.stub'), base_path('.env')); - } - } }