castiron/typo3-extbaseinstantiable

This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.

Small easy extbase object instantiation

1.0.1 2018-06-05 06:35 UTC

This package is not auto-updated.

Last update: 2021-06-03 17:41:44 UTC


README

This package provides a mixin (read: trait) that lets you bestow the power of self-instantiation (using TYPO3 conventional mechanisms) to your classes. Add this mixin to any class to make it instantiable using the Extbase ObjectManager with ease.

Interface

Once you've mixed the trait into your class, you can call MyClass::get() to get an instance of the class.

Detailed usage

/**
 * Class MyClass
 */
class MyClass
{
    use \Castiron\ExtbaseInstantiable\Traits\ExtbaseInstantiable;

    /**
     * Some public interface
     */
    public function execute()
    {
        // yadda yadda whatever
    }
}

/**
 * Instantiate (with ObjectManager) and call a public method.
 */
MyClass::get()->execute();

Why do I want this?

A couple of reasons why this is handy:

  • It makes instantiating your class in TYPO3-world easy-peasy (vs GeneralUtility::makeInstance or ObjectManager::get called directly)
  • It uses ObjectManager::get under the hood, so automatic dependency injection works if you use annotations like @inject

FAQ

Will it also respect marker interfaces like SingletonInterface?

Yes! It's using normal TYPO3 object instantiation under the hood, so all that weirdo magic will work.

Installation

composer require castiron/typo3-extbaseinstantiable