{"id":18929538,"url":"https://github.com/thecodingmachine/yaml-definition-loader","last_synced_at":"2026-03-16T14:30:18.762Z","repository":{"id":57067892,"uuid":"46947839","full_name":"thecodingmachine/yaml-definition-loader","owner":"thecodingmachine","description":"Provides a loader that can convert YAML files to container definitions compatible with the definition-interop standard.","archived":false,"fork":false,"pushed_at":"2015-12-15T09:58:55.000Z","size":26,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":8,"default_branch":"1.0","last_synced_at":"2025-02-16T12:30:31.480Z","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/thecodingmachine.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":"2015-11-26T21:40:04.000Z","updated_at":"2015-11-26T21:45:44.000Z","dependencies_parsed_at":"2022-08-24T10:20:15.321Z","dependency_job_id":null,"html_url":"https://github.com/thecodingmachine/yaml-definition-loader","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Fyaml-definition-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Fyaml-definition-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Fyaml-definition-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Fyaml-definition-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thecodingmachine","download_url":"https://codeload.github.com/thecodingmachine/yaml-definition-loader/tar.gz/refs/heads/1.0","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239927825,"owners_count":19719835,"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-11-08T11:33:26.547Z","updated_at":"2026-03-16T14:30:18.729Z","avatar_url":"https://github.com/thecodingmachine.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/thecodingmachine/yaml-definition-loader/badges/quality-score.png?b=1.0)](https://scrutinizer-ci.com/g/thecodingmachine/yaml-definition-loader/?branch=1.0)\n[![Build Status](https://travis-ci.org/thecodingmachine/yaml-definition-loader.svg?branch=1.0)](https://travis-ci.org/thecodingmachine/yaml-definition-loader)\n[![Coverage Status](https://coveralls.io/repos/thecodingmachine/yaml-definition-loader/badge.svg?branch=1.0\u0026service=github)](https://coveralls.io/github/thecodingmachine/yaml-definition-loader?branch=1.0)\n\n# YAML Definition Loader for *definition-interop*\n\nThis package contains a **loader** that can convert YAML files to container definitions compatible with the \n*definition-interop* standard.\n\nIn order to keep things simple for newcomers, the supported YAML file is a subset of Symfony services YML file format.\n\n## Installation\n\nYou can install this package through Composer:\n\n```json\n{\n    \"require\": {\n        \"thecodingmachine/yaml-definition-loader\": \"~1.0\"\n    }\n}\n```\n\nThe packages adheres to the [SemVer](http://semver.org/) specification, and there will be full backward compatibility\nbetween minor versions.\n\n## Automatic discovery\n\nIf you want YAML files of your package to be automatically discoverable (using Puli), you should bind your YAML files\nto the \"definition-interop/yaml-definition-files\" binding type.\n\nLets assume that your service file is in \"services/my_service.yml\".\n\nIn your package, simply type: \n\n```bash\n# This maps the virtual Puli path \"/my_vendor/my_package\" to the \"services\" directory. \npuli map /my_vendor/my_package services\n\n# Binds all YML files in the directory services/*.yml (please note how the directory is a virtual Puli directory).\npuli bind /my_vendor/my_package/*.yml definition-interop/yaml-definition-files\n```\n\nBinded YML files can be discovered automatically if consumers use Puli for Discovery.\n\n## Usage\n\nThis package contains a `YamlDefinitionLoader` class. The goal of this class is to take a YAML file and generate\na number of \"entry definitions\" (as defined in [*definition-interop*](https://github.com/container-interop/definition-interop/)).\n\nThese definitions can then be turned into a dependency injection container using the appropriate tools (like [Yaco](https://github.com/thecodingmachine/yaco)). \n\n\n```php\nuse TheCodingMachine\\Definition\\YamlDefinitionLoader;\n\n$servicesProvider = new YamlDefinitionLoader(\"my-services.yml\");\n\n$definitions = $servicesProvider-\u003egetDefinitions();\n```\n\nNote: the `YamlDefinitionLoader` implements the `Interop\\Container\\Definition\\DefinitionProviderInterface`.\n\n## File format\n\n### Declare parameters\n\n```yaml\nparameters:\n    foo: bar\n```\n\n### Declare an instance\n\n```yaml\nservices:\n    my_service:\n        class: My\\ClassName\n        arguments: [ foo, bar ]\n```\n\nThis will declare a \"my_service\" service, from class `My\\ClassName`, passing to the constructor the strings \"foo\" and \"bar\".\n\n### Reference an instance\n\n```yaml\nservices:\n    my_reference:\n        class: My\\ReferencedClass\n    my_service:\n        class: My\\ClassName\n        arguments: [ \"@my_reference\" ]\n```\n\nThe `my_reference` service will be passed in parameter to the constructor of the `my_service` service.\nTo reference a service, use the `@` prefix. If you want a string starting with a `@`, you should double it. For instance:\n\n- `@service`\n- `@@some text starting with @`\n\n### Call a method of a service\n\n```yaml\nservices:\n    my_service:\n        class: My\\ClassName\n        calls:\n            - [ setLogger, [ '@logger' ] ]\n```\n\nYou can call methods of a service after generating it. For instance, you could call setters.\nYou need to create a `calls` attribute and pass it a list of methods to be called. The first item is the method name\nand the second item is a list of parameters to pass to that method.\n\n### Set a public property of a service\n\n```yaml\nservices:\n    my_service:\n        class: My\\ClassName\n        properties:\n            foo: bar\n            bar: \"@baz\"\n```\n\nUse the `properties` key to set a public property in a service.\n\n### Aliases\n\n```yaml\nservices:\n    my_service:\n        class: My\\ClassName\n    my_alias:\n        alias: my_service\n```\n\nYou can build services alias using the `alias` attribute.\n\nAlternatively, you can also use this syntax:\n\n```yaml\nservices:\n    my_alias: \"@my_service\"\n```\n\n### Factories\n\nYou can use factory methods of other services or classes to build your services.\n\n**Static factories**\n\n```yaml\nservices:\n    my_service:\n        factory: My\\ClassName::myMethod\n```\n\nThe `my_service` instance will be returned from a call to `My\\ClassName::myMethod`. You can even pass parameters to this\nmethod using the `arguments` attribute:\n\n```yaml\nservices:\n    my_service:\n        factory: My\\ClassName::myMethod\n        attributes: [ '@logger', 42 ] \n```\n\nYou can also use this alternative syntax:\n\n```yaml\nservices:\n    my_service:\n        factory: [ 'My\\ClassName', 'myMethod' ]\n```\n\n**Service based factories**\n\n```yaml\nservices:\n    factory:\n        class: My\\Factory\n    my_service:\n        factory: factory:myMethod\n```\n\nThe `my_service` instance will be returned from a call to `myMethod` on the service named `factory`. Notice how we used\na single ':' instead of a double '::'.\n\nYou can also use this alternative syntax:\n\n```yaml\nservices:\n    factory:\n        class: My\\Factory\n    my_service:\n        factory: 'My\\ClassName@myMethod'\n```\n\n\n## Noticeable differences with Symfony YAML services format\n\n- The keys are case sensitive\n- Parameters do not accept references (no \"@service\" reference in the \"parameters\" section). They can only be scalars.\n- These features are not supported:\n    - tags\n    - public/private services\n    - shared services\n    - synthetic services\n    - lazy services\n    - abstract services\n    - file based services\n    - deprecated services\n    - decorated services\n    - autowired services\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthecodingmachine%2Fyaml-definition-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthecodingmachine%2Fyaml-definition-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthecodingmachine%2Fyaml-definition-loader/lists"}