-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New
file
function to get file contents in configuration
- Loading branch information
Showing
7 changed files
with
102 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
/* | ||
* This file is part of Berlioz framework. | ||
* | ||
* @license https://opensource.org/licenses/MIT MIT License | ||
* @copyright 2021 Ronan GIRON | ||
* @author Ronan GIRON <https://github.com/ElGigi> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code, to the root. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Berlioz\Config\ConfigFunction; | ||
|
||
use LogicException; | ||
|
||
/** | ||
* Class FileFunction. | ||
*/ | ||
class FileFunction implements ConfigFunctionInterface | ||
{ | ||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getName(): string | ||
{ | ||
return 'file'; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function execute(string $str): array|string | ||
{ | ||
$contents = @file_get_contents($str); | ||
|
||
if (false === $contents) { | ||
throw new LogicException(sprintf('File "%s" does not exists in configuration', $str)); | ||
} | ||
|
||
return $contents; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
/* | ||
* This file is part of Berlioz framework. | ||
* | ||
* @license https://opensource.org/licenses/MIT MIT License | ||
* @copyright 2021 Ronan GIRON | ||
* @author Ronan GIRON <https://github.com/ElGigi> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code, to the root. | ||
*/ | ||
|
||
namespace Berlioz\Config\Tests\ConfigFunction; | ||
|
||
use Berlioz\Config\ConfigFunction\EnvFunction; | ||
use Berlioz\Config\ConfigFunction\FileFunction; | ||
use LogicException; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class FileFunctionTest extends TestCase | ||
{ | ||
public function testGetName() | ||
{ | ||
$function = new FileFunction(); | ||
|
||
$this->assertEquals('file', $function->getName()); | ||
} | ||
|
||
public function testExecute() | ||
{ | ||
$function = new FileFunction(); | ||
|
||
$this->assertEquals('FOO', $function->execute(__DIR__ . '/file')); | ||
} | ||
|
||
public function testExecuteFailed() | ||
{ | ||
$this->expectException(LogicException::class); | ||
|
||
$function = new FileFunction(); | ||
$function->execute('file_unknown'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
FOO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters