{"id":21962696,"url":"https://github.com/icio/scope","last_synced_at":"2025-03-22T20:44:47.720Z","repository":{"id":20075871,"uuid":"23344788","full_name":"icio/scope","owner":"icio","description":"Python's with statement for PHP","archived":false,"fork":false,"pushed_at":"2014-09-25T20:55:43.000Z","size":208,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-28T00:43:00.232Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/icio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-26T08:39:30.000Z","updated_at":"2014-11-02T21:53:17.000Z","dependencies_parsed_at":"2022-08-21T13:40:56.175Z","dependency_job_id":null,"html_url":"https://github.com/icio/scope","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icio%2Fscope","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icio%2Fscope/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icio%2Fscope/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icio%2Fscope/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/icio","download_url":"https://codeload.github.com/icio/scope/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245020314,"owners_count":20548156,"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-29T10:53:25.439Z","updated_at":"2025-03-22T20:44:47.669Z","avatar_url":"https://github.com/icio.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Scope [![Build Status](https://travis-ci.org/icio/scope.svg?branch=master)](https://travis-ci.org/icio/scope)\n\nScope offers a mechanism for preparing global environments and containers for the duration of a callback, keeping state mutation and clean-up to only declaration in your code. Inspired by Python's native [with](https://docs.python.org/2/reference/datamodel.html#with-statement-context-managers).\n\nFor example, instead of doing:\n\n```php\nglobal $x;\n$xBackup = $x;\n$x = $xNew;\n$done = do_it();\n$x = $xBackup;\n```\n\nwith `KeyState` you can set an Array key state:\n\n```php\n(new KeyState($GLOBALS, array(\"x\" =\u003e $newX)))-\u003ecall('do_it');\n```\n\nCurrently available scopes help with:\n\n* Collecting multiple scopes together, with `Scope`;\n* Setting temporary values on arrays, with `KeyState`;\n* Capturing function output, with `Buffer`;\n* Changing into a new directory, with `WorkingDirectory`; and\n* Worrying about different error levels, with `ErrorReporting`.\n\nSometimes you'll want to hop in and out of a given scope, providing default context by following the changes incurred by your actions within. The scopes can optionally account for this. The `Buffer` can collect the output across multiple sessions; the `WorkingDirectory` can go back to the directory it left upon re-entry; the `KetState` can track the value of keys, should they be changed in-scope; and the `ErrorReporting` can track any changes to the reporting. See the spec tests for details.\n\nAll entered scopes are passed into the callback as function arguments. For example, when working with output buffers you can capture and return the output as so:\n\n```php\n$output = (new Scope(\n    new Buffer(Buffer::CLEAN),\n    new WorkingDirectory(\"./old\")\n))-\u003ecall(function(Buffer $buffer) {\n    require \"old-script.php\";\n    return $buffer-\u003egetContents();\n});\n```\n\nIf exceptions are thrown during the callback then we close the scopes and re-throw the exception. If exceptions are thrown by the scopes then we clean up any already entered and re-throw the exception. Exceptions thrown whilst trying to leave a scope prevent the clean-up of others (which should perhaps change).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficio%2Fscope","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ficio%2Fscope","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficio%2Fscope/lists"}