PHPackages                             cabello/selector - 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. cabello/selector

ActiveLibrary

cabello/selector
================

Extract information from JSON, StdClass in a fashionable way

76PHP

Since Sep 27Pushed 12y ago2 watchersCompare

[ Source](https://github.com/cabello/selector)[ Packagist](https://packagist.org/packages/cabello/selector)[ RSS](/packages/cabello-selector/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Selector [![Build Status](https://camo.githubusercontent.com/9be07289770a3b075409ba9981595a800032d842e547cde8f205ed3508527ba3/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f636162656c6c6f2f73656c6563746f722e706e67)](http://travis-ci.org/cabello/selector)
=========================================================================================================================================================================================================================================================================

[](#selector-)

Disclaimer
----------

[](#disclaimer)

If you found this project but think it's incomplete or doesn't meet your needs, try [Property Access](http://symfony.com/doc/current/components/property_access/index.html).

Problem
-------

[](#problem)

Imagine that you have a `StdClass` (possibly created by a `json_decode`) instance full of attributes you want to retrieve. So you do something like this:

```
$username = $photo->owner->username;

```

What happens if *username* is undefined and/or *owner*?

```
$username = isset($photo) && isset($photo->owner) && isset($photo->owner->username)
          ? $photo->owner->username
          : 'anonymous';

```

Imagine this kind of logic spread all over your codebase. What a mess!

Solution
--------

[](#solution)

Selector turns the horrible code above into this:

```
$photoSelector = Selector($photo);
$username      = $photoSelector->getOne('owner.username', 'anonymous');

```

You never have to worry again about checking if the `StdClass` have the properties you need, and as a plus you receive several ways of retrieving data.

Features
--------

[](#features)

### Selector

[](#selector)

#### Selector::getOne

[](#selectorgetone)

#### Description

[](#description)

#### Parameters

[](#parameters)

#### Return Values

[](#return-values)

#### Examples

[](#examples)

##### Example #1

[](#example-1)

The above example will output:

##### Example #2

[](#example-2)

The above example will output:

#### Selector::getAll

[](#selectorgetall)

#### Description

[](#description-1)

#### Parameters

[](#parameters-1)

#### Return Values

[](#return-values-1)

#### Examples

[](#examples-1)

##### Example #1

[](#example-1-1)

The above example will output:

##### Example #2

[](#example-2-1)

The above example will output:

#### Selector::findOne

[](#selectorfindone)

#### Description

[](#description-2)

#### Parameters

[](#parameters-2)

#### Return Values

[](#return-values-2)

#### Examples

[](#examples-2)

##### Example #1

[](#example-1-2)

The above example will output:

##### Example #2

[](#example-2-2)

The above example will output:

#### Selector::findAll

[](#selectorfindall)

#### Description

[](#description-3)

#### Parameters

[](#parameters-3)

#### Return Values

[](#return-values-3)

#### Examples

[](#examples-3)

##### Example #1

[](#example-1-3)

The above example will output:

##### Example #2

[](#example-2-3)

The above example will output:

#### Selector::getDictionary

[](#selectorgetdictionary)

#### Description

[](#description-4)

#### Parameters

[](#parameters-4)

#### Return Values

[](#return-values-4)

#### Examples

[](#examples-4)

##### Example #1

[](#example-1-4)

The above example will output:

##### Example #2

[](#example-2-4)

The above example will output:

Developer
---------

[](#developer)

Assuming you have `composer.phar` installed, it's simple to contribute to Selector, fork, clone your repository and run:

```
cd selector # your clone folder
composer.phar install --dev
vendor/bin/phpunit tests

```

And you are ready to write new tests, contributions and sending pull requests. ![:octocat:](https://github.githubassets.com/images/icons/emoji/octocat.png ":octocat:")

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/dd9ce08fd9750fa9846f4f9ec099d0705e9509e88f079893ef99b9d4ff87e29d?d=identicon)[danilo.cabello](/maintainers/danilo.cabello)

---

Top Contributors

[![cabello](https://avatars.githubusercontent.com/u/60936?v=4)](https://github.com/cabello "cabello (47 commits)")

### Embed Badge

![Health badge](/badges/cabello-selector/health.svg)

```
[![Health](https://phpackages.com/badges/cabello-selector/health.svg)](https://phpackages.com/packages/cabello-selector)
```

PHPackages © 2026

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