Commit bc944e08 authored by Steevan BARBOYON's avatar Steevan BARBOYON
Browse files

Use files instead of classmap, add non used files into exclude-from-classmap

parent e90e59b7
Showing with 69 additions and 18 deletions
+69 -18
......@@ -19,6 +19,40 @@ class OverloadClass
* @throws \Exception
*/
public static function overload(Event $event)
{
static::defineAutoloadExcludeFromClassmap($event);
static::defineAutoloadFiles($event);
}
protected static function defineAutoloadExcludeFromClassmap(Event $event)
{
$originalFiles = ($event->isDevMode())
? [static::EXTRA_OVERLOAD_CLASS, static::EXTRA_OVERLOAD_CLASS_DEV]
: [static::EXTRA_OVERLOAD_CLASS];
$overloadFiles = ($event->isDevMode()) ? [] : [static::EXTRA_OVERLOAD_CLASS_DEV];
$autoload = static::getAutoload($event);
$extra = $event->getComposer()->getPackage()->getExtra();
foreach ($originalFiles as $env) {
if (array_key_exists($env, $extra)) {
foreach ($extra[$env] as $className => $infos) {
$autoload['exclude-from-classmap'][] = $infos['original-file'];
}
}
}
foreach ($overloadFiles as $env) {
if (array_key_exists($env, $extra)) {
foreach ($extra[$env] as $className => $infos) {
$autoload['exclude-from-classmap'][] = $infos['overload-file'];
}
}
}
$event->getComposer()->getPackage()->setAutoload($autoload);
}
protected static function defineAutoloadFiles(Event $event)
{
$extra = $event->getComposer()->getPackage()->getExtra();
......@@ -37,13 +71,10 @@ class OverloadClass
}
$cacheDir = $extra[$cacheDirKey];
$autoload = static::getAutoload($event);
foreach ($envs as $extraKey) {
if (array_key_exists($extraKey, $extra)) {
$autoload = $event->getComposer()->getPackage()->getAutoload();
if (array_key_exists('classmap', $autoload) === false) {
$autoload['classmap'] = array();
}
foreach ($extra[$extraKey] as $className => $infos) {
if (
array_key_exists(static::EXTRA_OVERLOAD_DUPLICATE_ORIGINAL_FILE, $infos) === false
......@@ -56,12 +87,29 @@ class OverloadClass
$event->getIO()
);
}
$autoload['classmap'][$className] = $infos['overload-file'];
$autoload['files'][$className] = $infos['overload-file'];
}
$event->getComposer()->getPackage()->setAutoload($autoload);
}
}
$event->getComposer()->getPackage()->setAutoload($autoload);
}
/**
* @param Event $event
* @return array
*/
protected static function getAutoload(Event $event)
{
$return = $event->getComposer()->getPackage()->getAutoload();
if (array_key_exists('files', $return) === false) {
$return['files'] = array();
}
if (array_key_exists('exclude-from-classmap', $return) === false) {
$return['exclude-from-classmap'] = array();
}
return $return;
}
/**
......
[![version](https://img.shields.io/badge/version-1.2.0-green.svg)](https://github.com/steevanb/composer-overload-class/tree/1.2.0)
[![version](https://img.shields.io/badge/version-1.3.0-green.svg)](https://github.com/steevanb/composer-overload-class/tree/1.3.0)
[![composer](https://img.shields.io/badge/composer-^1.0-blue.svg)](https://getcomposer.org)
![Lines](https://img.shields.io/badge/code%20lines-444-green.svg)
![Lines](https://img.shields.io/badge/code%20lines-495-green.svg)
![Total Downloads](https://poser.pugx.org/steevanb/composer-overload-class/downloads)
[![SensionLabsInsight](https://img.shields.io/badge/SensionLabsInsight-platinum-brightgreen.svg)](https://insight.sensiolabs.com/projects/a753e540-2863-444f-a174-d743ca475566/analyses/15)
[![SensionLabsInsight](https://img.shields.io/badge/SensionLabsInsight-platinum-brightgreen.svg)](https://insight.sensiolabs.com/projects/a753e540-2863-444f-a174-d743ca475566/analyses/16)
[![Scrutinizer](https://scrutinizer-ci.com/g/steevanb/composer-overload-class/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/steevanb/composer-overload-class/)
composer-overload-class
-----------------------
Allow to overload autoloaded classes, to include your files instead of supposed ones.
Sometimes, you need to overload a class from a dependency. But you can't, cause you've found a nice "new Foo\Bar()" somewhere in this dependency...
......@@ -27,7 +28,7 @@ Installation
------------
```bash
composer require steevanb/composer-overload-class ^1.2
composer require steevanb/composer-overload-class ^1.3
```
Configuration
......@@ -90,20 +91,17 @@ namespace Doctrine\ORM\Internal\Hydration;
use Doctrine\ORM\EntityManagerInterface;
use steevanb\DoctrineStats\Doctrine\ORM\Event\HydrationEventsTrait;
# extends cloned ObjectHydrator class, i just want to change hydrateAllData() code
# extends cloned ObjectHydrator class, I just want to change hydrateAllData() code
class ObjectHydrator extends \ComposerOverloadClass\Doctrine\ORM\Internal\Hydration\ObjectHydrator
{
use HydrationEventsTrait;
/**
* @return EntityManagerInterface
*/
protected function getEntityManager()
protected function getEntityManager(): EntityManagerInterface
{
return $this->_em;
}
protected function hydrateAllData()
protected function hydrateAllData(): void
{
$eventId = $this->dispatchPreHydrationEvent();
parent::hydrateAllData();
......
### [1.3.0](../../compare/1.2.0...1.3.0) (2017-07-12)
- Use _files_ instead of _classmap_ Composer configuration to overload classes
- Add non used files into _exclude-from-classmap_ Composer configuration to fix _Ambiguous class resolution_ warning
### [1.2.0](../../compare/1.1.3...1.2.0) (2017-05-29)
- Add ```duplicate-original-file``` configuration to indicate if you want to duplicate original classe or not
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment