{"id":26233596,"url":"https://github.com/jimbo2150/php-utilities","last_synced_at":"2026-03-11T11:05:32.373Z","repository":{"id":279321523,"uuid":"938429270","full_name":"jimbo2150/php-utilities","owner":"jimbo2150","description":"Various utilities for PHP projects and libraries.","archived":false,"fork":false,"pushed_at":"2025-05-27T21:33:06.000Z","size":138,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-19T09:41:30.806Z","etag":null,"topics":["library","php","php8","trait","traits","utilities"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jimbo2150.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-02-25T00:08:37.000Z","updated_at":"2025-05-27T21:33:09.000Z","dependencies_parsed_at":"2025-05-16T01:19:49.366Z","dependency_job_id":"ce82f24c-6591-4c5a-b0e3-663abea5476b","html_url":"https://github.com/jimbo2150/php-utilities","commit_stats":null,"previous_names":["jimbo2150/php-utilities"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/jimbo2150/php-utilities","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimbo2150%2Fphp-utilities","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimbo2150%2Fphp-utilities/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimbo2150%2Fphp-utilities/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimbo2150%2Fphp-utilities/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jimbo2150","download_url":"https://codeload.github.com/jimbo2150/php-utilities/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimbo2150%2Fphp-utilities/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30379265,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-11T06:09:32.197Z","status":"ssl_error","status_checked_at":"2026-03-11T06:09:17.086Z","response_time":84,"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":["library","php","php8","trait","traits","utilities"],"created_at":"2025-03-13T01:16:41.288Z","updated_at":"2026-03-11T11:05:32.358Z","avatar_url":"https://github.com/jimbo2150.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Version](https://img.shields.io/github/v/release/jimbo2150/php-utilities)\n![License](https://img.shields.io/github/license/jimbo2150/php-utilities)\n![PHP Required Version](https://img.shields.io/packagist/dependency-v/jimbo2150/php-utilities/php)\n\n# PHP Utilities\n\n**A collection of useful PHP utility functions, interfaces, classes, traits, and enums to simplify common tasks and enhance your PHP projects.**\n\n## Table of Contents\n\n-   [Installation](#installation)\n-   [Usage](#usage)\n-   [Features](#features)\n-   [Changelog](#changelog)\n\n## Installation\n\nThis library is distributed via [Composer](https://getcomposer.org/)'s [Packagist](https://packagist.org/) repository. To install it, run the following command in your project directory:\n\n```bash\ncomposer require jimbo2150/php-utilities\n```\n\n## Usage\n\n### Traitable\n\nThe `Traitable` trait provides a `hasTrait($traitName)` method that checks if the given trait is associated with the object instance. It works similar to how `instanceof` works with class hierarchy. It checks if the trait is directly connected to the class or if any of the class's ancestors have the given trait or if the class or class ancestors' traits uses the checked trait (e.g. it checks the trait hierarchy). It also caches the trait hierarchy as it traverses the tree so subsequent runs with classes that have those traits will perform faster and not have to traverse all or part of the hierarchy.\n\nHere is an example of usage:\n\n```php\nuse Jimbo2150\\PhpUtilities\\Traitable;\n\ntrait resourceful {\n\n}\n\ntrait streamable {\n\t// ...\n}\n\ntrait writeable {\n\tuse resourceful;\n\tuse streamable;\n\t// ...\n}\n\ntrait readable {\n\tuse resourceful;\n\tuse streamable;\n\t// ...\n}\n\ntrait blankable {\n\n}\n\nclass StringBuffer {\n\tuse Traitable;\n\tuse writeable;\n\tuse readable;\n\t// ...\n}\n\n$string_stream = new StringBuffer();\n$string_stream-\u003ehasTrait(resourceful::class); // true\n$string_stream-\u003ehasTrait(readable::class); // true\n$string_stream-\u003ehasTrait(blankable::class); // false\n```\n\n### Traits\n\nThis helper class can be used instead of the `Traitable` trait to check if a class is an instance of a given trait. Using the same class/trait definition as above, you can run:\n\n```php\nuse Jimbo2150\\PhpUtilities\\Traits;\n\n$string_stream = new StringBuffer();\nTraits::instanceOf($string_stream, resourceful::class); // true\nTraits::instanceOf($string_stream, readable::class); // true\nTraits::instanceOf($string_stream, blankable::class); // false\n```\n\n## Features\n\nCurrently this library has a Traitable trait which allows you to check if the instance has an assigned trait to itself or any of it's ancestors (or any of the trait's traits). It's the equivalent of doing `$x instanceof TraitX` to check if an object is an instance of a given trait. There is also an associated `Trait` helper class with static functions which actually perform the trait check.\n\nFeel free to suggest other utilities to add and I will take them under consideration - or submit a pull request with a new utility you would like to have added.\n\n## Changelog\n\nSee [CHANGELOG.md](/CHANGELOG.md).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjimbo2150%2Fphp-utilities","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjimbo2150%2Fphp-utilities","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjimbo2150%2Fphp-utilities/lists"}