PHPackages                             deviscoding/code-objects - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. deviscoding/code-objects

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

deviscoding/code-objects
========================

PHP Library for managing code objects and strings.

1.4.1(1y ago)04714LGPL-2.1PHPPHP &gt;=7.0

Since Feb 26Pushed 1y ago1 watchersCompare

[ Source](https://github.com/jonesiscoding/code-objects)[ Packagist](https://packagist.org/packages/deviscoding/code-objects)[ RSS](/packages/deviscoding-code-objects/feed)WikiDiscussions main Synced today

READMEChangelog (6)Dependencies (1)Versions (7)Used By (4)

Code Objects
============

[](#code-objects)

PHP Library which includes classes for the resolution of class names and callables, as well as the manipulation of code construct strings such as class names, method names, CSS classes, HTML5 ids, table names, and more.

Using this library? I'd love to hear about it! Star the repo, or mention [@jonesiscoding](https://twitter.com/jonesiscoding/)in a tweet!

Version Objects
---------------

[](#version-objects)

There are two version objects designed for parsing and comparing Semantic Version numbers, `Version` and `VersionImmutable`.

Construct Objects
-----------------

[](#construct-objects)

There are three main construct objects: `ConstructString`, `ClassString` and `MethodString`. Both `ClassString` and `MethodString` are extensions of `ConstructString`.

The base `ConstructString` class to work with the name of any coding construct such as a table, class, method, key, etc.

The more specific `ClassString` and `MethodString` contain additional methods for dealing with situations specific to a method name or a class name such as extracting the class name, the namespace, the function name, etc.

### Common Methods

[](#common-methods)

MethodPurpose`css`Sanitizes a string for use as a CSS class, or HTML5 id.`camelize`Changes *class\_name* to *className* (camelCase)`classify`Changes *class\_name* to *ClassName* (PascalCase)`slugify`Removes all special characters and replaced spacers with dashes or the provided separator`snakeize`Changes *ClassName* to *class\_name* (snake\_case)Resolver Classes
----------------

[](#resolver-classes)

The resolver classes are aimed at allowing for the resolution of PHP classes and callables. At most times during development, the use of autoloaders and PSR-0 or PSR-4 structure would prevent the need for the resolution of classes and callables.

These classes can be useful, however, in situations where callables are configured outside your code base, such as in a YAML or XML configuration file or in a database. Often in these situations, callables and classes are referred to with a key or id, rather than the fully qualified class name

Another situation in which these classes can be useful is when you have multiple classes that could be used, and these classes exist in multiple name spaces. For example, when some classes that implement a specific interface are part of your code base, but others may be part of a vendor library.

Each class contains one main method: `resolve`, which will resolve the given string, array, or object.

### Class Resolver

[](#class-resolver)

At instantiation, this class is provided a namespace or "sibling" class (from which to derive a namespace). An array of namespaces or sibling classes may also be provided.

When the `resolve` method is called, it resolves the provided string into a fully qualified class name by matching to existing classes within the namespaces provided to the resolver at instantiation.

### Implementation Resolver

[](#implementation-resolver)

This class functions the same as the `ClassResolver`, but only resolves classes that implement the interface given at the time of instantiation.

### Callback Resolver

[](#callback-resolver)

The `CallbackResolver` class is also provided a namespace or "sibling" class at instantiation, and will also take an array of namespaces or sibling classes.

When the `resolve` method is called, it resolves the provided string, array, or object into a `\Closure` by first resolving any class as needed, instantiating and needed object (if possible), verifying that the requested method is callable, then converting the callable into a `\Closure`.

The item to resolve may be in any of these formats:

- `ClassName::methodString` (works with non-static methods too)
- `\Fully\Qualified\ClassName::methodString` (works with non-static methods too)
- `['ClassName', 'methodString']`
- `['\Fully\Qualified\ClassName', 'methodString']`
- `'InvokableClassName'`
- `'\Fully\Qualified\InvokableClassName`

These may also be provided. Though they would need no resolution, they would be validated to be callable and turned into a `\Closure`.

- `InvokableObject`
- \[Object, 'methodString'\]

### ContainerAwareCallbackResolver

[](#containerawarecallbackresolver)

The `ContainerAwareCallbackResolver` must be provided a *PSR-11 Container Interface* at instantiation, and may also be provided optional namespaces or "sibling" classes at instantiation. The `ContainerInterface` object is used as a dependency injection service locator, for example, the container used in the Symfony framework.

When the `resolve` method is called, this resolver type will attempt to match the *class* portion of any item to an *id* of a service in the `ContainerInterface`, then proceed with resolving the rest of the callback.

### Closure

[](#closure)

The `Closure` class is a super-charged drop-in replacement for PHP 7.1's `\Closure::fromCallable`, and works using a method of the same name. This class is not intended for separate use, but instead does the "heavy lifting" for the `CallbackResolver`, taking either an array or a string that should be callable, instantiates any class into an object (if necessary and possible), then creates a closure from the resulting callable.

In PHP 7.1+, the original `\Closure::fromCallable` is used for the final step. In previous versions, the resulting `\Closure` is created "the old fashioned way"

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~185 days

Recently: every ~228 days

Total

6

Last Release

661d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d57a7df632f0f3297af28804aa4d48a6c9bbd67795056353fb3dd8c7ed7e1cb5?d=identicon)[jonesiscoding](/maintainers/jonesiscoding)

---

Top Contributors

[![jonesiscoding](https://avatars.githubusercontent.com/u/5215554?v=4)](https://github.com/jonesiscoding "jonesiscoding (13 commits)")

### Embed Badge

![Health badge](/badges/deviscoding-code-objects/health.svg)

```
[![Health](https://phpackages.com/badges/deviscoding-code-objects/health.svg)](https://phpackages.com/packages/deviscoding-code-objects)
```

###  Alternatives

[symfony/dependency-injection

Allows you to standardize and centralize the way objects are constructed in your application

4.2k455.6M9.6k](/packages/symfony-dependency-injection)[illuminate/contracts

The Illuminate Contracts package.

706130.3M13.3k](/packages/illuminate-contracts)[illuminate/container

The Illuminate Container package.

31182.0M2.4k](/packages/illuminate-container)[ecotone/ecotone

Enterprise architecture layer for Laravel and Symfony — CQRS, Event Sourcing, Durable Workflows (Sagas, Orchestrators), Projections, and Outbox messaging via PHP attributes.

564576.7k53](/packages/ecotone-ecotone)[symfony/type-info

Extracts PHP types information.

20069.8M270](/packages/symfony-type-info)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k43](/packages/civicrm-civicrm-core)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
