{"id":37001653,"url":"https://github.com/jaxon-php/jaxon-storage","last_synced_at":"2026-01-14T00:23:23.843Z","repository":{"id":327420208,"uuid":"1109084794","full_name":"jaxon-php/jaxon-storage","owner":"jaxon-php","description":"File storage for the Jaxon library","archived":false,"fork":false,"pushed_at":"2025-12-18T23:42:59.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-12-21T23:06:04.118Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jaxon-php.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-12-03T10:11:43.000Z","updated_at":"2025-12-18T23:43:02.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/jaxon-php/jaxon-storage","commit_stats":null,"previous_names":["jaxon-php/jaxon-storage"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/jaxon-php/jaxon-storage","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaxon-php%2Fjaxon-storage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaxon-php%2Fjaxon-storage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaxon-php%2Fjaxon-storage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaxon-php%2Fjaxon-storage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jaxon-php","download_url":"https://codeload.github.com/jaxon-php/jaxon-storage/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaxon-php%2Fjaxon-storage/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28406482,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T21:51:37.118Z","status":"ssl_error","status_checked_at":"2026-01-13T21:45:14.585Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-14T00:23:23.381Z","updated_at":"2026-01-14T00:23:23.834Z","avatar_url":"https://github.com/jaxon-php.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://github.com/jaxon-php/jaxon-storage/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/jaxon-php/jaxon-storage/actions)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/jaxon-php/jaxon-storage/badges/quality-score.png?b=main)](https://scrutinizer-ci.com/g/jaxon-php/jaxon-storage/?branch=main)\n[![StyleCI](https://styleci.io/repos/1109084794/shield?branch=main)](https://styleci.io/repos/1109084794)\n[![codecov](https://codecov.io/gh/jaxon-php/jaxon-storage/graph/badge.svg?token=OFyT9WzVxt)](https://codecov.io/gh/jaxon-php/jaxon-storage)\n\n[![Latest Stable Version](https://poser.pugx.org/jaxon-php/jaxon-storage/v/stable)](https://packagist.org/packages/jaxon-php/jaxon-storage)\n[![Total Downloads](https://poser.pugx.org/jaxon-php/jaxon-storage/downloads)](https://packagist.org/packages/jaxon-php/jaxon-storage)\n[![Latest Unstable Version](https://poser.pugx.org/jaxon-php/jaxon-storage/v/unstable)](https://packagist.org/packages/jaxon-php/jaxon-storage)\n[![License](https://poser.pugx.org/jaxon-php/jaxon-storage/license)](https://packagist.org/packages/jaxon-php/jaxon-storage)\n\nFile storage for the Jaxon library\n=================================\n\nThis package provides a tiny wrapper for file storage for the Jaxon library using the [PHP League Flysystem](https://flysystem.thephpleague.com) library.\n\n## Features\n\nThe library features are provided in the `Jaxon\\Storage\\StorageManager` class, which implements three functions.\n\n#### The global function\n\nStarting from version 1.1.0, a global function is available to get the instance of the storage manager.\n\n```php\nuse function Jaxon\\Storage\\storage;\n```\n\nThis function will get the instance from the DI container if the Jaxon Core library is available, or else it will create its own instance of the `Jaxon\\Storage\\StorageManager` class.\n\n#### Register an adapter\n\nThis function registers an adapter from the [Flysystem](https://flysystem.thephpleague.com) library.\n\n```php\n    /**\n     * @param string $sAdapter\n     * @param Closure $cFactory\n     *\n     * @return void\n     */\n    public function register(string $sAdapter, Closure $cFactory)\n```\n\nThe first parameter is the adapter id, and the second is a closure which takes a root dir and an optional array of options as parameters, and returns a `League\\Flysystem\\FilesystemAdapter` object configured for file input and output at a given location.\n\nBy default, the library registers an adapter for the local filesystem.\n\n```php\nuse League\\Flysystem\\Local\\LocalFilesystemAdapter;\nuse function Jaxon\\Storage\\storage;\n\n// Local file system adapter\nstorage()-\u003eregister('local', function(string $sRootDir, array $aOptions) {\n    return new LocalFilesystemAdapter($sRootDir, ...$aOptions);\n});\n```\n\nAn adapter can be registered as an alias of an already registered one.\nThis is useful for example for using the same adapter with different options.\n\n```php\nuse function Jaxon\\Storage\\storage;\n\n// The \"uploads\" adapter is an alias of the local file system adapter\nstorage()-\u003eregister('uploads', 'local');\n```\n\n#### Create a file input/output object\n\nA [Flysystem](https://flysystem.thephpleague.com) object for file input and output is created by chaining the `adapter()` and `make()` functions.\n\n```php\nuse function Jaxon\\Storage\\storage;\n\n$storage = storage()\n    -\u003eadapter('local')\n    -\u003emake('/var/www/storage/uploads');\n$storage-\u003ewrite('uploaded-file.txt', $uploadedContent)\n```\n\nThe `adapter()` function takes the id of a registered adapter as parameter, while the `make()` function takes the path to the root dir.\n\nThe code snippet below writes the given content in the `/var/www/storage/uploads/uploaded-file.txt` file.\n\nThe adapter and directory options can be passed to the `adapter()` and `make()` functions.\nThe adapter options are set on the adapter object (e.g `LocalFilesystemAdapter`), while the directory options are set on the returned `Filesystem` object. Their values are then described in their respective documentations.\n\n```php\nuse function Jaxon\\Storage\\storage;\n\n$aAdapterOptions = [\n    'lazyRootCreation' =\u003e true,\n];\n$aDirOptions = [\n    'config' =\u003e [\n        'public_url' =\u003e '/uploads',\n    ],\n];\n$storage = storage()\n    -\u003eadapter('local', $aAdapterOptions)\n    -\u003emake('/var/www/storage/uploads', $aDirOptions);\n$storage-\u003ewrite('uploaded-file.txt', $uploadedContent)\n```\n\n#### Create a file input/output object from the Jaxon config\n\nThis function creates a [Flysystem](https://flysystem.thephpleague.com) object for file input and output, with options from the  `app.storage.$sOptionName.adapter`, `app.storage.$sOptionName.dir` and `app.storage.$sOptionName.options` entries of the Jaxon library config.\n\n```php\nuse League\\Flysystem\\Filesystem;\n\n    /**\n     * @param string $sOptionName\n     *\n     * @return Filesystem\n     * @throws RequestException\n     */\n    public function get(string $sOptionName): Filesystem\n```\n\nWith this config,\n\n```php\nreturn [\n    'app' =\u003e [\n        'storage' =\u003e [\n            'adapters' =\u003e [\n                // Adapters options\n                'local' =\u003e [], // Optional\n            ]\n            'stores' =\u003e [\n                'uploads' =\u003e [\n                    'adapter' =\u003e 'local',\n                    'dir' =\u003e '/var/www/storage/uploads',\n                    // 'options' =\u003e [], // Optional\n                ],\n            ],\n        ],\n    ],\n];\n```\n\nThe code snippet below writes the given content in the `/var/www/storage/uploads/uploaded-file.txt` file, as in the previous example.\n\n```php\nuse function Jaxon\\Storage\\storage;\n\n$storage = storage()-\u003eget('uploads');\n$storage-\u003ewrite('uploaded-file.txt', $uploadedContent)\n```\n\nEach adapter can also be defined as an alias of an already defined adapter.\n\n```php\nreturn [\n    'app' =\u003e [\n        'storage' =\u003e [\n            'adapters' =\u003e [\n                // Adapters options\n                'uploads' =\u003e [\n                    'alias' =\u003e 'local',\n                    'options' =\u003e [], // Local adapter options for the uploads\n                ],\n                'exports' =\u003e [\n                    'alias' =\u003e 'local',\n                    'options' =\u003e [], // Local adapter options for the exports\n                ],\n            ]\n        ],\n        'stores' =\u003e [],\n    ],\n];\n```\n\n## Using without the Jaxon library\n\nStarting from version 1.1.0, the Jaxon Storage classes do not depend on the Jaxon Core classes anymore.\nAs a consequence, some features will not be automatically available, and will need an extra setup.\n\n#### The locale for translations\n\nWithout the Jaxon Core library, the Jaxon Storage will create its own instance of the `Jaxon\\Utils\\Translation\\Translator` class, which will then need to be set.\n\n```php\nuse function Jaxon\\Storage\\storage;\n\n// Set the translation locle to french.\nstorage()-\u003etranslator()-\u003esetLocale('fr');\n```\n\n#### The storage config options\n\nWithout the Jaxon Core library, a call to the `storage()-\u003eget()` function will throw an exception due to missing config options.\nThe library then needs to be provided with a closure which returns a `Jaxon\\Config\\Config` object populated with the config options.\n\n```php\nuse Jaxon\\Config\\Config;\nuse Jaxon\\Config\\ConfigSetter;\nuse function Jaxon\\Storage\\storage;\n\n// Provide the config setter\nstorage()-\u003esetConfigGetter(function(): Config {\n    $setter = new ConfigSetter();\n    return $setter-\u003enewConfig([\n        'adapters' =\u003e [\n            // Adapters options\n            'local' =\u003e [], // Optional\n        ],\n        'stores' =\u003e [\n            'uploads' =\u003e [\n                'adapter' =\u003e 'local',\n                'dir' =\u003e '/var/www/storage/uploads',\n                // 'options' =\u003e [], // Optional\n            ],\n        ],\n    ]);\n});\n\n// Usage\n$storage = storage()-\u003eget('uploads');\n$storage-\u003ewrite('uploaded-file.txt', $uploadedContent)\n```\n\n## Register additional adapters\n\nThe [Flysystem](https://flysystem.thephpleague.com) library provides adapters for many other filesystems, which can be registered with this library.\n\nThey are provided in separate packages, which need to be installed first.\n\n#### AWS S3 file system adapter\n\n```php\nuse Aws\\S3\\S3Client;\nuse League\\Flysystem\\AwsS3V3\\AwsS3V3Adapter;\nuse function Jaxon\\Storage\\storage;\n\nstorage()-\u003eregister('aws-s3', function(string $sRootDir, array $aOptions) {\n    $client = new S3Client($aOptions['client'] ?? []);\n    return new AwsS3V3Adapter($client, $aOptions['bucket'] ?? '', $sRootDir);\n});\n```\n\n#### Async AWS S3 file system adapter\n\n```php\nuse AsyncAws\\S3\\S3Client;\nuse League\\Flysystem\\AsyncAwsS3\\AsyncAwsS3Adapter;\nuse function Jaxon\\Storage\\storage;\n\nstorage()-\u003eregister('async-aws-s3', function(string $sRootDir, array $aOptions) {\n    $client = isset($aOptions['client']) ? new S3Client($aOptions['client']) : new S3Client();\n    return new AsyncAwsS3Adapter($client, $aOptions['bucket'] ?? '', $sRootDir);\n});\n```\n\n#### Google Cloud file system adapter\n\n```php\nuse Google\\Cloud\\Storage\\StorageClient;\nuse League\\Flysystem\\AzureBlobStorage\\GoogleCloudStorageAdapter;\nuse function Jaxon\\Storage\\storage;\n\nstorage()-\u003eregister('google-cloud', function(string $sRootDir, array $aOptions) {\n    $storageClient = new StorageClient($aOptions['client'] ?? []);\n    $bucket = $storageClient-\u003ebucket($aOptions['bucket'] ?? '');\n    return new GoogleCloudStorageAdapter($bucket, $sRootDir);\n});\n```\n\n#### Microsoft Azure file system adapter\n\n```php\nuse League\\Flysystem\\AzureBlobStorage\\AzureBlobStorageAdapter;\nuse MicrosoftAzure\\Storage\\Blob\\BlobRestProxy;\nuse function Jaxon\\Storage\\storage;\n\nstorage()-\u003eregister('azure-blob', function(string $sRootDir, array $aOptions) {\n    $client = BlobRestProxy::createBlobService($aOptions['dsn']);\n    return new AzureBlobStorageAdapter($client, $aOptions['container'], $sRootDir);\n});\n```\n\n#### FTP file system adapter\n\n```php\nuse League\\Flysystem\\Ftp\\FtpAdapter;\nuse League\\Flysystem\\Ftp\\FtpConnectionOptions;\nuse function Jaxon\\Storage\\storage;\n\nstorage()-\u003eregister('ftp', function(string $sRootDir, array $aOptions) {\n    $aOptions['root'] = $sRootDir;\n    $xOptions = FtpConnectionOptions::fromArray($aOptions);\n    return new FtpAdapter($xOptions);\n});\n```\n\n#### SFTP V2 file system adapter\n\n```php\nuse League\\Flysystem\\PhpseclibV2\\SftpAdapter;\nuse League\\Flysystem\\PhpseclibV2\\SftpConnectionProvider;\nuse function Jaxon\\Storage\\storage;\n\nstorage()-\u003eregister('sftp-v2', function(string $sRootDir, array $aOptions) {\n    $provider = new SftpConnectionProvider(...$aOptions);\n    return new SftpAdapter($provider, $sRootDir);\n});\n```\n\n#### SFTP V3 file system adapter\n\n```php\nuse League\\Flysystem\\PhpseclibV3\\SftpAdapter;\nuse League\\Flysystem\\PhpseclibV3\\SftpConnectionProvider;\nuse function Jaxon\\Storage\\storage;\n\nstorage()-\u003eregister('sftp-v3', function(string $sRootDir, array $aOptions) {\n    $provider = new SftpConnectionProvider(...$aOptions);\n    return new SftpAdapter($provider, $sRootDir);\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaxon-php%2Fjaxon-storage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaxon-php%2Fjaxon-storage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaxon-php%2Fjaxon-storage/lists"}