PHPackages                             horat1us/php-method-injection - 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. horat1us/php-method-injection

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

horat1us/php-method-injection
=============================

PHP Trait to inject methods

1.0.0(9y ago)11.5kMITPHPPHP &gt;=7.0

Since May 8Pushed 9y ago2 watchersCompare

[ Source](https://github.com/Horat1us/php-method-injection)[ Packagist](https://packagist.org/packages/horat1us/php-method-injection)[ RSS](/packages/horat1us-php-method-injection/feed)WikiDiscussions master Synced 1w ago

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

PHP Method Injection Trait
==========================

[](#php-method-injection-trait)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/66dd20dcedcfee0aba47ba96784104d72ed821a0dcd15c88aceaee89692f25e9/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f486f7261743175732f7068702d6d6574686f642d696e6a656374696f6e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Horat1us/php-method-injection/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/d3baeb39c668342f19a1099d2e057f8dca7bf19bc0d308a8913bf925571f3264/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f486f7261743175732f7068702d6d6574686f642d696e6a656374696f6e2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Horat1us/php-method-injection/?branch=master)[![Build Status](https://camo.githubusercontent.com/60eb9363eeea990b1ff542cf5d18d806eef4d371d20355db13a579c34a8be2ad/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f486f7261743175732f7068702d6d6574686f642d696e6a656374696f6e2f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Horat1us/php-method-injection/build-status/master)[![Latest Stable Version](https://camo.githubusercontent.com/a51673a6599c29a681f2922db33fb274b107e16b2dbd61b4d50bd546da4d760d/68747470733a2f2f706f7365722e707567782e6f72672f686f7261743175732f7068702d6d6574686f642d696e6a656374696f6e2f762f737461626c65)](https://packagist.org/packages/horat1us/php-method-injection)[![Total Downloads](https://camo.githubusercontent.com/fa7aa2d42497d26af1476ad1972e43c97ee52aaef149ef48fa9256c3e04e5e18/68747470733a2f2f706f7365722e707567782e6f72672f686f7261743175732f7068702d6d6574686f642d696e6a656374696f6e2f646f776e6c6f616473)](https://packagist.org/packages/horat1us/php-method-injection)[![License](https://camo.githubusercontent.com/4a48092192942306e9d5f1c364102be18047502de9fb5d5977734501fdd1152d/68747470733a2f2f706f7365722e707567782e6f72672f686f7261743175732f7068702d6d6574686f642d696e6a656374696f6e2f6c6963656e7365)](https://packagist.org/packages/horat1us/php-method-injection)

This trait allows you to extend your object with custom method dynamically.

Usage
-----

[](#usage)

You can use **DynamicObject**or implement interface **InjectMethodsInterface** with trait **InjectMethods** on your custom object.

[Simple example](./examples/simple-object.php) will output:

```
Hello, Alexander
Hello, Letnikow
Array
(
    [arguments] => Array
        (
            [0] => Man
        )

    [methodName] => welcome
    [object] => Horat1us\MethodInjection\DynamicObject
    [message] => Injected method welcome not found in Horat1us\MethodInjection\DynamicObject
)

```

About
-----

[](#about)

This package is created for using in tests. For example, you have interface

```
