Skip to content

Commit

Permalink
Added support for Composer 2
Browse files Browse the repository at this point in the history
Forked from indigophp/doctrine-annotation-autoload.
  • Loading branch information
Yogarine committed Nov 2, 2020
1 parent dde2f50 commit dcf25c3
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.idea

build/
vendor/
composer.lock
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Copyright (c) 2015 Indigo Development Team
Copyright (c) 2020 Alwin Garside

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Composer Doctrine Annotation Autoload plugin

[![Latest Version](https://img.shields.io/github/release/indigophp/doctrine-annotation-autoload.svg?style=flat-square)](https://github.com/indigophp/doctrine-annotation-autoload/releases)
[![Latest Version](https://img.shields.io/github/release/Yogarine/doctrine-annotation-autoload.svg?style=flat-square)](https://github.com/Yogarine/doctrine-annotation-autoload/releases)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
[![Total Downloads](https://img.shields.io/packagist/dt/indigophp/doctrine-annotation-autoload.svg?style=flat-square)](https://packagist.org/packages/indigophp/doctrine-annotation-autoload)
[![Total Downloads](https://img.shields.io/packagist/dt/yogarine/doctrine-annotation-autoload.svg?style=flat-square)](https://packagist.org/packages/yogarine/doctrine-annotation-autoload)

**Hooks into Composer autoload generation and adds Doctrine annotation autoloading.**

Expand All @@ -12,7 +12,7 @@
Via Composer

``` bash
$ composer require indigophp/doctrine-annotation-autoload
$ composer require yogarine/doctrine-annotation-autoload
```


Expand All @@ -29,13 +29,15 @@ $ composer dump-autoload

## Security

If you discover any security related issues, please contact us at [security@indigophp.com](mailto:security@indigophp.com).
If you discover any security related issues, please submit an issue here:<br>
[https://github.com/Yogarine/doctrine-annotation-autoload/issues](https://github.com/Yogarine/doctrine-annotation-autoload/issues)


## Credits

- [Márk Sági-Kazár](https://github.com/sagikazarmark)
- [All Contributors](https://github.com/indigophp/doctrine-annotation-autoload/contributors)
- [Márk Sági-Kazár](https://github.com/Yogarine)
- [All Contributors](https://github.com/Yogarine/doctrine-annotation-autoload/contributors)


## License
Expand Down
22 changes: 14 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
{
"name": "indigophp/doctrine-annotation-autoload",
"name": "yogarine/doctrine-annotation-autoload",
"type": "composer-plugin",
"description": "Hooks into Composer autoload generation and adds Doctrine annotation autoloading",
"license": "MIT",
"keywords": ["doctrine", "annotation", "autoload"],
"homepage": "https://indigophp.com",
"authors": [
{
"name": "Márk Sági-Kazár",
"email": "mark.sagikazar@gmail.com"
},
{
"name": "Alwin Garside",
"email": "alwin@garsi.de"
}
],
"require": {
"php": ">=5.4",
"composer-plugin-api": "^1.0",
"php": ">=5.3.2",
"composer-plugin-api": "^1.0 || ^2.0",
"doctrine/annotations": "*"
},
"require-dev": {
"composer/composer": "^1.0 || ^2.0"
},
"autoload": {
"psr-4": {
"Indigo\\Composer\\": "src/"
"Yogarine\\Composer\\": "src/"
}
},
"extra": {
"class": "Indigo\\Composer\\DoctrineAnnotationAutoloadPlugin",
"class": "Yogarine\\Composer\\DoctrineAnnotationAutoloadPlugin",
"branch-alias": {
"dev-master": "0.2-dev"
"dev-master": "0.4-dev"
}
},
"prefer-stable": true,
"minimum-stability": "dev"
"minimum-stability": "stable"
}
19 changes: 15 additions & 4 deletions src/Autoload/DoctrineAutoloadGenerator.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,40 @@
<?php

namespace Indigo\Composer\Autoload;
namespace Yogarine\Composer\Autoload;

use Composer\Autoload\AutoloadGenerator;

/**
* Add the autoloader to Doctrine Annotation Registry.
*
* @author Márk Sági-Kazár <mark.sagikazar@gmail.com>
* @author Alwin Garside <alwin@garsi.de>
*/
class DoctrineAutoloadGenerator extends AutoloadGenerator
{
/**
* {@inheritdoc}
* @param string $vendorPathToTargetDirCode
* @param string $suffix
* @return string
*/
protected function getAutoloadFile($vendorPathToTargetDirCode, $suffix)
{
$lastChar = $vendorPathToTargetDirCode[strlen($vendorPathToTargetDirCode) - 1];
if ("'" === $lastChar || '"' === $lastChar) {
$vendorPathToTargetDirCode = substr($vendorPathToTargetDirCode, 0, -1).'/autoload_real.php'.$lastChar;
} else {
$vendorPathToTargetDirCode .= " . '/autoload_real.php'";
}

return <<<AUTOLOAD
<?php
// autoload.php @generated by Composer
// autoload.php @generated by doctrine-annotation-autoload plugin for Composer:
// https://github.com/Yogarine/doctrine-annotation-autoload
use Doctrine\Common\Annotations\AnnotationRegistry;
require_once $vendorPathToTargetDirCode . '/autoload_real.php';
require_once $vendorPathToTargetDirCode;
\$loader = ComposerAutoloaderInit$suffix::getLoader();
Expand Down
22 changes: 21 additions & 1 deletion src/DoctrineAnnotationAutoloadPlugin.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php

namespace Indigo\Composer;
namespace Yogarine\Composer;

use Composer\Autoload\AutoloadGenerator;
use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;
Expand All @@ -12,6 +13,7 @@
* This might conflict with other plugins dealing with the autoloader as well.
*
* @author Márk Sági-Kazár <mark.sagikazar@gmail.com>
* @author Alwin Garside <alwin@garsi.de>
*/
class DoctrineAnnotationAutoloadPlugin implements PluginInterface
{
Expand All @@ -24,4 +26,22 @@ public function activate(Composer $composer, IOInterface $io)

$composer->setAutoloadGenerator($autoloadGenerator);
}

/**
* {@inheritdoc}
*/
public function deactivate(Composer $composer, IOInterface $io)
{
$autoloadGenerator = new AutoloadGenerator($composer->getEventDispatcher(), $io);

$composer->setAutoloadGenerator($autoloadGenerator);
}

/**
* {@inheritdoc}
*/
public function uninstall(Composer $composer, IOInterface $io)
{
// Nothing to do here.
}
}

0 comments on commit dcf25c3

Please sign in to comment.