{"id":19406289,"url":"https://github.com/chadicus/extension_methods","last_synced_at":"2026-03-03T13:34:42.648Z","repository":{"id":73122383,"uuid":"58159202","full_name":"chadicus/extension_methods","owner":"chadicus","description":"Extension methods enable you to \"add\" methods to existing classes without creating a new derived class or otherwise modifying the original class.","archived":false,"fork":false,"pushed_at":"2016-05-05T20:51:35.000Z","size":2,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-25T00:49:33.009Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"M4","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/chadicus.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-05-05T20:38:54.000Z","updated_at":"2016-05-05T20:41:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"a267e4c3-79dc-4d65-9788-959baecc6800","html_url":"https://github.com/chadicus/extension_methods","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/chadicus/extension_methods","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chadicus%2Fextension_methods","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chadicus%2Fextension_methods/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chadicus%2Fextension_methods/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chadicus%2Fextension_methods/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chadicus","download_url":"https://codeload.github.com/chadicus/extension_methods/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chadicus%2Fextension_methods/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30046546,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-03T10:53:31.691Z","status":"ssl_error","status_checked_at":"2026-03-03T10:53:22.041Z","response_time":61,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2024-11-10T11:41:53.921Z","updated_at":"2026-03-03T13:34:42.625Z","avatar_url":"https://github.com/chadicus.png","language":"M4","funding_links":[],"categories":[],"sub_categories":[],"readme":"# extension_methods\n Extension methods are a special kind of static method, but they are called as if they were instance methods on the extended class. For client code written in PHP, there is no apparent difference between calling an extension method and the methods that are actually defined in a class.\n\n## Theory of Operation\n\nClass is written that offers additional functionality to a class\n\n```php\n\u003c?php\nfinal class DOMDocumentExtensions\n{\n    /**\n     * Helper method to add a new \\DOMNode to the given document with the given value.\n     *\n     * @param \\DOMDocument $document The document to which the node will be added.\n     * @param string       $xpath    A valid xpath destination of the new node.\n     * @param mixed        $value    The value for the new node.\n     *\n     * @return void\n     *\n     * @throws \\DOMException Thrown if the given $xpath is not valid.\n     */\n    public static function addXPath(\\DOMDocument $document, $xpath, $value = null)\n    {\n        $domXPath = new \\DOMXPath($document);\n        $list = @$domXPath-\u003equery($xpath);\n        if ($list === false) {\n            throw new \\DOMException(\"XPath {$xpath} is not valid.\");\n        }\n\n        if ($list-\u003elength) {\n            $list-\u003eitem(0)-\u003enodeValue = $value;\n            return;\n        }\n\n        $pointer = $document;\n        foreach (array_filter(explode('/', $xpath)) as $tagName) {\n            $pointer = self::parseFragment($domXPath, $pointer, $tagName);\n        }\n\n        $pointer-\u003enodeValue = $value;\n    }\n\n    // other methods...\n}\n```\n\nExtension class is registered.\n\n```php\nregister_class_extensions('\\DOMDocument', 'DOMDocumentExtensions');\n```\n\nNew methods can be used on instanciated object\n\n```php\n$dom = new \\DOMDocument();\n$dom-\u003eaddXPath('/path/to/new/node', 'the node value');\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchadicus%2Fextension_methods","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchadicus%2Fextension_methods","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchadicus%2Fextension_methods/lists"}