{"id":20254734,"url":"https://github.com/chippyash/assembly-builder","last_synced_at":"2025-04-11T00:03:48.614Z","repository":{"id":34219014,"uuid":"38077540","full_name":"chippyash/Assembly-Builder","owner":"chippyash","description":"A lightweight value assembly builder emulating Scala For Comprehensions but much more useful","archived":false,"fork":false,"pushed_at":"2021-05-24T05:38:41.000Z","size":67,"stargazers_count":0,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-11T00:03:40.240Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/chippyash.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-25T22:21:47.000Z","updated_at":"2021-05-24T05:38:02.000Z","dependencies_parsed_at":"2022-09-04T11:12:09.899Z","dependency_job_id":null,"html_url":"https://github.com/chippyash/Assembly-Builder","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chippyash%2FAssembly-Builder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chippyash%2FAssembly-Builder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chippyash%2FAssembly-Builder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chippyash%2FAssembly-Builder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chippyash","download_url":"https://codeload.github.com/chippyash/Assembly-Builder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248317705,"owners_count":21083528,"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-14T10:34:39.122Z","updated_at":"2025-04-11T00:03:48.584Z","avatar_url":"https://github.com/chippyash.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# chippyash/Assembly-Builder\n\n## Quality Assurance\n\n![PHP 5.6](https://img.shields.io/badge/PHP-5.6-blue.svg)\n![PHP 7](https://img.shields.io/badge/PHP-7-blue.svg)\n[![Build Status](https://travis-ci.org/chippyash/Assembly-Builder.svg?branch=master)](https://travis-ci.org/chippyash/Assembly-Builder)\n[![Code Climate](https://codeclimate.com/github/chippyash/Assembly-Builder/badges/gpa.svg)](https://codeclimate.com/github/chippyash/Assembly-Builder)\n[![Test Coverage](https://codeclimate.com/github/chippyash/Assembly-Builder/badges/coverage.svg)](https://codeclimate.com/github/chippyash/Assembly-Builder/coverage)\n\nThe above badges represent the current development branch.  As a rule, I don't push\n to GitHub unless tests, coverage and usability are acceptable.  This may not be\n true for short periods of time; on holiday, need code for some other downstream\n project etc.  If you need stable code, use a tagged version. Read 'Further Documentation'\n and 'Installation'.\n \nDeveloper support for PHP5.4 \u0026 5.5 was withdrawn at version 2.0.0 of this library.\nIf you need support for PHP 5.4 or 5.5, please use a version`\u003e=1,\u003c2`\n\nDeveloper support for PHP7.X was withdrawn at version 3.0.0 of this library.\nIf you need support for PHP 7.X, please use a version`\u003e=2,\u003c3`\n\n## What?\n\nProvides an Assembler, a lightweight variant of the Builder Pattern.  Also provides a\nScala like For Comprehension, (a simple descendant of Assembler.)\n\n## Why?\n\nIn my research of the Scala language, I came across the [For Comprehension](http://the-matrix.github.io/php/a-functional-for-comprehension/).\n It turns out that at its core, it is really a variant of a classic [Builder Pattern](https://github.com/chippyash/Builder-Pattern),\n but without the associated requirements for a Director.\n \nI did some searching but couldn't find anything remotely like it, so if you know of anything\nplease do let me know.  \n\nSo why is it useful?\n\nIn essence it provides a mechanism to collect together `things` and then assemble them\n at some later point. The things in this case are functions.  Since the introduction\n of Callables (or Closures) in PHP, life has changed a bit for the PHP dev. The \n anonymous function gives a freedom to do anything (PHP has always had that,) in a much\n simpler way.\n \n### It is really simple:\n\n- create an `Assembler`\n- attach a bunch of functions to it with a key (variable name) for the function\n    - functions can access previously defined functions (or stored variables)\n- assemble everything (call the functions that have been previously attached)\n- access one, some or none of the results\n\nThe examples/OneManCoffeeShop.php script gives a flavour of the Assembler in action in a \nrelatively simple scenario.\n\nexamples/CarAssemblyLine.php is a bit more complex, but shows how you can pass around\nan Assembler to various processes a bit like a shopping trolley, leaving it until some\npoint in the future where it is all assembled into some final product.  It also demonstrates\na simple derivation of the Assembler, the Scala like `For Comprehension` which because\n`For` is a reserved word in PHP, is called `FFor`.\n\nIn a large system, you might want to use an Assembler as a collection point for stuff\ngoing on in the application.  For this purpose you can get a Singleton instance via\n`Assembler::get()`. Of course, you can only use this once (as in subsequent calls to\nAssembler::get() will return the same instance,) so use with care. \n\n## How?\n\n### Assembler\n\nCreate an Assembler\n\n\u003cpre\u003e\nuse Assembler\\Assembler;\n\n$myAssembler = Assembler::create();\n//or to create the singleton instance\n$myAssembler = Assembler::get();\n\u003c/pre\u003e\n\nAdd functions to an Assembler. This may seems strange at first. The pattern for adding\nfunctions is:\n\n\u003cpre\u003e\nAssembler-\u003enameOfVar(function(){ return ...;});\n//e.g.\n$myAssembler-\u003efoo(function(){return 'foo';});\n\u003c/pre\u003e\n\nOr to chain a number of assembly items together:\n\n\u003cpre\u003e\n$myAssembler-\u003efoo(function(){return 'foo';})\n    -\u003ebar(function(){return 'bar';});\n\u003c/pre\u003e\n\nYou can reference predefined entries by passing in their name as a parameter to \nsubsequent entries:\n\n\u003cpre\u003e\n$myAssembler-\u003efoo(function(){return 'foo';})\n    -\u003ebar(function($foo){return \"$foo bar\";});\n\u003c/pre\u003e\n\nAt this point, the Assembler has not executed your functions, so you can redefined them:\n\n\u003cpre\u003e\n$myAssembler-\u003efoo(function(){return 'foo';})\n    -\u003ebar(function($foo){return \"$foo bar\";})\n    -\u003efoo(function(){return 'foo foo';});\n\u003c/pre\u003e\n\nTo execute the functions, call the `assemble()` method:\n\n\u003cpre\u003e\n$myAssembler-\u003efoo(function(){return 'foo})\n    -\u003ebar(function($foo){return \"$foo bar\";})\n    -\u003efoo(function(){return 'foo foo';})\n    -\u003eassemble();\n\u003c/pre\u003e\n\nAt this point, the entries become immutable and cannot be overwritten.  You can\ncontinue to add additional entries, perhaps referencing earlier ones and then call\n-\u003eassemble() again to fix the entries.\n\nTo retrieve one of more values from the Assembler you use the `release()` method.\nrelease() takes one or more strings, the names of the items that you want to release.\nTo release a single item:\n\n\u003cpre\u003e\n$myFoo = Assembler::create()\n    -\u003efoo(function(){return 'foo})\n    -\u003ebar(function($foo){return \"$foo bar\";})\n    -\u003efoo(function(){return 'foo foo';})\n    -\u003eassemble()\n    -\u003erelease('foo');\n\u003c/pre\u003e\n\nReleasing multiple items will return an array of values, so perhaps the easiest way\nto access them is to use the venerable PHP `list()` (or []) method, e.g.\n\n\u003cpre\u003e\nlist($myFoo, $myBar) = Assembler::create()\n    -\u003efoo(function(){return 'foo})\n    -\u003ebar(function($foo){return \"$foo bar\";})\n    -\u003efoo(function(){return 'foo foo';})\n    -\u003eassemble()\n    -\u003erelease('foo', 'bar');\n\u003c/pre\u003e\n\nYou can merge one Assembler into another using the `merge()` method:\n\n\u003cpre\u003e\n$worker1 = Assembler::create()\n    -\u003efoo(function(){return 'foo});\n    \n$worker2 = Assembler::create()\n    -\u003ebar(function($foo){return \"$foo bar\";})\n    \n$myFoo = $worker1-\u003emerge($worker2-\u003eassemble())\n    -\u003eassemble()\n    -\u003erelease('foo');\n\u003c/pre\u003e\n\nYou can send in parameters during the creation (create() or get()) of an Assembler.\nThis is most useful to prevent you having to use the `use clause` during function\ndefinition.  Parameters sent in during the create process are immutable, i.e. you cannot\noverride them with a later declaration.\n\n\u003cpre\u003e\n$a = 'foo';\n$b = 'bar'\n\n$value = Assembler::create(['a'=\u003e$a, 'b'=\u003e$b])\n    -\u003efoo(function($a, $b) { return \"$a$b\";})\n    -\u003eassemble()\n    -\u003erelease('foo');\n// $value == 'foobar'\n\n//This will have no effect on 'a'\n$value = Assembler::create(['a'=\u003e$a, 'b'=\u003e$b])\n    -\u003ea(function() {return 1;})\n    -\u003efoo(function($a, $b) { return \"$a$b\";})\n    -\u003eassemble()\n    -\u003erelease('foo');\n\n//without parameter injection\n$value = Assembler::create()\n    -\u003efoo(function() use ($a, $b) { return \"$a$b\";})\n    -\u003eassemble()\n    -\u003erelease('foo');\n\n\u003c/pre\u003e\n\nYou can utilise the ParameterGrabable trait to facilitate parameter injection into\nthe create() constructor.\n\n\u003cpre\u003e\nuse Assembler\\Traits\\ParameterGrabable;\nuse Assembler\\Assembler;\n\nclass myClass {\n     use ParameterGrabable;\n\n     static function foo($param1, $param2 = null) {\n         $a = Assembler::create(self::grabFunctionParameters(__CLASS__, __FUNCTION__, func_get_args());\n     }\n\n     function bar($param1, $param2 = null) {\n         $a = Assembler::create($this-\u003egrabMethodParameters(__CLASS__, __METHOD__, func_get_args());\n     }\n}\n\u003c/pre\u003e\n\n### FFor\n\nThe FFor class is a simple extension of Assembler, but with restrictions:\n\n- you cannot create a singleton FFor via get(). Use create().  FFor is intended as a language\nconstruct\n- you cannot merge() a FFor.\n- there is an additional method; fyield(). fyield() is a pseudonym for -\u003eassemble()-\u003erelease()\nand takes the same parameters as release()\n\nSee the examples/CarAssemblyLine.php script for a usage example.\n\n## Further documentation\n\nPlease note that what you are seeing of this documentation displayed on Github is\nalways the latest dev-master. The features it describes may not be in a released version\n yet. Please check the documentation of the version you Compose in, or download.\n\n![Uml diag](https://github.com/chippyash/Assembly-Builder/blob/master/docs/uml.png)\n\nSee the tests and [Test Contract](https://github.com/chippyash/Assembly-Builder/blob/master/docs/Test-Contract.md)\n for further information.\n \nCheck out [ZF4 Packages](http://zf4.biz/packages?utm_source=github\u0026utm_medium=web\u0026utm_campaign=blinks\u0026utm_content=assembler) for more packages\n\n## Running the examples\n\nAlthough the library itself does not have any other dependencies other than PHP,\nthe examples do.  These are included in the `composer requires-dev` statement so as\nlong as you have included the dev requirements (default for Composer,) you should be \ngood to go.\n\n## Changing the library\n\n1.  fork it\n2.  write the test\n3.  amend it\n4.  do a pull request\n\nFound a bug you can't figure out?\n\n1.  fork it\n2.  write the test\n3.  do a pull request\n\nNB. Make sure you rebase to HEAD before your pull request\n\nOr - raise an issue ticket.\n\n## Where?\n\nThe library is hosted at [Github](https://github.com/chippyash/Assembly-Builder). It is\navailable at [Packagist.org](https://packagist.org/packages/chippyash/assembly-builder)\n\n### Installation\n\nInstall [Composer](https://getcomposer.org/)\n\n#### For production\n\n\u003cpre\u003e\n    \"chippyash/assembly-builder\": \"\u003e=3\"\n\u003c/pre\u003e\n\nOr to use the latest, possibly unstable version:\n\n\u003cpre\u003e\n    \"chippyash/assembly-builder\": \"dev-master\"\n\u003c/pre\u003e\n\n\n#### For development\n\nClone this repo, and then run Composer in local repo root to pull in dependencies\n\n\u003cpre\u003e\n    git clone git@github.com:chippyash/Assembly-Builder.git Assembler\n    cd Assembler\n    composer install\n\u003c/pre\u003e\n\nTo run the tests:\n\n\u003cpre\u003e\n    cd Assembler\n    vendor/bin/phpunit -c test/phpunit.xml test/\n\u003c/pre\u003e\n\n## License\n\nThis software library is released under the [BSD 3 Clause license](https://opensource.org/licenses/BSD-3-Clause)\n\nThis software library is Copyright (c) 2015, Ashley Kitson, UK\n\n## History\n\nV1.0.0 Initial Release\n\nV1.1.0 Add ability to send in parameters on Assembler and Ffor creation\n\nV1.1.1 Fix parameter order passing bug\n\nV1.1.2 Add ParameterGrabable trait\n\nV1.2.0 Update to use Chippyash\\Type V3\n\nV1.2.1 Add link to packages\n\nV1.2.2 Verify PHP 7 compatibility\n\nV1.2.3 Update dependency on Monad\n\nV1.2.4 Update build scripts\n\nV1.2.5 update composer - forced by packagist composer.json format change\n\nV2.0.0 BC Break. Support withdrawn for old php versions\n\nV2.1.0 Change of license from GPL V3 to BSD 3 Clause\n\nV3.0.0 BC Break. Support for PHP \u003cV8 withdrawn","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchippyash%2Fassembly-builder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchippyash%2Fassembly-builder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchippyash%2Fassembly-builder/lists"}