Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Composer package discovery through `extra.phenix` metadata.
- Package resource registration and the `package:discover` and `vendor:publish` commands.
- Namespaced package views, translations, and package migration paths.

# Release Notes for 0.9.x

## [v0.10.1 (2026-10-07)](https://github.com/phenixphp/framework/compare/0.10.0...0.10.1)
Expand Down
25 changes: 21 additions & 4 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
use Phenix\Constants\ServerMode;
use Phenix\Contracts\App as AppContract;
use Phenix\Contracts\Makeable;
use Phenix\Exceptions\RuntimeError;
use Phenix\Exceptions\RuntimeException;
use Phenix\Facades\Config;
use Phenix\Facades\Route;
use Phenix\Http\Client\HttpClient;
Expand All @@ -39,6 +39,9 @@
use Phenix\Http\ErrorHandler as AppErrorHandler;
use Phenix\Http\ExceptionHandler as AppExceptionHandler;
use Phenix\Logging\LoggerFactory;
use Phenix\Packages\PackageManifest;
use Phenix\Packages\PackageRegistry;
use Phenix\Providers\ServiceProvider;
use Phenix\Runtime\Log;
use Phenix\Session\SessionMiddlewareFactory;

Expand All @@ -47,6 +50,7 @@
use function count;
use function extension_loaded;
use function is_array;
use function is_string;

