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
ffb2e54a
Commit
ffb2e54a
authored
8 years ago
by
Steevan BARBOYON
Browse files
Options
Download
Email Patches
Plain Diff
Throw \Esception when extra/composer-overload-cache-dir is not defined, write infos when verbose
parent
aa9488ec
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
OverloadClass.php
+43
-18
OverloadClass.php
README.md
+7
-4
README.md
changelog.md
+8
-1
changelog.md
with
58 additions
and
23 deletions
+58
-23
OverloadClass.php
+
43
-
18
View file @
ffb2e54a
...
...
@@ -3,6 +3,7 @@
namespace
steevanb\ComposerOverloadClass
;
use
Composer\Script\Event
;
use
Composer\IO\IOInterface
;
class
OverloadClass
{
...
...
@@ -14,6 +15,7 @@ class OverloadClass
/**
* @param Event $event
* @throws \Exception
*/
public
static
function
overload
(
Event
$event
)
{
...
...
@@ -21,14 +23,18 @@ class OverloadClass
if
(
$event
->
isDevMode
())
{
$envs
=
[
static
::
EXTRA_OVERLOAD_CLASS
,
static
::
EXTRA_OVERLOAD_CLASS_DEV
];
$cacheDir
=
static
::
EXTRA_OVERLOAD_CACHE_DIR_DEV
;
if
(
array_key_exists
(
$cacheDir
,
$extra
)
===
false
)
{
$cacheDir
=
static
::
EXTRA_OVERLOAD_CACHE_DIR
;
$cacheDir
Key
=
static
::
EXTRA_OVERLOAD_CACHE_DIR_DEV
;
if
(
array_key_exists
(
$cacheDir
Key
,
$extra
)
===
false
)
{
$cacheDir
Key
=
static
::
EXTRA_OVERLOAD_CACHE_DIR
;
}
}
else
{
$envs
=
[
static
::
EXTRA_OVERLOAD_CLASS
];
$cacheDir
=
static
::
EXTRA_OVERLOAD_CACHE_DIR
;
$cacheDirKey
=
static
::
EXTRA_OVERLOAD_CACHE_DIR
;
}
if
(
array_key_exists
(
$cacheDirKey
,
$extra
)
===
false
)
{
throw
new
\
Exception
(
'You must specify extra/'
.
$cacheDirKey
.
' in composer.json'
);
}
$cacheDir
=
$extra
[
$cacheDirKey
];
foreach
(
$envs
as
$extraKey
)
{
if
(
array_key_exists
(
$extraKey
,
$extra
))
{
...
...
@@ -39,9 +45,10 @@ class OverloadClass
foreach
(
$extra
[
$extraKey
]
as
$className
=>
$infos
)
{
static
::
generateProxy
(
$extra
[
$cacheDir
]
,
$cacheDir
,
$className
,
$infos
[
'original-file'
]
$infos
[
'original-file'
],
$event
->
getIO
()
);
$autoload
[
'classmap'
][
$className
]
=
$infos
[
'overload-file'
];
}
...
...
@@ -51,30 +58,48 @@ class OverloadClass
}
}
/**
* @param string $path
* @param IOInterface $io
*/
protected
function
createDirectories
(
$path
,
IOInterface
$io
)
{
if
(
is_dir
(
$path
)
===
false
)
{
$io
->
write
(
'Creating directory <info>'
.
$path
.
'</info>.'
,
true
,
IOInterface
::
VERBOSE
);
$createdPath
=
null
;
foreach
(
explode
(
DIRECTORY_SEPARATOR
,
$path
)
as
$directory
)
{
if
(
is_dir
(
$createdPath
.
$directory
)
===
false
)
{
mkdir
(
$createdPath
.
$directory
);
}
$createdPath
.
=
$directory
.
DIRECTORY_SEPARATOR
;
}
}
}
/**
* @param string $cacheDir
* @param string $fullyQualifiedClassName
* @param string $filePath
* @param IOInterface $io
* @return string
*/
protected
static
function
generateProxy
(
$cacheDir
,
$fullyQualifiedClassName
,
$filePath
)
protected
static
function
generateProxy
(
$cacheDir
,
$fullyQualifiedClassName
,
$filePath
,
IOInterface
$io
)
{
if
(
is_dir
(
$cacheDir
)
===
false
)
{
mkdir
(
$cacheDir
);
}
$php
=
static
::
getPhpForDuplicatedFile
(
$filePath
,
$fullyQualifiedClassName
);
$classNameParts
=
array_merge
(
array
(
static
::
NAMESPACE_PREFIX
),
explode
(
'\\'
,
$fullyQualifiedClassName
));
array_pop
(
$classNameParts
);
foreach
(
$classNameParts
as
$part
)
{
$cacheDir
.
=
DIRECTORY_SEPARATOR
.
$part
;
if
(
is_dir
(
$cacheDir
)
===
false
)
{
mkdir
(
$cacheDir
);
}
}
$finalCacheDir
=
$cacheDir
.
DIRECTORY_SEPARATOR
.
implode
(
DIRECTORY_SEPARATOR
,
$classNameParts
);
static
::
createDirectories
(
$finalCacheDir
,
$io
);
$overloadedFilePath
=
$
c
acheDir
.
DIRECTORY_SEPARATOR
.
basename
(
$filePath
);
$overloadedFilePath
=
$
finalC
acheDir
.
DIRECTORY_SEPARATOR
.
basename
(
$filePath
);
file_put_contents
(
$overloadedFilePath
,
$php
);
$io
->
write
(
'<info>'
.
$filePath
.
'</info> is overloaded by <comment>'
.
$overloadedFilePath
.
'</comment>'
,
true
,
IOInterface
::
VERBOSE
);
}
/**
...
...
This diff is collapsed.
Click to expand it.
README.md
+
7
-
4
View file @
ffb2e54a
[

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

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

](https://getcomposer.org)



[

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

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

](https://scrutinizer-ci.com/g/steevanb/composer-overload-class/)
composer-overload-class
...
...
@@ -21,11 +21,13 @@ Your class need to have exact same namespace as overloaded one, and you can exte

[
Changelog
](
changelog.md
)
Installation
------------
```
bash
composer require steevanb/composer-overload-class 1.
0.
*
composer require steevanb/composer-overload-class
^
1.
1
```
Configuration
...
...
@@ -65,6 +67,7 @@ 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
composer dumpautoload
-v
```
That's all folks !
...
...
This diff is collapsed.
Click to expand it.
changelog.md
+
8
-
1
View file @
ffb2e54a
1.1.2 (2016-12-28)
------------------
-
Throw
\E
xception 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 (2016-11-19)
------------------
...
...
@@ -14,7 +21,7 @@
-
Fix add use to ComposerOverloadClass
1.
0.0 (2016-07
)
17)
1.
0.0 (2016-07
-
17)
------------------
-
Create ComposerOverloadClass
...
...
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