Skip to content

Commit dc9bfcb

Browse files
author
Arif Hoque
committed
v1.0.7
1 parent 0f99674 commit dc9bfcb

23 files changed

+1384
-237
lines changed

composer.json

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
"symfony/process": "^7.2",
2222
"symfony/var-dumper": "^7.1",
2323
"vlucas/phpdotenv": "^5.5",
24-
"nesbot/carbon": "^3.8"
24+
"nesbot/carbon": "^3.8",
25+
"psr/simple-cache": "^3.0",
26+
"symfony/cache": "^7.2"
2527
},
2628
"require-dev": {
27-
"mockery/mockery": "^1.6",
28-
"phpunit/phpunit": "^11.5.3"
29+
"mockery/mockery": "^1.6",
30+
"phpunit/phpunit": "^11.5.3"
2931
},
3032
"autoload": {
3133
"psr-4": {
@@ -43,11 +45,6 @@
4345
"suggest": {
4446
"ext-pdo": "Required to use all database features."
4547
},
46-
"scripts": {
47-
"post-install-cmd": [
48-
"rm -f .editorconfig .gitattributes .gitignore phpunit.xml.dist UPGRADE.md"
49-
]
50-
},
5148
"config": {
5249
"sort-packages": true,
5350
"allow-plugins": {

src/Phaseolies/Application.php

Lines changed: 98 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ class Application extends Container
8080
*/
8181
protected $environmentFile = '.env';
8282

83+
/**
84+
* The environment name.
85+
*
86+
* @var string|null
87+
*/
88+
protected $environment;
89+
8390
/**
8491
* Indicates if the application is running in the console.
8592
*/
@@ -450,16 +457,6 @@ public function runningInConsole(): bool
450457
return $this->isRunningInConsole;
451458
}
452459

453-
/**
454-
* Determines if the application is running UNIT TEST
455-
*
456-
* @return bool
457-
*/
458-
public function isRunningUnitTests(): bool
459-
{
460-
return strpos($_SERVER['argv'][0] ?? '', 'phpunit') !== false;
461-
}
462-
463460
/**
464461
* Checks if the application has been bootstrapped.
465462
*
@@ -637,6 +634,97 @@ public function getProvider(string $provider): ?ServiceProvider
637634
return null;
638635
}
639636

637+
/**
638+
* Determine if the application is in the given environment.
639+
*
640+
* @param string|array $environments
641+
* @return bool
642+
*/
643+
public function environment(...$environments): bool
644+
{
645+
if (count($environments) === 1 && is_array($environments[0])) {
646+
$environments = $environments[0];
647+
}
648+
649+
$current = $this['config']->get('app.env', 'production');
650+
651+
foreach ($environments as $environment) {
652+
if ($environment === $current || strtolower($environment) === strtolower($current)) {
653+
return true;
654+
}
655+
}
656+
657+
return false;
658+
}
659+
660+
/**
661+
* Get or check the current application environment.
662+
*
663+
* @param string|null $environment
664+
* @return string|bool
665+
*/
666+
public function environmentIs($environment = null)
667+
{
668+
if (is_null($environment)) {
669+
return $this['config']->get('app.env', 'production');
670+
}
671+
672+
return $this->environment($environment);
673+
}
674+
675+
/**
676+
* Determine if the application is running in production.
677+
*
678+
* @return bool
679+
*/
680+
public function isProduction(): bool
681+
{
682+
return $this->environment('production');
683+
}
684+
685+
/**
686+
* Determine if the application is running in development.
687+
*
688+
* @return bool
689+
*/
690+
public function isDevelopment(): bool
691+
{
692+
return $this->environment('development', 'local');
693+
}
694+
695+
/**
696+
* Determines if the application is running UNIT TEST
697+
*
698+
* @return bool
699+
*/
700+
public function isRunningUnitTests(): bool
701+
{
702+
return strpos($_SERVER['argv'][0] ?? '', 'phpunit') !== false;
703+
}
704+
705+
/**
706+
* Get the environment file the application is using.
707+
*
708+
* @return string
709+
*/
710+
public function environmentFile(): string
711+
{
712+
return $this->environmentFile;
713+
}
714+
715+
/**
716+
* Set the environment file to be loaded during bootstrapping.
717+
*
718+
* @param string $file
719+
* @return $this
720+
*/
721+
public function loadEnvironmentFrom($file)
722+
{
723+
$this->environmentFile = $file;
724+
725+
return $this;
726+
}
727+
640728
/**
641729
* Dispatches the application request.
642730
*

0 commit comments

Comments
 (0)