{"id":20827713,"url":"https://github.com/peridot-php/peridot-scope","last_synced_at":"2025-05-07T21:05:21.757Z","repository":{"id":23256567,"uuid":"26614731","full_name":"peridot-php/peridot-scope","owner":"peridot-php","description":"Scopes for function binding and mixins","archived":false,"fork":false,"pushed_at":"2016-07-31T00:12:46.000Z","size":16,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-07T21:05:16.845Z","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/peridot-php.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-11-14T00:32:01.000Z","updated_at":"2016-07-31T00:05:56.000Z","dependencies_parsed_at":"2022-08-21T14:40:21.878Z","dependency_job_id":null,"html_url":"https://github.com/peridot-php/peridot-scope","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peridot-php%2Fperidot-scope","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peridot-php%2Fperidot-scope/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peridot-php%2Fperidot-scope/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peridot-php%2Fperidot-scope/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peridot-php","download_url":"https://codeload.github.com/peridot-php/peridot-scope/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252954427,"owners_count":21830903,"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-17T23:12:49.976Z","updated_at":"2025-05-07T21:05:21.731Z","avatar_url":"https://github.com/peridot-php.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Peridot Scope\n=============\n\n[![Build Status](https://travis-ci.org/peridot-php/peridot-scope.png)](https://travis-ci.org/peridot-php/peridot-scope) [![HHVM Status](http://hhvm.h4cc.de/badge/peridot-php/peridot-scope.svg)](http://hhvm.h4cc.de/package/peridot-php/peridot-scope)\n\nPeridot [Scope](https://github.com/peridot-php/peridot/wiki/Scopes).\n\nScopes allow safe binding of state for closures and offers a mechanism\nfor mixing state and behavior in via [child scopes](https://github.com/peridot-php/peridot/wiki/Scopes#extending-functionality-with-scopes).\n\nExtracted from the [Peridot](http://peridot-php.github.io/) testing framework.\n\n##Usage\n\nWe recommend installing this package via composer:\n\n```\n$ composer require peridot-php/peridot-scope:~1.0\n```\n\n###Creating a Scope\n\n```php\n$scope = new Scope();\n$scope-\u003ename = \"Brian\";\n\n$fnWithName = function() {\n    print $this-\u003ename;\n};\n\n$fnWithName = $scope-\u003eperidotBindTo($fnWithName);\n\n$fnWithName(); //prints \"Brian\"\n```\n\n###Using the ScopeTrait\n\nIf an existing class can benefit from a Scope, you can use the `ScopeTrait`\n\n```php\nclass Test\n{\n    use ScopeTrait;\n    \n    protected $definition;\n    \n    public function __construct(callable $definition)\n    {\n        $this-\u003edefinition = $definition; \n    }\n    \n    /**\n     * Return the definition bound to a scope\n     */\n    public function getDefinition()\n    {\n        $scope = $this-\u003egetScope();\n        return $scope-\u003eperidotBindTo($this-\u003edefinition);\n    }\n}\n```\n\n##Mixins\n\nYou can mix behavior in via [child scopes](https://github.com/peridot-php/peridot/wiki/Scopes#extending-functionality-with-scopes).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperidot-php%2Fperidot-scope","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fperidot-php%2Fperidot-scope","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperidot-php%2Fperidot-scope/lists"}