2017 © Pedro Peláez
 

library anonymize

Converts an object/class into an anonymous class.

image

drupol/anonymize

Converts an object/class into an anonymous class.

  • Tuesday, February 27, 2018
  • by drupol
  • Repository
  • 2 Watchers
  • 0 Stars
  • 4 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Latest Stable Version GitHub stars Total Downloads Build Status Scrutinizer code quality Code Coverage Mutation testing badge License Say Thanks! Donate!, (*1)

Anonymize

Description

Convert a regular class into an anonymous class., (*2)

Features

  • Converts public properties and methods into dynamic classes and properties.

Requirements

  • PHP >= 7.1.3

Installation

composer require drupol/anonymize, (*3)

Usage

Using the object:, (*4)

<?php

include 'vendor/autoload.php';

class Hello
{
    public $property = 'YES!';

    public function say()
    {
        echo 'Hello ' . $this->world();
    }

    private function world()
    {
        return 'world!';
    }
}

$class = new Hello();
$class->say(); // Hello world!

$anonymizedClass = \drupol\Anonymize\Anonymize::convertToAnonymous($class);

$anonymizedClass::addDynamicMethod('say', function () use ($anonymizedClass) {
    echo 'Goodbye ' . $anonymizedClass->world();
});

$anonymizedClass::addDynamicMethod('world', function () {
    return 'universe!';
});

$anonymizedClass->say(); // Goodbye universe!

API

<?php

/**
 * Convert an object into an anonymous object.
 *
 * @param \stdClass $object
 *   The object to convert.  
 *
 * @return Anonymize
 */
AnonymizeTrait::convertToAnonymous($object);

The rest of the library API relies and inherit from DynamicObjects., (*5)

Code quality, tests and benchmarks

Every time changes are introduced into the library, Travis CI run the tests and the benchmarks., (*6)

The library has tests written with PHPSpec. Feel free to check them out in the spec directory. Run composer phpspec to trigger the tests., (*7)

Before each commit some inspections are executed with GrumPHP, run ./vendor/bin/grumphp run to check manually., (*8)

PHPInfection is used to ensure that your code is properly tested, run composer infection to test your code., (*9)

Contributing

Feel free to contribute to this library by sending Github pull requests. I'm quite reactive :-), (*10)

Sponsors

The Versions