{"id":18323622,"url":"https://github.com/mortalflesh/callbackparser","last_synced_at":"2025-08-12T16:39:59.136Z","repository":{"id":57016920,"uuid":"67357463","full_name":"MortalFlesh/CallbackParser","owner":"MortalFlesh","description":"PHP parser for arrow functions","archived":false,"fork":false,"pushed_at":"2021-03-30T14:29:38.000Z","size":31,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-21T05:42:25.256Z","etag":null,"topics":["arrow-functions","callback","php-parser","wtf"],"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/MortalFlesh.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2016-09-04T16:58:59.000Z","updated_at":"2023-09-08T17:14:26.000Z","dependencies_parsed_at":"2022-08-22T09:40:42.967Z","dependency_job_id":null,"html_url":"https://github.com/MortalFlesh/CallbackParser","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/MortalFlesh/CallbackParser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MortalFlesh%2FCallbackParser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MortalFlesh%2FCallbackParser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MortalFlesh%2FCallbackParser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MortalFlesh%2FCallbackParser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MortalFlesh","download_url":"https://codeload.github.com/MortalFlesh/CallbackParser/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MortalFlesh%2FCallbackParser/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270099226,"owners_count":24527027,"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","status":"online","status_checked_at":"2025-08-12T02:00:09.011Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["arrow-functions","callback","php-parser","wtf"],"created_at":"2024-11-05T18:28:54.863Z","updated_at":"2025-08-12T16:39:59.099Z","avatar_url":"https://github.com/MortalFlesh.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"CallbackParser\n==============\n\n[![Latest Stable Version](https://img.shields.io/packagist/v/mf/callback-parser.svg)](https://packagist.org/packages/mf/callback-parser)\n[![Build Status](https://travis-ci.org/MortalFlesh/CallbackParser.svg?branch=master)](https://travis-ci.org/MortalFlesh/CallbackParser)\n[![Coverage Status](https://coveralls.io/repos/github/MortalFlesh/CallbackParser/badge.svg?branch=master)](https://coveralls.io/github/MortalFlesh/CallbackParser?branch=master)\n[![Total Downloads](https://img.shields.io/packagist/dt/mf/callback-parser.svg)](https://packagist.org/packages/mf/callback-parser)\n[![License](https://img.shields.io/packagist/l/mf/callback-parser.svg)](https://packagist.org/packages/mf/callback-parser)\n\nPHP parser for arrow functions\n\u003e This library is no longer supported, since the arrow functions are natively in PHP 7.4 - https://www.php.net/manual/en/functions.arrow.php\n\n## Table of Contents\n- [Requirements](#requirements)\n- [Installation](#installation)\n- [Arrow Functions](#arrow-functions)\n- [How does it work](#how-does-it-work)\n- [Possibly WTF?](#wtf)\n- [80:20 - Simple](#80-20)\n\n## \u003ca name=\"requirements\"\u003e\u003c/a\u003eRequirements\n- PHP 7.1\n- `eval()` function for parsing [Arrow Functions](#arrow-functions)\n\n\n## \u003ca name=\"installation\"\u003e\u003c/a\u003eInstallation:\n```\ncomposer require mf/callback-parser\n```\n\n\n## \u003ca name=\"arrow-functions\"\u003e\u003c/a\u003eArrow Functions\n\n### Usage:\n```php\n$callbackParser = new CallbackParser();\n$callback = $callbackParser-\u003eparseArrowFunction('($a, $b) =\u003e $a + $b');\n\nvar_dump($callback(2, 3));  // int 5\n```\n\n### With Custom Exception\n```php\n$callbackParser = new CallbackParser(App\\MyCustomException::class);\n\n$callbackParser-\u003eparseArrowFunction('invalid');  // throws App\\MyCustomException\n```\n\n\n## \u003ca name=\"how-does-it-work\"\u003e\u003c/a\u003eHow does it work?\n- it parses function from string and evaluate it with `eval()`\n\n\n## \u003ca name=\"wtf\"\u003e\u003c/a\u003ePossibly WTF?\nThis parser can parse an arrow function into PHP to be execute as usual. \nBut this process could be a little bit more complex than just `eval` it.\nYou can check `CallbackParserTest::provideInvalidFunction()` for examples.\n\n### Namespaces of parameters\nFor example namespace of class for given parameter type.\n```php\n(SimpleEntity $entity) =\u003e $entity-\u003egetId()\n```\nThis example above shows an `INVALID` arrow function to be parsed (yet?).\nTheres more reasons for this is an `invalid` one:\n- callback is parsed and `eval`ed elsewhere of scope, where you give such a callback\n- so `CallbackParser` does not know `SimpleEntity` full class name\n\nThere is more ways to 'fix' it, like:\n- you can register a class map of allowed parameter types and parser could find a relevant one and\n use a full class name from the map, but IMHO this could be more complex than it should be\n- parser could also find a relevant class in you entire project and magically use one of the most relevant, \nbut it's a dark magic and I'd rather avoid it\n\n#### Question is - is it really necessary?\nI dont think so. Because PHP is quite powerful (`weak`) and allows you\nto use class methods of an object even if you don't know what they are.\nBut since the original purpose of this parser was to parse a callbacks on [Collections](https://github.com/MortalFlesh/MFCollectionsPHP),\nyou have other ways to know and verify a object type in parameter, so you can simply use those methods right away.\n\n```php\n$list = new Generic\\ListCollection(SimpleEntity::class);\n$list-\u003eadd(new SimpleEntity(1));\n$list-\u003eadd(new SimpleEntity(2));\n\n$ids = $list-\u003emap('($entity) =\u003e $entity-\u003egetId()');\n\nvar_dump($ids);\n\n//array (size=2)\n//  0 =\u003e int 1\n//  1 =\u003e int 2\n```\n\n## \u003ca name=\"80-20\"\u003e\u003c/a\u003eSimple simpler and complex still simply - 80:20\nIMHO this parser allows you to parse simple functions simply, and you can still write a complex functions like PHP allows you.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmortalflesh%2Fcallbackparser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmortalflesh%2Fcallbackparser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmortalflesh%2Fcallbackparser/lists"}