Skip to content

Commit

Permalink
Add replace configuration to indicate if you want to duplicate origi…
Browse files Browse the repository at this point in the history
…nal classe or not
  • Loading branch information
steevanb committed Jun 29, 2017
1 parent 6a06329 commit e90e59b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 32 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vendor/
.idea/
18 changes: 12 additions & 6 deletions OverloadClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class OverloadClass
const EXTRA_OVERLOAD_CACHE_DIR_DEV = 'composer-overload-cache-dir-dev';
const EXTRA_OVERLOAD_CLASS = 'composer-overload-class';
const EXTRA_OVERLOAD_CLASS_DEV = 'composer-overload-class-dev';
const EXTRA_OVERLOAD_DUPLICATE_ORIGINAL_FILE = 'duplicate-original-file';
const NAMESPACE_PREFIX = 'ComposerOverloadClass';

/**
Expand Down Expand Up @@ -44,12 +45,17 @@ public static function overload(Event $event)
}

foreach ($extra[$extraKey] as $className => $infos) {
static::generateProxy(
$cacheDir,
$className,
$infos['original-file'],
$event->getIO()
);
if (
array_key_exists(static::EXTRA_OVERLOAD_DUPLICATE_ORIGINAL_FILE, $infos) === false
|| $infos[static::EXTRA_OVERLOAD_DUPLICATE_ORIGINAL_FILE] === false
) {
static::generateProxy(
$cacheDir,
$className,
$infos['original-file'],
$event->getIO()
);
}
$autoload['classmap'][$className] = $infos['overload-file'];
}

Expand Down
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[![version](https://img.shields.io/badge/version-1.1.3-green.svg)](https://github.com/steevanb/composer-overload-class/tree/1.1.3)
[![version](https://img.shields.io/badge/version-1.2.0-green.svg)](https://github.com/steevanb/composer-overload-class/tree/1.2.0)
[![composer](https://img.shields.io/badge/composer-^1.0-blue.svg)](https://getcomposer.org)
![Lines](https://img.shields.io/badge/code%20lines-431-green.svg)
![Lines](https://img.shields.io/badge/code%20lines-444-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/8)
[![SensionLabsInsight](https://img.shields.io/badge/SensionLabsInsight-platinum-brightgreen.svg)](https://insight.sensiolabs.com/projects/a753e540-2863-444f-a174-d743ca475566/analyses/15)
[![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
Expand All @@ -27,7 +27,7 @@ Installation
------------

```bash
composer require steevanb/composer-overload-class ^1.1
composer require steevanb/composer-overload-class ^1.2
```

Configuration
Expand Down Expand Up @@ -55,7 +55,10 @@ Example taken from [steevanb/doctrine-stats](https://github.com/steevanb/doctrin
"__comment": "Path to original file, who contains the class you want to overload",
"original-file": "vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php",
"__comment": "Path to your file, who contains your class",
"overload-file": "vendor/steevanb/doctrine-stats/ComposerOverloadClass/Doctrine/ORM/Internal/ObjectHydrator.php"
"overload-file": "vendor/steevanb/doctrine-stats/ComposerOverloadClass/Doctrine/ORM/Internal/ObjectHydrator.php",
"__comment": "false (default) : duplicate original class, add ComposerOverloadClass namespace prefix, you can extend it",
"__comment": "true : do not duplicate original class, you need to write all code in your classe",
"duplicate-original-file": false
}
},
"__comment": "Classes to overload, in dev env",
Expand All @@ -67,6 +70,8 @@ Example taken from [steevanb/doctrine-stats](https://github.com/steevanb/doctrin
When configuration is finished, you need to re-generate Composer autoload :
```bash
composer dumpautoload

# show overrided files
composer dumpautoload -v
```

Expand All @@ -79,7 +84,6 @@ Example taken from steevanb/doctrine-stats, to overload Doctrine ObjectHydrator,

```php
# src/ComposerOverloadClass/Doctrine/ORM/Internal/ObjectHydrator.php
<?php

namespace Doctrine\ORM\Internal\Hydration;

Expand Down
38 changes: 18 additions & 20 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
1.1.3 (2016-12-28)
------------------
### [1.2.0](../../compare/1.1.3...1.2.0) (2017-05-29)

- Add static to OverloadClass::createDirectories()
- Add ```duplicate-original-file``` configuration to indicate if you want to duplicate original classe or not

1.1.2 (2016-12-28)
------------------
### [1.1.3](../../compare/1.1.2...1.1.3) (2016-12-28)

- Throw \Exception if extra/composer-overload-cache-dir is not defined in composer.json
- Write Creating dir when composer is called with -v
- Write Foo.php is overloaded by Bar.php when composer is called with -v
- Add ```static``` to ```OverloadClass::createDirectories()```

1.1.1 (2016-11-19)
------------------
### [1.1.2](../../compare/1.1.1...1.1.2) (2016-12-28)

- Throw \Exception if ```extra/composer-overload-cache-dir``` is not defined in composer.json
- Write ```Creating dir``` when composer is called with -v
- Write ```Foo.php is overloaded by Bar.php when``` composer is called with -v

### [1.1.1 ](../../compare/1.1.0...1.1.1) (2016-11-19)

- Create cache dir if not exists

1.1.0 (2016-07-19)
------------------
### [1.1.0](../../compare/1.0.1...1.1.0) (2016-07-19)

- Add extra/composer-overload-cache-dir-dev to set cache dir in dev
- Add extra/composer-overload-class-dev to define classes to overload in dev
- Add ```extra/composer-overload-cache-dir-dev``` to set cache dir in dev
- Add ```extra/composer-overload-class-dev``` to define classes to overload in dev

1.0.1 (2016-07-19)
------------------
### [1.0.1](../../compare/1.0.0...1.0.1) (2016-07-19)

- Fix add use to ComposerOverloadClass

1.0.0 (2016-07-17)
------------------
### 1.0.0 (2016-07-17)

- Create ComposerOverloadClass
- OverloadClass::overload() create a clone of original class, prefix it's namespace with ComposerOverloadClass, and add use if needed (only for extends class name)
- Create ```ComposerOverloadClass```
- ```OverloadClass::overload()``` create a clone of original class, prefix it's namespace with ```ComposerOverloadClass```, and add use if needed (only for extends class name)

0 comments on commit e90e59b

Please sign in to comment.