PHPackages                             exorg/decapsulator - 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. exorg/decapsulator

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

exorg/decapsulator
==================

Decapsulating objects wrapper.

2.0.0(2y ago)01142[1 issues](https://github.com/exorg/php-decapsulator/issues)MITPHPPHP 8.1 - 8.3

Since Mar 7Pushed 2y ago1 watchersCompare

[ Source](https://github.com/exorg/php-decapsulator)[ Packagist](https://packagist.org/packages/exorg/decapsulator)[ RSS](/packages/exorg-decapsulator/feed)WikiDiscussions develop Synced today

READMEChangelogDependencies (2)Versions (5)Used By (0)

Decapsulator
============

[](#decapsulator)

Decapsulating objects wrapper. Allows easy access to non-public properties and methods.

Getting Started
---------------

[](#getting-started)

### Prerequisities

[](#prerequisities)

- [PHP](https://www.php.net/) 8.1 - 8.3
- [Git](https://git-scm.com/) 2.25.1+
- [Composer](https://getcomposer.org/) 2.6.0+

The instruction assumes using the Linux operating system or compatible tools for other operating systems.

### Installation

[](#installation)

#### php8.\*-cli, Git and Composer required

[](#php8-cli-git-and-composer-required)

The recommended way to install DataCoder into the source code of the project is to handle it as code dependency by [Composer](http://getcomposer.org). [Git](https://git-scm.com/) is needed to fetch packages from version control repositories.

The *php8.\*-cli* is needed for installing Composer.

#### DataCoder installation

[](#datacoder-installation)

Add to your **composer.json** file appropriate entry by running the following command

```
composer require exorg/decapsulator
```

If it's project set-up stage and no one dependency have been installed yet, run

```
composer install
```

If another dependencies have been intalled previously, run

```
composer update
```

Usage
-----

[](#usage)

The simplest way to autoload all needed files in executable file is attaching *autoload.php* file generated by Composer (after running `composer install` or `composer update` command) like in following example

```
require_once (__DIR__ . '/vendor/autoload.php');
```

**Class of the fixture that will be decapsulated**

```
declare(strict_types=1);

class DemoClass
{
    /**
     * Public static property.
     *
     * @var mixed
     */
    public static $publicStaticProperty;

    /**
     * Protected static property.
     *
     * @var mixed
     */
    protected static $protectedStaticProperty;

    /**
     * Private static property.
     *
     * @var mixed
     */
    private static $privateStaticProperty;

    /**
     * Public property.
     *
     * @var mixed
     */
    public $publicProperty;

    /**
     * Protected property.
     *
     * @var mixed
     */
    protected $protectedProperty;

    /**
     * Private property.
     *
     * @var mixed
     */
    private $privateProperty;

    /**
     * Public static method with no arguments.
     *
     * @return string
     */
    public static function publicStaticMethodWithNoArguments()
    {
        return 'public:static:no-arguments';
    }

    /**
     * Protected static method with no arguments.
     *
     * @return string
     */
    protected static function protectedStaticMethodWithNoArguments()
    {
        return 'protected:static:no-arguments';
    }

    /**
     * Private static method with no arguments.
     *
     * @return string
     */
    private static function privateStaticMethodWithNoArguments()
    {
        return 'private:static:no-arguments';
    }

    /**
     * Public static method with arguments.
     *
     * @param mixed $argument1
     * @param mixed $argument2
     *
     * @return string
     */
    public static function publicStaticMethodWithArguments($argument1, $argument2)
    {
        return 'public:static:arguments:' . $argument1 . '+' . $argument2;
    }

    /**
     * Protected static method with arguments.
     *
     * @param mixed $argument1
     * @param mixed $argument2
     *
     * @return string
     */
    protected static function protectedStaticMethodWithArguments($argument1, $argument2)
    {
        return 'protected:static:arguments:' . $argument1 . '+' . $argument2;
    }

    /**
     * Private static method with arguments.
     *
     * @param mixed $argument1
     * @param mixed $argument2
     *
     * @return string
     */
    private static function privateStaticMethodWithArguments($argument1, $argument2)
    {
        return 'private:static:arguments:' . $argument1 . '+' . $argument2;
    }

    /**
     * Public method with no arguments.
     *
     * @return string
     */
    public function publicMethodWithNoArguments()
    {
        return 'public:no-arguments';
    }

    /**
     * Protected method with no arguments.
     *
     * @return string
     */
    protected function protectedMethodWithNoArguments()
    {
        return 'protected:no-arguments';
    }

    /**
     * Private method with no arguments.
     *
     * @return string
     */
    private function privateMethodWithNoArguments()
    {
        return 'private:no-arguments';
    }

    /**
     * Public method with arguments.
     *
     * @param mixed $argument1
     * @param mixed $argument2
     *
     * @return string
     */
    public function publicMethodWithArguments($argument1, $argument2)
    {
        return 'public:arguments:' . $argument1 . '+' . $argument2;
    }

    /**
     * Protected method with arguments.
     *
     * @param mixed $argument1
     * @param mixed $argument2
     *
     * @return string
     */
    protected function protectedMethodWithArguments($argument1, $argument2)
    {
        return 'protected:arguments:' . $argument1 . '+' . $argument2;
    }

    /**
     * Private method with arguments.
     *
     * @param mixed $argument1
     * @param mixed $argument2
     *
     * @return string
     */
    private function privateMethodWithArguments($argument1, $argument2)
    {
        return 'private:arguments:' . $argument1 . '+' . $argument2;
    }
}
```

### Properties decapsulation

[](#properties-decapsulation)

Static class properties are accessed from the class instance the same way as non-static.

```
require_once (__DIR__ . '/../vendor/autoload.php');
require_once (__DIR__ . '/DemoClass.php');

use ExOrg\Decapsulator\ObjectDecapsulator;

$object = new DemoClass();
$decapsulatedObject = ObjectDecapsulator::buildForObject($object);

$decapsulatedObject->privateStaticProperty = 2;
print('Private static property: ' . $decapsulatedObject->privateStaticProperty . PHP_EOL);

$decapsulatedObject->protectedStaticProperty = 4;
print('Protected static property: ' . $decapsulatedObject->protectedStaticProperty . PHP_EOL);

$decapsulatedObject->publicStaticProperty = 8;
print('Public static property: ' . $decapsulatedObject->publicStaticProperty . PHP_EOL);

$decapsulatedObject->privateProperty = 16;
print('Private property: ' . $decapsulatedObject->privateProperty . PHP_EOL);

$decapsulatedObject->protectedProperty = 32;
print('Protected property: ' . $decapsulatedObject->protectedProperty . PHP_EOL);

$decapsulatedObject->publicProperty = 64;
print('Public property: ' . $decapsulatedObject->publicProperty . PHP_EOL);
```

---

```
Private static property: 2
Protected static property: 4
Public static property: 8
Private property: 16
Protected property: 32
Public property: 64
```

### Methods decapsulation

[](#methods-decapsulation)

**Example file snippet**

Static class methods are accessed from the class instance the same way as non-static.

```
require_once (__DIR__ . '/../vendor/autoload.php');
require_once (__DIR__ . '/DemoClass.php');

use ExOrg\Decapsulator\ObjectDecapsulator;

$object = new DemoClass();
$decapsulatedObject = ObjectDecapsulator::buildForObject($object);

$result = $decapsulatedObject->privateStaticMethodWithNoArguments();
print('Private static method with no arguments result: ' . $result . PHP_EOL);

$result = $decapsulatedObject->protectedStaticMethodWithNoArguments();
print('Protected static method with no arguments result: ' . $result . PHP_EOL);

$result = $decapsulatedObject->publicStaticMethodWithNoArguments();
print('Public static method with no arguments result: ' . $result . PHP_EOL);

$result = $decapsulatedObject->privateStaticMethodWithArguments('rose', 'orange');
print('Private static method with arguments result: ' . $result . PHP_EOL);

$result = $decapsulatedObject->protectedStaticMethodWithArguments('violet', 'apple');
print('Protected static method with arguments result: ' . $result . PHP_EOL);

$result = $decapsulatedObject->publicStaticMethodWithArguments('orchid', 'plum');
print('Public static method with arguments result: ' . $result . PHP_EOL);

$result = $decapsulatedObject->privateMethodWithNoArguments();
print('Private method with no arguments result: ' . $result . PHP_EOL);

$result = $decapsulatedObject->protectedMethodWithNoArguments();
print('Protected method with no arguments result: ' . $result . PHP_EOL);

$result = $decapsulatedObject->publicMethodWithNoArguments();
print('Public method with no arguments result: ' . $result . PHP_EOL);

$result = $decapsulatedObject->privateMethodWithArguments('daisy', 'lemon');
print('Private method with arguments result: ' . $result . PHP_EOL);

$result = $decapsulatedObject->protectedMethodWithArguments('myosote', 'pear');
print('Protected method with arguments result: ' . $result . PHP_EOL);

$result = $decapsulatedObject->publicMethodWithArguments('dandelion', 'peach');
print('Public method with arguments result: ' . $result . PHP_EOL);
```

---

```
Private static method with no arguments result: private:static:no-arguments
Protected static method with no arguments result: protected:static:no-arguments
Public static method with no arguments result: public:static:no-arguments
Private static method with arguments result: private:static:arguments:rose+orange
Protected static method with arguments result: protected:static:arguments:violet+apple
Public static method with arguments result: public:static:arguments:orchid+plum
Private method with no arguments result: private:no-arguments
Protected method with no arguments result: protected:no-arguments
Public method with no arguments result: public:no-arguments
Private method with arguments result: private:arguments:daisy+lemon
Protected method with arguments result: protected:arguments:myosote+pear
Public method with arguments result: public:arguments:dandelion+peach
```

Tests
-----

[](#tests)

### Unit tests

[](#unit-tests)

This project has unit tests, which has been built with [PHPUnit](https://phpunit.de/) framework and run on Linux operating system.

To run tests, write the following command in your command line inside the main DataCoder project directory

```
vendor/bin/phpunit tests/
```

or use a Composer script

```
composer test
```

### Code style tests

[](#code-style-tests)

This code follows [PSR-1](http://www.php-fig.org/psr/psr-1/) and [PSR-12](http://www.php-fig.org/psr/psr-12/) standards.

To run tests for code style write the following command in your command line inside the main DataCoder project directory

```
vendor/bin/phpcs tests/ src/
```

or use a Composer script

```
composer sniff
```

You can also use a Composer script for running both tests and check code style

```
composer check
```

Built with
----------

[](#built-with)

- [Linux Mint](https://www.linuxmint.com/)
- [Visual Studio Code](https://code.visualstudio.com/)
- [Remarkable](https://remarkableapp.github.io/)
- [PHPUnit](https://phpunit.de/)
- [PHPCodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer)
- [Composer](https://getcomposer.org/)
- [Git](https://git-scm.com/)
- [GitHub](https://github.com/)

Versioning
----------

[](#versioning)

This project is versioning according to [SemVer](http://semver.org/) versioning standars. All available [releases](https://github.com/ExOrg/php-data-coder/releases) are [tagged](https://github.com/ExOrg/php-data-coder/tags).

Contributing
------------

[](#contributing)

Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on the code of conduct, and the process for submitting pull requests.

Author
------

[](#author)

- **Katarzyna Krasińska** - [katheroine](https://github.com/katheroine), [ExOrg](https://github.com/ExOrg)

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details.

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity81

Battle-tested with a long release history

 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 ~3346 days

Total

2

Last Release

789d ago

Major Versions

1.0 → 2.0.02024-05-04

PHP version history (2 changes)1.0PHP &gt;=5.5.9

2.0.0PHP 8.1 - 8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/3badf4e45129f57e587c47263f636b4f1954510d37e8b6db26ceef778e5834ee?d=identicon)[katheroine](/maintainers/katheroine)

---

Top Contributors

[![katheroine](https://avatars.githubusercontent.com/u/3116336?v=4)](https://github.com/katheroine "katheroine (65 commits)")

---

Tags

exorgdecapsulatorphp-decapsulator

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/exorg-decapsulator/health.svg)

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

###  Alternatives

[liquidweb/htaccess-validator-shell

Shell script for linting and validating Apache2 Htaccess files

1750.1k1](/packages/liquidweb-htaccess-validator-shell)[beste/latlon-geohash

Gustavo Niemeyer's geocoding system

1059.7k](/packages/beste-latlon-geohash)[trendyminds/visor

A simple admin overlay to get to the relevant areas of the Craft CMS control panel

248.2k](/packages/trendyminds-visor)

PHPackages © 2026

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