class App implements AppContract, Makeable
{
Expand Down Expand Up @@ -97,12 +101,25 @@ public function setup(): void
self::$container->add(HttpClient::class);
self::$container->add(HttpClientTestLogger::class)->setShared(true);

$manifest = new PackageManifest(self::$path);
self::$container->add(PackageManifest::class, $manifest)->setShared(true);
self::$container->add(PackageRegistry::class)->setShared(true);

self::$container->add(Phenix::class)->addMethodCall('registerCommands');

/** @var array $providers */
$providers = Config::get('app.providers', []);
$providers = array_values(array_unique([
...Config::get('app.providers', []),
...$manifest->providers(),
]));

foreach ($providers as $provider) {
if (! is_string($provider) || ! class_exists($provider) || ! is_subclass_of($provider, ServiceProvider::class)) {
$providerName = is_string($provider) ? $provider : get_debug_type($provider);

throw new RuntimeException("Service provider {$providerName} is invalid.");
}

self::$container->addServiceProvider(new $provider());
}

Expand Down Expand Up @@ -253,7 +270,7 @@ protected function createServer(): SocketHttpServer
$trustedProxies = Config::get('app.trusted_proxies', []);

if (is_array($trustedProxies) && count($trustedProxies) === 0) {
throw new RuntimeError('Trusted proxies must be an array of IP addresses or CIDRs.');
throw new RuntimeException('Trusted proxies must be an array of IP addresses or CIDRs.');
}

return SocketHttpServer::createForBehindProxy(
Expand Down Expand Up @@ -286,7 +303,7 @@ protected function createClusterServer(): SocketHttpServer
$trustedProxies = Config::get('app.trusted_proxies', []);

if (is_array($trustedProxies) && count($trustedProxies) === 0) {
throw new RuntimeError('Trusted proxies must be an array of IP addresses or CIDRs.');
throw new RuntimeException('Trusted proxies must be an array of IP addresses or CIDRs.');
}

$middleware[] = new Middleware\ForwardedMiddleware(ForwardedHeaderType::XForwardedFor, $trustedProxies);
Expand Down
8 changes: 4 additions & 4 deletions src/Concerns/ResolveHost.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Phenix\Concerns;

use League\Uri\Uri;
use Phenix\Exceptions\RuntimeError;
use Phenix\Exceptions\RuntimeException;
use Phenix\Facades\Config;

use function in_array;
Expand All @@ -19,7 +19,7 @@ protected function resolvePublicHost(): string
$host = $uri->getHost();

if (! in_array($uri->getScheme(), ['http', 'https'], true) || $host === '') {
throw new RuntimeError('App URL must be an absolute HTTP or HTTPS URL with a host.');
throw new RuntimeException('App URL must be an absolute HTTP or HTTPS URL with a host.');
}

return $host;
Expand All @@ -30,7 +30,7 @@ protected function resolveBindHost(): string
$host = trim((string) Config::get('app.host'));

if ($host === '') {
throw new RuntimeError('Bind host must not be empty.');
throw new RuntimeException('Bind host must not be empty.');
}

return trim($host, '[]');
Expand All @@ -41,7 +41,7 @@ protected function resolveBindPort(): int
$port = (int) Config::get('app.port');

if ($port < 1 || $port > 65535) {
throw new RuntimeError('Bind port must be between 1 and 65535.');
throw new RuntimeException('Bind port must be between 1 and 65535.');
}

return $port;
Expand Down
33 changes: 33 additions & 0 deletions src/Console/Commands/PackageDiscover.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Phenix\Console\Commands;

use Phenix\App;
use Phenix\Packages\PackageManifest;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class PackageDiscover extends Command
{
protected static $defaultName = 'package:discover';

protected static $defaultDescription = 'Rebuild the cached package manifest.';

protected function execute(InputInterface $input, OutputInterface $output): int
{
/** @var PackageManifest $manifest */
$manifest = App::make(PackageManifest::class);
$manifest->build();

$output->writeln('<info>Discovered packages:</info>');

foreach ($manifest->packages() as $package) {
$output->writeln(" <comment>{$package}</comment>");
}

return Command::SUCCESS;
}
}
130 changes: 130 additions & 0 deletions src/Console/Commands/VendorPublish.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php

declare(strict_types=1);

namespace Phenix\Console\Commands;

use FilesystemIterator;
use Phenix\App;
use Phenix\Exceptions\RuntimeException;
use Phenix\Packages\PackageRegistry;
use Phenix\Util\Path;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Throwable;

use function is_string;

class VendorPublish extends Command
{
protected static $defaultName = 'vendor:publish';

protected static $defaultDescription = 'Publish resources from installed packages.';

protected function configure(): void
{
$this->addOption('provider', null, InputOption::VALUE_REQUIRED, 'Service provider to publish.');
$this->addOption('tag', null, InputOption::VALUE_REQUIRED, 'Resource tag to publish.');
$this->addOption('all', null, InputOption::VALUE_NONE, 'Publish resources from all providers.');
$this->addOption('force', 'f', InputOption::VALUE_NONE, 'Overwrite existing files.');
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
/** @var PackageRegistry $registry */
$registry = App::make(PackageRegistry::class);
$provider = $input->getOption('provider');
$tag = $input->getOption('tag');

if (! $input->getOption('all') && $provider === null && $tag === null) {
$output->writeln('<error>Specify --provider, --tag, or --all.</error>');

return Command::FAILURE;
}

$paths = $registry->pathsToPublish(
is_string($provider) ? $provider : null,
is_string($tag) ? $tag : null,
);

if ($paths === []) {
$output->writeln('<comment>No publishable resources were found.</comment>');

return Command::SUCCESS;
}

$commandStatus = Command::SUCCESS;

foreach ($paths as $source => $destination) {
try {
$published = $this->publish(
(string) $source,
(string) $destination,
(bool) $input->getOption('force'),
);
$status = $published > 0 ? '<info>Published:</info>' : '<comment>Skipped:</comment>';
$output->writeln("{$status} {$source} <comment>→</comment> {$destination}");
} catch (Throwable $exception) {
$output->writeln('<error>' . $exception->getMessage() . '</error>');

$commandStatus = Command::FAILURE;
}
}

return $commandStatus;
}

private function publish(string $source, string $destination, bool $force): int
{
if (is_file($source)) {
return $this->copyFile($source, $destination, $force) ? 1 : 0;
}

if (! is_dir($source)) {
throw new RuntimeException("Publish source {$source} does not exist.");
}

$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($source, FilesystemIterator::SKIP_DOTS),
);
$published = 0;

foreach ($iterator as $file) {
if (! $file->isFile()) {
continue;
}

$relative = substr($file->getPathname(), strlen($source) + 1);
$target = Path::join(rtrim($destination, DIRECTORY_SEPARATOR), $relative);

if ($this->copyFile($file->getPathname(), $target, $force)) {
$published++;
}
}

return $published;
}

private function copyFile(string $source, string $destination, bool $force): bool
{
if (is_file($destination) && ! $force) {
return false;
}

$directory = dirname($destination);

if (! is_dir($directory) && ! @mkdir($directory, 0755, true) && ! is_dir($directory)) {
throw new RuntimeException("Unable to create publish directory {$directory}.");
}

if (! @copy($source, $destination)) {
throw new RuntimeException("Unable to publish {$source} to {$destination}.");
}

return true;
}
}
4 changes: 4 additions & 0 deletions src/Console/CommandsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use Phenix\Console\Commands\MakeRequest;
use Phenix\Console\Commands\MakeServiceProvider;
use Phenix\Console\Commands\MakeTest;
use Phenix\Console\Commands\PackageDiscover;
use Phenix\Console\Commands\VendorPublish;
use Phenix\Console\Commands\ViewCache;
use Phenix\Console\Commands\ViewClear;
use Phenix\Providers\ServiceProvider;
Expand All @@ -33,6 +35,8 @@ public function boot(): void
GenerateKey::class,
ViewClear::class,
ViewCache::class,
PackageDiscover::class,
VendorPublish::class,
]);
}
}
2 changes: 1 addition & 1 deletion src/Console/Phenix.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class Phenix extends Application
{
private static array $commands;
private static array $commands = [];

public function __construct()
{
Expand Down
31 changes: 30 additions & 1 deletion src/Database/Console/DatabaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@

namespace Phenix\Database\Console;

use Phenix\App;
use Phenix\Database\Constants\Driver;
use Phenix\Database\MigrationManager;
use Phenix\Facades\Config;
use Phenix\Packages\PackageRegistry;
use Phinx\Config\Config as MigrationConfig;
use Phinx\Console\Command\AbstractCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

abstract class DatabaseCommand extends AbstractCommand
{
Expand All @@ -33,9 +38,16 @@ public function __construct()
$environment['suffix'] = '';
}

/** @var PackageRegistry $packages */
$packages = App::make(PackageRegistry::class);
$migrationPaths = array_values(array_unique([
...(array) Config::get('database.paths.migrations'),
...$packages->migrationPaths(),
]));

$this->config = new MigrationConfig([
'paths' => [
'migrations' => Config::get('database.paths.migrations'),
'migrations' => $migrationPaths,
'seeds' => Config::get('database.paths.seeds'),
],
'environments' => [
Expand All @@ -48,6 +60,23 @@ public function __construct()
parent::__construct();
}

protected function loadManager(InputInterface $input, OutputInterface $output): void
{
if ($this->getManager() === null) {
$manager = new MigrationManager($this->getConfig(), $input, $output);
$manager->setVerbosityLevel($this->verbosityLevel);
$container = $this->getConfig()->getContainer();

if ($container !== null) {
$manager->setContainer($container);
}

$this->setManager($manager);
}

parent::loadManager($input, $output);
}

/**
* {@inheritDoc}
*
Expand Down
Loading
Loading