A collection of various PHP container classes like JSON, File, etc.
composer require ixnode/php-containervendor/bin/php-container -Vphp-container 0.1.0 (12-19-2022 01:17:26) - Björn Hempel <bjoern@hempel.li>use Ixnode\PhpContainer\File;$exists = (new File('path-to-file'))->exist();true || false$fileSize = (new File('path-to-file'))->getFileSize();1523943$fileSizeHuman = (new File('path-to-file'))->getFileSizeHuman();1.45 MB$content = (new File('path-to-file'))->getContentAsText();line 1
line 2
line 3
...$content = (new File('path-to-json-file'))->getJson()->getJsonStringFormatted();{
"data": "Content of file 'path-to-json-file'."
}use Ixnode\PhpContainer\Json;$json = (new Json(['data' => 'json']))->getJsonStringFormatted();{
"data": "json"
}$array = (new Json('{"data": "json"}'))->getArray();[
'data' => 'json',
]$array = (new Json(new File('path-to-json-file')))->getArray();$json = (new Json([
'key1' => 'value1',
'key2' => [
'associative' => [
'name' => 'Test',
'id' => 123
],
'indexed' => [1, 2, 3],
],
'key3' => 'value3',
'key4' => 'value4',
'key5' => 'value5',
]));print $json->getKeyString(['key2', 'associative', 'name']);
// return value: (string) 'Test'print $json->getKeyInteger(['key2', 'indexed', 0]);
// return value: (int) 1print_r($json->getKeyArray(['key2', 'indexed']));
// return value: (array) [1, 2, 3]$array = (new Json('[{"key1": 111, "key2": "222"},{"key1": 333, "key2": "444"}]'))->buildArray(
[
/* path []['key1'] as area1 */
'area1' => [['key1']],
/* path []['key2'] as area2 */
'area2' => [['key2']],
]
);[
'area1' => [111, 333],
'area2' => ['222', '444'],
]use Ixnode\PhpContainer\Csv;$array = (new Csv(new File('path-to-csv-file')))->getArray();Content of "path-to-csv-file":
"headerLine1Cell1";"headerLine1Cell2"
"valueLine2Cell1";"valueLine2Cell2"
"valueLine3Cell1";"valueLine3Cell2"
Response:
[
[
'headerLine1Cell1' => 'valueLine2Cell1',
'headerLine1Cell2' => 'valueLine2Cell2',
],
[
'headerLine1Cell1' => 'valueLine3Cell1',
'headerLine1Cell2' => 'valueLine3Cell2',
],
...
]use Ixnode\PhpContainer\Curl;$text = (new Curl('URL')->getContentAsText();use Ixnode\PhpContainer\Image;$imageWidth = (new Image(new File('path-to-json-file')))->getWidth();$imageString = (new Image(new File('path-to-json-file')))->getImageString(1000, Image::FORMAT_JPG, 85);git clone git@github.com:ixnode/php-container.git && cd php-containercomposer installcomposer testThis tool is licensed under the MIT License - see the LICENSE file for details