{"id":22425197,"url":"https://github.com/2lenet/entityfilebundle","last_synced_at":"2025-08-01T08:32:51.696Z","repository":{"id":37805398,"uuid":"488498951","full_name":"2lenet/EntityFileBundle","owner":"2lenet","description":null,"archived":false,"fork":false,"pushed_at":"2024-09-27T13:46:23.000Z","size":290,"stargazers_count":3,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-12-02T06:35:57.774Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/2lenet.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}},"created_at":"2022-05-04T07:52:54.000Z","updated_at":"2024-11-16T14:50:18.000Z","dependencies_parsed_at":"2022-08-18T15:01:32.254Z","dependency_job_id":"a83ffc1c-7000-495a-be82-45c898ca349d","html_url":"https://github.com/2lenet/EntityFileBundle","commit_stats":{"total_commits":35,"total_committers":5,"mean_commits":7.0,"dds":"0.11428571428571432","last_synced_commit":"dc4a2331e508baf38531bf996f1a3de80e746dbf"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2lenet%2FEntityFileBundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2lenet%2FEntityFileBundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2lenet%2FEntityFileBundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2lenet%2FEntityFileBundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/2lenet","download_url":"https://codeload.github.com/2lenet/EntityFileBundle/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228356403,"owners_count":17907191,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":"2024-12-05T19:13:28.216Z","updated_at":"2025-08-01T08:32:51.684Z","avatar_url":"https://github.com/2lenet.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EntityFileBundle\n\nWith this bundle, you can attach files to entities.\n\n* [Installation](#installation)\n* [Configuration](#configuration)\n  * [Basic configuration](#basic-configuration)\n  * [Change the storage adapter](#change-the-storage-adapter)\n* [Usage](#usage)\n  * [Retrieve files](#retrieve-files)\n  * [Retrieve files from URL](#retrieve-files-from-url)\n  * [Access file contents](#access-file-contents)\n  * [Delete a file](#delete-a-file)\n  * [Rename or move a file](#rename-or-move-a-file)\n  * [Exception handling](#exception-handling)\n* [Crudit](#crudit)\n\n## Installation\n\n```\ncomposer require 2lenet/entity-file-bundle\n```\n\n## Configuration\n\nThis bundle works with configurations. A configuration = 1 entity 1 file system.\n\nFor example, you may have a configuration for the logo of multiple sellers, and a configuration for the pictures of the products they sell.\n\n### Basic configuration\n\nIn  `lle_entity_file.yaml`\n```yaml\nlle_entity_file:\n    configurations:\n        seller_logos:\n            class: \"App\\\\Entity\\\\Seller\"\n            storage_adapter: \"lle_entity_file.storage.default\"\n\n```\n\nThat's it! With the default storage adapter configuration, those files will be saved under data/seller_logos\n\n### Change the storage adapter\n\nThis bundle uses the [FlySystem Symfony Bundle](https://flysystem.thephpleague.com/docs/). You can create your own storage adapters, (Local disk, FTP, Drive...).\n\nFor that, you need to [configure a new adapter](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/B-configuration-reference.md). Then, change the `storage_adapter` of your configuration.\n\n## Usage\n\nFirst of all, you need to get the manager for your configuration. For that, use the `Lle\\EntityFileBundle\\Service\\EntityFileLoader`\n\n```php\n$manager = $entityFileLoader-\u003eget(\"seller_logos\");\n```\n\n### Create a file\n\n```php\n$manager = $entityFileLoader-\u003eget(\"seller_logos\");\n\n$entityFile = $manager-\u003esave($seller, $data, $path);\n\n$this-\u003eem-\u003epersist($entityFile);\n$this-\u003eem-\u003eflush();\n```\n\n$data may be a string, a Symfony File object (including UploadedFile) or a resource.\n\n\u003e :warning: **Never forget to persist and flush the EntityFile.**\n\n* I want my EntityFile to contain additional properties!\n\nYou can use your own Entity class, it needs to be a Doctrine entity that implements `Lle\\EntityFileBundle\\Entity\\EntityFileInterface`. For your convenience, the trait `LleEntityFileBundle\\Entity\\Trait\\EntityFileTrait` exists.\n\nYou will also have to update your configuration:\n```yaml\nunicorn:\n    # ...\n    entity_file_class: \"App\\\\Entity\\\\UnicornEntityFile\"\n```\n\n* I want to edit my new properties!\n\n```php\n$manager = $entityFileLoader-\u003eget(\"unicorn\");\n\n$entityFile = $manager-\u003esave($seller, $data, \"unicorn.png\");\n\n$entityFile-\u003esetDescription(\"Picture of a very sexy unicorn\");\n$this-\u003eem-\u003epersist($entityFile);\n$this-\u003eem-\u003eflush();\n```\n\n* I want to have a dynamic path in my file structure!\n\n```php\n$manager = $entityFileLoader-\u003eget(\"seller_logos\");\n\n$manager-\u003esave($order, $data, \"you/can/do/this\");\n\n// example:\n\n$dir = $order-\u003egetDate()-\u003eformat(\"Y-m\");\n$name = $order-\u003egetId() . \".xml\";\n\n$manager-\u003esave($order, $data, $dir . \"/\" . $name)\n```\n\n* For some reason, I want to save my files somewhere else than data\n\nCreate your own storage adapter in `flysystem.yaml`, which is basically a copy of the default one with different directory option.\n```yaml\nflysystem:\n    storages:\n        unicorn.storage:\n            adapter: \"local\"\n            options:\n                directory: \"%kernel.project_dir%/unicorns\"\n                permissions:\n                    file:\n                        public: 511\n                        private: 511\n                    dir:\n                        public: 511\n                        private: 511\n```\n\n### Retrieve files\n\n```php\n$manager = $entityFileLoader-\u003eget(\"seller_logos\");\n\n$manager-\u003eget($seller);\n$manager-\u003egetOne($seller);\n```\n\n### Retrieve files from URL\n\nIf you didn't use Symfony Flex, you need to add the routes in routes.yaml:\n```yaml\nlle_entity_file:\n    resource: \"@LleEntityFileBundle/Resources/config/routes.yaml\"\n```\n\nTwo routes are available:\n\n* lle_entityfile_entityfile_read (requires configName and id)  \nExample: /lle-entity-file/seller_logos/1\n* lle_entityfile_entityfile_readbypath (requires configName and path)  \n  Example: /lle-entity-file/seller_logos?path=2le.png\n\n#### Protect your urls\nBy default, only logged in users can access those urls. You can change the `role` key in the configuration:\n```yaml\noperation_reports:\n    # ...\n    role: \"ROLE_OPERATOR\"\n```\n\n* I want the files to be public !\n\nYou can use \"PUBLIC_ACCESS\" in the `role` key.\n\n* I want to do something more complex !\n\n[Create a custom voter.](https://symfony.com/doc/current/security/voters.html)\n\n#### Change content disposition (Show in browser or automatically download)\nBy default, files are served inline. You can change the disposition key under your configuration:\n```yaml\nzip_reports:\n    # ...\n    disposition: \"attachment\"\n```\n\n### Access file contents\n\n```php\n$manager = $entityFileLoader-\u003eget(\"seller_logos\");\n\n$manager-\u003eread($file);\n$manager-\u003ereadStream($file);\n```\n\n### Delete a file\n```php\n$manager = $entityFileLoader-\u003eget(\"seller_logos\");\n\n// deletes the entity and the actual file\n$manager-\u003edelete($file);\n```\n\n### Rename or move a file\n```php\n$manager = $entityFileLoader-\u003eget(\"seller_logos\");\n\n$manager-\u003emove($file, \"actually_not_an_unicorn.png\");\n$this-\u003eem-\u003eflush();\n```\n\n\u003e :warning: **Never forget to flush the EntityFile.**\n\n### Exception handling\n\nhttps://flysystem.thephpleague.com/docs/usage/exception-handling/\n\n## Crudit\n\nThis bundle is compatible with 2LE's Crudit bundle.\n\nYou can use the EntityFileBrick, for example in tabs:\n\n```php\n  public function getTabs(): array\n  {\n      return [\n          \"tab.files\" =\u003e EntityFileBrickConfig::new(\"seller_logos\"),\n      ];\n  }\n```\n\nIt features a dropzone where you can see, add, remove and download files.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2lenet%2Fentityfilebundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F2lenet%2Fentityfilebundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2lenet%2Fentityfilebundle/lists"}