Skip to content

Commit

Permalink
Feat: Add basic extension loading
Browse files Browse the repository at this point in the history
Enable loading of phpdoc extensions. Extensions are based on symfony
DI extensions. We do check the manifest.xml for compatibility to ensure
we have everything needed.
  • Loading branch information
jaapio committed Aug 20, 2023
1 parent 4c2f900 commit 691e1c1
Show file tree
Hide file tree
Showing 15 changed files with 533 additions and 151 deletions.
6 changes: 5 additions & 1 deletion bin/phpdoc
Expand Up @@ -2,6 +2,7 @@
<?php

use phpDocumentor\AutoloaderLocator;
use phpDocumentor\Extension\ExtensionHandler;
use Symfony\Component\Console\Input\ArgvInput;

set_time_limit(0);
Expand All @@ -10,7 +11,10 @@ require __DIR__ . '/../src/phpDocumentor/AutoloaderLocator.php';
$loader = AutoloaderLocator::autoload();

$containerFactory = new \phpDocumentor\Console\ContainerFactory();
$container = $containerFactory->create(AutoloaderLocator::findVendorPath());
$container = $containerFactory->create(
AutoloaderLocator::findVendorPath(),
ExtensionHandler::getInstance(getcwd() . '/.phpdoc/extensions')
);
$output = new \Symfony\Component\Console\Output\ConsoleOutput();

$application = $container->get(\phpDocumentor\Console\Application::class);
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Expand Up @@ -46,6 +46,8 @@
"league/uri-interfaces": "^2.0",
"monolog/monolog": "^2.9",
"nikic/php-parser": "^4.14",
"phar-io/manifest": "^2.0",
"phar-io/version": "^3.2",
"phpdocumentor/flyfinder": "^1.0",
"phpdocumentor/graphviz": "^2.0",
"phpdocumentor/guides": "^0.1.0",
Expand Down
226 changes: 113 additions & 113 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions config/services.yaml
Expand Up @@ -154,6 +154,9 @@ services:
$files: '@files'
$descriptors: '@descriptors'

phpDocumentor\Extension\ExtensionHandler:
factory: [ '\phpDocumentor\Extension\ExtensionHandler', 'getInstance' ]

###################################################################################
## Autoloading definitions for external services ##################################
###################################################################################
Expand Down
27 changes: 0 additions & 27 deletions src/phpDocumentor/Application.php
Expand Up @@ -13,21 +13,15 @@

namespace phpDocumentor;

use Jean85\PrettyVersions;
use OutOfBoundsException;
use RuntimeException;
use Webmozart\Assert\Assert;

use function date_default_timezone_set;
use function extension_loaded;
use function file_exists;
use function file_get_contents;
use function getcwd;
use function ini_get;
use function ini_set;
use function ltrim;
use function sprintf;
use function trim;

/**
* Application class for phpDocumentor.
Expand All @@ -38,27 +32,6 @@
*/
final class Application
{
private const VERSION = '@package_version@';

public static function VERSION(): string
{
$version = self::VERSION;

$trickBoxIntoNotReplacingThisScalar = sprintf('%s%s%s', '@', 'package_version', '@');
$didBoxReplaceTheVersionPlaceholder = $trickBoxIntoNotReplacingThisScalar !== self::VERSION;

if ($didBoxReplaceTheVersionPlaceholder === false) {
$version = trim(file_get_contents(__DIR__ . '/../../VERSION'));
try {
$version = PrettyVersions::getRootPackageVersion()->getPrettyVersion();
$version = sprintf('%s', ltrim($version, 'v'));
} catch (OutOfBoundsException) {
}
}

return $version;
}

public static function templateDirectory(): string
{
$templateDir = __DIR__ . '/../../data/templates';
Expand Down
17 changes: 14 additions & 3 deletions src/phpDocumentor/AutoloaderLocator.php
Expand Up @@ -26,13 +26,24 @@

final class AutoloaderLocator
{
private static ClassLoader|null $classLoader;

public static function loader(): ClassLoader
{
return self::autoload();
}

public static function autoload(): ClassLoader
{
if (Phar::running(false)) {
return require 'phar://' . Phar::running(false) . '/vendor/autoload.php';
if (isset(self::$classLoader) === false) {
if (Phar::running(false)) {
self::$classLoader = require 'phar://' . Phar::running(false) . '/vendor/autoload.php';
} else {
self::$classLoader = require self::findVendorPath() . '/autoload.php';
}
}

return require self::findVendorPath() . '/autoload.php';
return self::$classLoader;
}

/**
Expand Down

0 comments on commit 691e1c1

Please sign in to comment.