Skip to content

Commit

Permalink
Merge pull request #2 from steevanb/fix-directory-separator
Browse files Browse the repository at this point in the history
  Replace DIRECTORY_SEPARATOR by / for Windows users
  • Loading branch information
steevanb committed Dec 5, 2019
2 parents 13524cd + ad0b1b3 commit ad1f722
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 40 deletions.
42 changes: 12 additions & 30 deletions OverloadClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ class OverloadClass
const EXTRA_OVERLOAD_DUPLICATE_ORIGINAL_FILE = 'duplicate-original-file';
const NAMESPACE_PREFIX = 'ComposerOverloadClass';

/**
* @param Event $event
* @throws \Exception
*/
public static function overload(Event $event)
{
static::defineAutoloadExcludeFromClassmap($event);
Expand Down Expand Up @@ -99,10 +95,7 @@ protected static function defineAutoloadFiles(Event $event)
$event->getComposer()->getPackage()->setAutoload($autoload);
}

/**
* @param Event $event
* @return array
*/
/** @return array */
protected static function getAutoload(Event $event)
{
$return = $event->getComposer()->getPackage()->getAutoload();
Expand All @@ -116,21 +109,18 @@ protected static function getAutoload(Event $event)
return $return;
}

/**
* @param string $path
* @param IOInterface $io
*/
/** @param string $path */
protected static 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) {
foreach (explode('/', $path) as $directory) {
if (is_dir($createdPath . $directory) === false) {
mkdir($createdPath . $directory);
}
$createdPath .= $directory . DIRECTORY_SEPARATOR;
$createdPath .= $directory . '/';
}
}
}
Expand All @@ -139,22 +129,25 @@ protected static function createDirectories($path, IOInterface $io)
* @param string $cacheDir
* @param string $fullyQualifiedClassName
* @param string $filePath
* @param IOInterface $io
* @return string
*/
protected static function generateProxy($cacheDir, $fullyQualifiedClassName, $filePath, IOInterface $io)
{
$php = static::getPhpForDuplicatedFile($filePath, $fullyQualifiedClassName);
$classNameParts = array_merge(array(static::NAMESPACE_PREFIX), explode('\\', $fullyQualifiedClassName));
array_pop($classNameParts);
$finalCacheDir = $cacheDir . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $classNameParts);
$finalCacheDir = $cacheDir . '/' . implode('/', $classNameParts);
static::createDirectories($finalCacheDir, $io);

$overloadedFilePath = $finalCacheDir . DIRECTORY_SEPARATOR . basename($filePath);
$overloadedFilePath = $finalCacheDir . '/' . basename($filePath);
file_put_contents($overloadedFilePath, $php);

$io->write(
'Generate proxy for <info>' . $fullyQualifiedClassName . '</info> in <comment>' . $overloadedFilePath . '</comment>',
'Generate proxy for <info>'
. $fullyQualifiedClassName
. '</info> in <comment>'
. $overloadedFilePath
. '</comment>',
true,
IOInterface::VERBOSE
);
Expand All @@ -164,7 +157,6 @@ protected static function generateProxy($cacheDir, $fullyQualifiedClassName, $fi
* @param string $filePath
* @param string $fullyQualifiedClassName
* @return string
* @throws \Exception
*/
protected static function getPhpForDuplicatedFile($filePath, $fullyQualifiedClassName)
{
Expand Down Expand Up @@ -224,10 +216,8 @@ protected static function getPhpForDuplicatedFile($filePath, $fullyQualifiedClas
}

/**
* @param array $classFound
* @param string $fullyQualifiedClassName
* @param string $filePath
* @throws \Exception
*/
protected static function assertOnlyRightClassFound(array $classFound, $fullyQualifiedClassName, $filePath)
{
Expand Down Expand Up @@ -257,10 +247,8 @@ protected static function replaceNamespace($namespace, $phpCodeForNamespace, &$p
}

/**
* @param array $tokens
* @param int $index
* @return string
* @throws \Exception
*/
protected static function getClassNameFromTokens(array &$tokens, $index)
{
Expand Down Expand Up @@ -296,8 +284,6 @@ protected static function getClassNameFromTokens(array &$tokens, $index)
/**
* @param string $className
* @param string $namespace
* @param array $uses
* @param array $addUses
*/
protected static function addUse($className, $namespace, array $uses, array &$addUses)
{
Expand All @@ -315,11 +301,7 @@ protected static function addUse($className, $namespace, array $uses, array &$ad
}
}

/**
* @param array $addUses
* @param array $phpLines
* @param int $line
*/
/** @param int $line */
protected static function addUsesInPhpLines(array $addUses, array &$phpLines, $line)
{
$linesBefore = ($line > 0) ? array_slice($phpLines, 0, $line) : [];
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
[![version](https://img.shields.io/badge/version-1.3.2-green.svg)](https://github.com/steevanb/composer-overload-class/tree/1.3.2)
[![version](https://img.shields.io/badge/version-1.3.3-green.svg)](https://github.com/steevanb/composer-overload-class/tree/1.3.3)
[![composer](https://img.shields.io/badge/composer-^1.0-blue.svg)](https://getcomposer.org)
![Lines](https://img.shields.io/badge/code%20lines-508-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/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
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### [1.3.3](../../compare/1.3.2...1.3.3) (2019-12-05)

- Replace `DIRECTORY_SEPARATOR` by `/` for Windows users

### [1.3.2](../../compare/1.3.1...1.3.2) (2017-07-12)

- Add _Generate proxy for Foo in Bar_ message in verbose mode, when _duplicate-original-file_ is not set or set to _true_
Expand Down
12 changes: 4 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@
"description": "Add extra to composer.json, to overload autoloaded class",
"minimum-stability": "dev",
"autoload": {
"psr-4": { "steevanb\\ComposerOverloadClass\\": "" }
"psr-4": {
"steevanb\\ComposerOverloadClass\\": ""
}
},
"require": {
"php": "^5.4.0 || ^7.0"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/steevanb/composer-overload-class.git"
}
]
}
}

0 comments on commit ad1f722

Please sign in to comment.