Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8e20aa3
Add classmap output
BrianHenryIE Apr 10, 2020
0ce198d
Missed some copying and pasting
BrianHenryIE Apr 10, 2020
dbeea02
Merge branch 'Regex-fix-for-preceeding-backslash'
BrianHenryIE May 22, 2020
fb75567
Merge branch 'Use-getRealPath-for-symlinked-packages'
BrianHenryIE May 22, 2020
444a32e
Merge branch 'autoload-override'
BrianHenryIE May 22, 2020
7bb930d
Merge branch 'classmap-replacing-in-child-packages'
BrianHenryIE May 22, 2020
e05525c
too much documentation
BrianHenryIE May 22, 2020
8074ed7
too much documentation
BrianHenryIE May 22, 2020
7e929fb
too much documentation
BrianHenryIE May 22, 2020
6e4b3d4
Missed a merge conflict
BrianHenryIE May 22, 2020
6883b58
Update NamespaceReplacer.php
BrianHenryIE May 22, 2020
c7e4b7b
Merge branch 'generate-classmap'
BrianHenryIE May 22, 2020
ad44c39
Update Replacer.php
BrianHenryIE May 22, 2020
3952042
classmap_output example in readme
BrianHenryIE May 22, 2020
8485089
readdme indentation
BrianHenryIE May 22, 2020
f2083e9
Merge remote-tracking branch 'upstream/master'
BrianHenryIE Jun 6, 2020
cee820c
GitHub Annotations for PHPCS
BrianHenryIE Sep 20, 2020
e9e9e6a
Run PHPCBF first so only important errors are noted
BrianHenryIE Sep 20, 2020
9129051
Fix and commit PHPCBF changes on master
BrianHenryIE Sep 20, 2020
f016a2f
Merge remote-tracking branch 'upstream/master' into master
BrianHenryIE Nov 23, 2020
d81cf26
Use cs2pr for annotations
BrianHenryIE Nov 25, 2020
3819870
Revert composer.json
BrianHenryIE Nov 25, 2020
994bfa8
Update phpcbf.yml
BrianHenryIE Nov 25, 2020
d9b95cb
Remove broken git-auto-commit-action
BrianHenryIE Nov 25, 2020
6fe6e04
Tested
BrianHenryIE Nov 25, 2020
56afd93
Update setup-php to support tools
BrianHenryIE Nov 25, 2020
349fdc3
Merge branch 'master' into github-actions-phpcs-annotations
BrianHenryIE Nov 25, 2020
09a7227
Update main.yml
BrianHenryIE Nov 25, 2020
2e59ef1
Revert "Update main.yml"
BrianHenryIE Nov 25, 2020
cd631e0
Revert bad merge
BrianHenryIE Nov 25, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,24 @@ jobs:
- name: Install dependencies
run: composer install --prefer-dist --no-suggest --no-progress
- name: Run tests
run: vendor/bin/phpunit --printer mheap\\GithubActionsReporter\\Printer
run: composer run test
lint:
runs-on: ubuntu-latest
name: Lint project files
steps:
- uses: actions/checkout@v1
- name: Install PHP
uses: shivammathur/setup-php@1.3.7
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
tools: composer, cs2pr
- name: Debugging
run: |
php --version
php -m
composer --version
- name: Install dependencies
run: composer install --prefer-dist --no-suggest --no-progress
- name: Run validate
run: composer run lint

- name: Run PHPCS
run: vendor/bin/phpcs -q -n --report=checkstyle | cs2pr
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ Mozart requires little configuration. All you need to do is tell it where the bu
"packages": [
"pimple/pimple"
],
"exclude_packages": [
"psr/container"
],
"override_autoload": {
"google/apiclient": {
"classmap": [
Expand All @@ -55,7 +52,6 @@ The following configuration is optional:

- `delete_vendor_directories` is a boolean flag to indicate if the packages' vendor directories should be deleted after being processed. _default: true_.
- `packages` is an optional array that defines the packages to be processed by Mozart. The array requires the slugs of packages in the same format as provided in your `composer.json`. Mozart will automatically rewrite dependencies of these packages as well. You don't need to add dependencies of these packages to the list. If this field is absent, all packages listed under composer require will be included.
- `exclude_packages` is an optional array that defines the packages to be excluded from the processing performed by Mozart. This is useful if some of the packages in the `packages` array define dependent packages whose namespaces you want to keep unchanged. The array requires the slugs of the packages, as in the case of the `packages` array.
- `override_autoload` a dictionary, keyed with the package names, of autoload settings to replace those in the original packages' `composer.json` `autoload` property.

After Composer has loaded the packages as defined in your `composer.json` file, you can now run `mozart compose` and Mozart will bundle your packages according to the above configuration. It is recommended to dump the autoloader after Mozart has finished running, in case there are new classes or namespaces generated that aren't included in the autoloader yet.
Expand Down
11 changes: 2 additions & 9 deletions src/Console/Commands/Compose.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$require = array_keys(get_object_vars($composer->require));
}

$packagesByName = $this->findPackages($require);
$excludedPackagesNames = isset($config->excluded_packages) ? $config->excluded_packages : [];
$packagesToMoveByName = array_diff_key($packagesByName, array_flip($excludedPackagesNames));
$packages = array_values($packagesToMoveByName);

foreach ($packages as $package) {
$package->dependencies = array_diff_key($package->dependencies, array_flip($excludedPackagesNames));
}
$packages = $this->findPackages($require);

$this->mover = new Mover($workingDir, $config);
$this->replacer = new Replacer($workingDir, $config);
Expand Down Expand Up @@ -180,7 +173,7 @@ private function findPackages($slugs)
}

$package->dependencies = $this->findPackages($dependencies);
$packages[$package_slug] = $package;
$packages[] = $package;
}

return $packages;
Expand Down
22 changes: 3 additions & 19 deletions src/Mover.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,7 @@ public function movePackage(Package $package)
}
}

if (!in_array($package->config->name, $this->movedPackages)) {
$this->movedPackages[] = $package->config->name;
}
$this->movedPackages[] = $package->config->name;
}

if (!isset($this->config->delete_vendor_directories) || $this->config->delete_vendor_directories === true) {
Expand Down Expand Up @@ -202,25 +200,11 @@ public function moveFile(Package $package, $autoloader, $file, $path = '')
protected function deletePackageVendorDirectories()
{
foreach ($this->movedPackages as $movedPackage) {
$packageDir = 'vendor' . DIRECTORY_SEPARATOR . $movedPackage;
if (!is_dir($packageDir) || is_link($packageDir)) {
$packageDir = DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . $movedPackage;
if (is_link($packageDir)) {
continue;
}

$this->filesystem->deleteDir($packageDir);

//Delete parent directory too if it became empty
//(because that package was the only one from that vendor)
$parentDir = dirname($packageDir);
if ($this->dirIsEmpty($parentDir)) {
$this->filesystem->deleteDir($parentDir);
}
}
}

private function dirIsEmpty($dir)
{
$di = new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS);
return iterator_count($di) === 0;
}
}