{"id":23514679,"url":"https://github.com/padawansoftware/uploaderbundle","last_synced_at":"2026-04-30T14:33:02.538Z","repository":{"id":57035023,"uuid":"222427920","full_name":"padawansoftware/UploaderBundle","owner":"padawansoftware","description":"A library to manage file upload in symfony","archived":false,"fork":false,"pushed_at":"2019-11-19T12:28:20.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-16T21:43:13.817Z","etag":null,"topics":["file","symfony","upload","vichuploaderbundle"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":false,"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/padawansoftware.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}},"created_at":"2019-11-18T10:58:42.000Z","updated_at":"2020-01-19T11:29:03.000Z","dependencies_parsed_at":"2022-08-23T20:50:43.532Z","dependency_job_id":null,"html_url":"https://github.com/padawansoftware/UploaderBundle","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/padawansoftware%2FUploaderBundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/padawansoftware%2FUploaderBundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/padawansoftware%2FUploaderBundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/padawansoftware%2FUploaderBundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/padawansoftware","download_url":"https://codeload.github.com/padawansoftware/UploaderBundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254029009,"owners_count":22002284,"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":["file","symfony","upload","vichuploaderbundle"],"created_at":"2024-12-25T14:09:54.714Z","updated_at":"2026-04-30T14:33:02.494Z","avatar_url":"https://github.com/padawansoftware.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# UploaderBundle\n\nUploaderBundle is a wrapper for [VichUploaderBundle](https://github.com/dustin10/VichUploaderBundle).\n\nThis bundle adds facilities for managing assets upload by providing a base Asset entity class and a set of tools for managing it.\n\n## Configure VichUploaderBundle\n\nAs this bundle is just a wrapper for VichUploaderBundle, you must [configure](https://github.com/dustin10/VichUploaderBundle/blob/master/Resources/doc/index.md) it first.\n\nIt is required that the configuration has a mapping named `asset`, that will be used for our `Asset` entity:\n\n```yml\n# config/packages/vich_uploader.yaml or app/config/config.yml\nvich_uploader:\n    db_driver: orm\n\n    mappings:\n        asset: # it is important that one mapping has name asset\n            uri_prefix: /media\n            upload_destination: '%kernel.project_dir%/public/media'\n```\n\n## Entity as standalone class\n\nIf you're planning to use your Entity class as standalone class and not associated to another entity, isenought to create a class that extends from bundle Asset\n\n\n```php\nuse Doctrine\\ORM\\Mapping as ORM;\nuse PSUploaderBundle\\Entity\\Asset as BaseAsset;\n\n/**\n * @ORM\\Entity\n */\nclass Asset extends BaseAsset {\n}\n```\n\nThat's all you need. Now when you create/update your database schema, a new class will be created:\n```\n+------------------+--------------+------+-----+---------+----------------+\n| Field            | Type         | Null | Key | Default | Extra          |\n+------------------+--------------+------+-----+---------+----------------+\n| asset_id         | int(11)      | NO   | PRI | NULL    | auto_increment |\n| asset_name       | varchar(255) | NO   |     | NULL    |                |\n| asset_updated_at | date         | NO   |     | NULL    |                |\n+------------------+--------------+------+-----+---------+----------------+\n```\n\n## Use Asset with associated entity\n\nIt is common that `Asset` entity is related to another entities. For example, a Post in a blog may have a related image as header, or a Tutorial can have a file as download. Thus, this bundle has facilities to manage the association.\n\nFor associate Asset with another entity, add Doctrine ORM association in the entity class.\n\n```php\nuse Doctrine\\ORM\\Mapping as ORM;\n\nclass Post\n{\n    /**\n     * @var Asset\n     *\n     * @ORM\\OneToOne(targetEntity=\"Asset\")\n     * @ORM\\JoinColumn(name=\"post_image\", referencedColumnName=\"asset_id\")\n     */\n    protected $image;\n}\n```\n\nNow you can fetch our assets from the associated entity.\n\nWhen associating entities with Asset it may happend that you only associate with one entity or you can associate with multiple entities.\n\n### Association with one entity\n\nIf you're association Asset with only one Entity, you can also add association in the Asset side:\n\n```php\nuse Doctrine\\ORM\\Mapping as ORM;\nuse PSUploaderBundle\\Entity\\Asset as BaseAsset;\n\n/**\n * @ORM\\Entity\n */\nclass Asset extends BaseAsset {\n\n    /**\n     * @var mixed\n     *\n     * The post this asset it attached to\n     *\n     * @ORM\\OneToOne(targetEntity=\"Post\", mappedBy=\"asset\")\n     */\n    protected $post;\n}\n```\n\nYou also need to make a change in the associated entity:\n\n```php\nuse Doctrine\\ORM\\Mapping as ORM;\n\nclass Post\n{\n    /**\n     * @var Asset\n     *\n     * @ORM\\OneToOne(targetEntity=\"Asset\", inversedBy=\"post\")\n     * @ORM\\JoinColumn(name=\"post_image\", referencedColumnName=\"asset_id\")\n     */\n    protected $image;\n}\n```\n\n\nThis way, you can also fetch associated entity from the `Asset` entity.\n\n\n### Association with more than one entity\n\nAs we've comment before, if you're planning to associate Asset entity with more than one entity, you can't add association in the Asset entity as you would have to specify the `targetEntity`. This does not meen you cant fetch associated entity from the `Asset` entity. Fortunately this bundle has the solution:\n\nFirst, your `Asset` class must implement `PSUploaderBundle\\Library\\Interfaces\\EntityAssetInterface` and the two methods defined:\n\n```php\nuse Doctrine\\ORM\\Mapping as ORM;\nuse PSUploaderBundle\\Entity\\Asset as BaseAsset;\nuse PSUploaderBundle\\Library\\Interfaces\\EntityAssetInterface;\n\n/**\n * @ORM\\Entity\n */\nclass Asset extends BaseAsset implements EntityAssetInterface\n{\n    /**\n     * @var mixed\n     *\n     * The entity this asset it attached to\n     */\n    protected $entity;\n\n\n    /**\n     * @return mixed\n     */\n    public function getEntity()\n    {\n        return $this-\u003eentity;\n    }\n\n    /**\n     * @param mixed $entity\n     *\n     * @return self\n     */\n    public function setEntity($entity)\n    {\n        $this-\u003eentity = $entity;\n\n        return $this;\n    }\n}\n```\n\nThen in your associated entities, you have to annotate with field holds the `Asset`:\n\n```php\nuse Doctrine\\ORM\\Mapping as ORM;\nuse PSUploaderBundle\\Library\\Annotation\\Asset as AssetAnnotation;\n\n/**\n * @AssetAnnotation(\"image\")\n **/\nclass Post\n{\n    /**\n     * @var Asset\n     *\n     * @ORM\\OneToOne(targetEntity=\"Asset\")\n     * @ORM\\JoinColumn(name=\"post_image\", referencedColumnName=\"asset_id\")\n     */\n    protected $image;\n}\n```\n\nFinally, you've to register `PSUploaderBundle\\EventListener\\InjectEntityListener` as a service:\n\n```yml\n    PSUploaderBundle\\EventListener\\InjectEntityListener:\n        tags:\n            - { name: doctrine.event_subscriber }\n```\n\nWich this `InjectEntityListener` does is listen when an entity is fetched from database and, if that entity has an associated `Asset`, injects the entity into the `Asset`.\n\n\n### Add validation for image Asset\n\nYou may want to add an `Image` validation constraint for the `Asset`. Constraints must be set on the final field, so trying to add them in the `Asset` field of the associated entity won't work as it is not the real file:\n\n```php\nuse Doctrine\\ORM\\Mapping as ORM;\nuse PSUploaderBundle\\Library\\Annotation\\Asset as AssetAnnotation;\nuse Symfony\\Component\\Validator\\Constraints as Assert;\n\n/**\n * @AssetAnnotation(\"image\")\n **/\nclass Post\n{\n    /**\n     * @var Asset\n     *\n     * @ORM\\OneToOne(targetEntity=\"Asset\")\n     * @ORM\\JoinColumn(name=\"post_image\", referencedColumnName=\"asset_id\")\n     *\n     * Assert image and 23/9 aspect ratio\n     * @Assert\\Image (\n     *  minRatio = 2.55,\n     *  maxRatio = 2.56\n     * )\n     */\n    protected $image;\n}\n```\n\nFortunately, this bundle comes with a custom `Image` constraint for solving that:\n\n```php\nuse Doctrine\\ORM\\Mapping as ORM;\nuse PSUploaderBundle\\Library\\Annotation\\Asset as AssetAnnotation;\nuse PSUploaderBundle\\Library\\Validation\\ImageAsset as ImageAssetConstraint;\n\n/**\n * @AssetAnnotation(\"image\")\n **/\nclass Post\n{\n    /**\n     * @var Asset\n     *\n     * @ORM\\OneToOne(targetEntity=\"Asset\")\n     * @ORM\\JoinColumn(name=\"post_image\", referencedColumnName=\"asset_id\")\n     *\n     * Assert image and 23/9 aspect ratio\n     * @ImageAssetConstraint (\n     *  minRatio = 2.55,\n     *  maxRatio = 2.56\n     * )\n     */\n    protected $image;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpadawansoftware%2Fuploaderbundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpadawansoftware%2Fuploaderbundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpadawansoftware%2Fuploaderbundle/lists"}