Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Meiji
Composer Overload Class
Commits
bc944e08
Commit
bc944e08
authored
7 years ago
by
Steevan BARBOYON
Browse files
Options
Download
Email Patches
Plain Diff
Use files instead of classmap, add non used files into exclude-from-classmap
parent
e90e59b7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
OverloadClass.php
+56
-8
OverloadClass.php
README.md
+8
-10
README.md
changelog.md
+5
-0
changelog.md
with
69 additions
and
18 deletions
+69
-18
OverloadClass.php
+
56
-
8
View file @
bc944e08
...
...
@@ -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
;
}
/**
...
...
This diff is collapsed.
Click to expand it.
README.md
+
8
-
10
View file @
bc944e08
[

](https://github.com/steevanb/composer-overload-class/tree/1.
2
.0)
[

](https://github.com/steevanb/composer-overload-class/tree/1.
3
.0)
[

](https://getcomposer.org)



[

](https://insight.sensiolabs.com/projects/a753e540-2863-444f-a174-d743ca475566/analyses/1
5
)
[

](https://insight.sensiolabs.com/projects/a753e540-2863-444f-a174-d743ca475566/analyses/1
6
)
[

](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
\B
ar()" 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
();
...
...
This diff is collapsed.
Click to expand it.
changelog.md
+
5
-
0
View file @
bc944e08
### [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
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help