{"id":15525581,"url":"https://github.com/coderabbi/virtuoso","last_synced_at":"2025-04-16T05:48:35.676Z","repository":{"id":18219350,"uuid":"21357813","full_name":"coderabbi/virtuoso","owner":"coderabbi","description":"Laravel Composable View Composers Package - Compose View Composers from Component Composers","archived":false,"fork":false,"pushed_at":"2017-06-28T03:34:04.000Z","size":14,"stargazers_count":66,"open_issues_count":0,"forks_count":2,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-29T05:03:56.646Z","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/coderabbi.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":"2014-06-30T16:22:28.000Z","updated_at":"2023-10-22T09:58:57.000Z","dependencies_parsed_at":"2022-07-31T11:47:56.746Z","dependency_job_id":null,"html_url":"https://github.com/coderabbi/virtuoso","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/coderabbi%2Fvirtuoso","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderabbi%2Fvirtuoso/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderabbi%2Fvirtuoso/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderabbi%2Fvirtuoso/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coderabbi","download_url":"https://codeload.github.com/coderabbi/virtuoso/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249204658,"owners_count":21229778,"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-10-02T10:58:47.507Z","updated_at":"2025-04-16T05:48:35.652Z","avatar_url":"https://github.com/coderabbi.png","language":"PHP","funding_links":[],"categories":["Packages"],"sub_categories":["Helpers/General"],"readme":"![image](https://dl.dropboxusercontent.com/s/em253abjckwr6k4/Virtuoso.png)\n\n# Laravel Virtuoso\n\n#### Laravel Composable View Composers Package\n\nIncrease flexibility and reduce code duplication by easily composing complex View Composers from simple \ncomponent Composers without unnecessary indirection or boilerplate code.\n\n## Background\n\nIn many of our projects, the same data is often repeated on multiple pages. This presents the challenge \nof preparing this data in our Controllers and providing it to our various Views without an undue amount \nof code repetition. Laravel provides us with the ability to limit this potential repetition through an \nabstraction known as the View Composer. A View Composer allows you to abstract this code to a single \nlocation and make it available to multiple Views. A View Composer is simply a piece of code which is \nbound to a View and executed whenever that View is requested.\n\nAn example View Composer from the Laravel documentation:\n\n``` php\nView::composer('profile', function($view)\n{\n\t$view-\u003ewith('count', User::count());\n}\n```\n\nA View Composer may also be created as a Class:\n\n``` php\n\u003c?php namespace My\\Project\\Name\\Space;\n\nclass UserCountComposer\n{\n\n\tpublic function compose($view)\n\t{\n\t\t$view-\u003ewith('count', User::count());\n\t}\n\n}\n```\n\nOf course, when a View Composer is created as a Class, the association between the View Composer and the \nView must be registered, either using the following syntax:\n\n``` php\nView::composer('profile', 'UserCountComposer');\n```\nor via a Service Provider:\n\n``` php\n\u003c?php namespace My\\Project\\Name\\Space;\n \nuse Illuminate\\Support\\ServiceProvider;\n \nclass ComposerServiceProvider \n\textends ServiceProvider \n{\n \n\tpublic function register()\n  \t{\n    \t$this-\u003eapp['view']-\u003ecomposer('profile', 'My\\Project\\Name\\Space\\UserCountComposer');\n  \t}\n \n}\n```\n\nData provided to the View by a View Composer may be accessed as if it had been provided by the Controller:\n\n``` php\n\u003cul\u003e\n\t@foreach ($data as $datum)\n\t\t\u003cli\u003e{{ $datum }}\u003c/li\u003e\n\t@endforeach\n\u003c/ul\u003e\n```\n\n#### Additional Resources\n\n* View Composers in the [Laravel Documentation](http://laravel.com/docs/responses#view-composers).\n* View Composers at [Laracasts](https://laracasts.com/lessons/view-composers).\n\n## Application\n\nUnfortunately, the out-of-the-box functionality of Laravel View Composers can be somewhat cumbersome.  \n\nIf we choose to go with the ```View::composer()``` format, our bootstrap files will quickly become overblown\nand unwieldy.  On the other hand, if we choose a Class based approach, in addition to creating the View Composer Classes,\nwe need to register our Composer/View associations.  This presents its own challenges.  We might choose to create a \nService Provider to register each of our Composer/View associations, resulting in repetitive boilerplate code as our \nService Providers proliferate. Alternately, we might choose to create a single Service Provider to register all of our \nComposer/View associations, but this merely simplifies our bootstrap files at the expense of an unwieldy Service Provider. Perhaps \nthe best choice is to create a Service Provider for each View and within it register its View Composer associations, but \nthis requires a fair amount of boilerplate and dramatically increases the indirection which already exists with View Composers.\n\nThis is the challenge that Virtuoso is intended to meet.  Virtuoso allows you to easily create simple, single-focused \nView Composers for your data and leverage composition when providing data to your Views by associating one or more View\nComposers with a single View via a \"Composite Composer\" as needed _without any unnecessary indirection or repetitive \nboilerplate code_ - all of your Composer/View associations can be found in a single location and all without writing any\nnew Service Providers!\n\n## Requirements\n\nVirtuoso supports the following versions of PHP:\n\n* PHP 5.4.\\*\n* PHP 5.5.\\*\n* PHP 5.6.\\*\n* HHVM\n\nand the following versions of Laravel:\n \n* Laravel 4.1.\\*\n* Laravel 4.2.\\*\n\n## Installation\n\nFirst, install Virtuoso through Composer (Virtuoso on [Packagist](https://packagist.org/packages/coderabbi/virtuoso)), \neither by adding it to the Require Array of your `composer.json`:\n\n```js\n\"require\": {\n    \"coderabbi/virtuoso\": \"0.*\"\n}\n```\n\nor from the Command Line: \n\n``` bash\nphp composer.phar require coderabbi/virtuoso:0.*\n```\n\nNext, update `app/config/app.php` to include a reference to this package's Service Provider in the \nProviders Array:\n\n``` php\n'providers' =\u003e array(\n    'Coderabbi\\Virtuoso\\ComposerServiceProvider'\n)\n```\n\nFinally, update `app\\config\\view.php` to include the Composers Array:\n\n``` php\n'composers' =\u003e array (\n)\n```\n\n## Usage\n\n#### Simple View Composers\n\nFirst, create your View Composer as you normally would (make sure to implement the Composer Interface):\n\n``` php\n\u003c?php namespace My\\Project\\Name\\Space;\n\nuse Coderabbi\\Virtuoso\\Composer;\n\nclass MyFirstSimpleComposer\n\timplements Composer\n{\n\n\tpublic function compose($view)\n\t{\n\t\t$view-\u003ewith('myData', $this-\u003egetMyData());\n\t}\n\t\n\tprivate function getMyData()\n\t{\n\t\t// do your thing here\n\t}\n\t\n}\n```\n\n\u003e Ideally, you should limit the data provided by each Composer to it's simplest, most cohesive unit. This\n\u003e will allow you to compose Composite View Composers for your Views more easily.\n\nNext, associate the View (full path within the View Directory specified in `app/config/view.php` \nusing dot notation) with your Simple View Composer (fully qualified Class Name including Namespace) \nby adding it to the Composers Array in `app\\config\\view.php`:\n\n``` php\n'composers' =\u003e array (\n\t'partials.header' =\u003e 'My\\Project\\Name\\Space\\MyFirstSimpleComposer',\n)\n```\n\nThat's it!  Virtuoso will take care of registering the View/Composer associations for you - no new Service Providers\nrequired!\n\nYou may access data provided by the Simple View Composer from the View as you normally would.\n\n#### Composite View Composers\n\nFirst, create the simple View Composers which will together comprise the Composite View Composer as above (but do not \nassociate them with your View in the Composer Array in `app\\config\\view.php`).\n\nNext, create your Composite View Composer (make sure to extend CompositeComposer) and add the component View \nComposers to its `$composers` array:\n\n``` php\n\u003c?php namespace My\\Project\\Name\\Space;\n\nuse Coderabbi\\Virtuoso\\CompositeComposer;\n\nclass MyFirstCompositeComposer\n\textends CompositeComposer\n{\n\n\tprotected $composers = array(\n\t\t'MyFirstSimpleComposer',\n\t\t'MySecondSimpleComposer',\n\t\t'MyThirdSimpleComposer'\n\t);\n\t\n}\n```\n\nFinally, associate your Composite View Composer (fully qualified Class Name including Namespace) with the \nView (full path within the View Directory specified in `app/config/view.php` using dot notation) by adding \nit to the Composers Array in `app\\config\\view.php`:\n\n``` php\n'composers' =\u003e array (\n\t'partials.header' =\u003e 'My\\Project\\Name\\Space\\MyFirstCompositeComposer',\n)\n```\n\nThat's it!  Virtuoso will take care of registering the individual View/Composer associations for you - no new Service\nProviders Required!\n\nYou may access data provided by the Composite View Composer from the View as you normally would.\n\n## Roadmap\n\nThe addition of tests will bring the package to v1.0. It's a very simple package designed to address a single \nlimitation in the standard implementations of Laravel View Composers so at this time I have no further plans\nfor the package beyond that version.  You are welcome to submit Issues or Pull Requests if you are so inclined; \nI will give my full attention to each.\n\n## License\n\nThis package is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).\nFurther details may be found in the [LICENSE](https://github.com/coderabbi/virtuoso/blob/master/LICENSE) file.\n\n## Author\n\nFollow [@coderabbi](http://twitter.com/coderabbi) on Twitter.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderabbi%2Fvirtuoso","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoderabbi%2Fvirtuoso","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderabbi%2Fvirtuoso/lists"}