Skip to content
Merged
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ composer.lock
/phpunit.xml
.phpunit.result.cache
!tests/Foundation/fixtures/hyperf1/composer.lock
tests/Foundation/fixtures/hyperf/runtime
tests/Http/fixtures
10 changes: 7 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"autoload": {
"psr-4": {
"Illuminate\\Events\\": "src/event/illuminate/",
"Workbench\\App\\": "src/testbench/workbench/app/",
"Hypervel\\": "src/core/src/",
"Hypervel\\Auth\\": "src/auth/src/",
"Hypervel\\Broadcasting\\": "src/broadcasting/src/",
Expand Down Expand Up @@ -54,7 +55,8 @@
"Hypervel\\Router\\": "src/router/src/",
"Hypervel\\Session\\": "src/session/src/",
"Hypervel\\Support\\": "src/support/src/",
"Hypervel\\Telescope\\": "src/telescope/src/"
"Hypervel\\Telescope\\": "src/telescope/src/",
"Hypervel\\Testbench\\": "src/testbench/src/"
},
"files": [
"src/auth/src/Functions.php",
Expand Down Expand Up @@ -152,7 +154,8 @@
"hypervel/router": "self.version",
"hypervel/session": "self.version",
"hypervel/support": "self.version",
"hypervel/telescope": "self.version"
"hypervel/telescope": "self.version",
"hypervel/testbench": "self.version"
},
"suggest": {
"hyperf/redis": "Required to use redis driver. (^3.1).",
Expand Down Expand Up @@ -186,7 +189,8 @@
"phpstan/phpstan": "^1.11.5",
"phpunit/phpunit": "10.5.45",
"pusher/pusher-php-server": "^7.2",
"swoole/ide-helper": "~5.1.0"
"swoole/ide-helper": "~5.1.0",
"symfony/yaml": "^7.3"
},
"config": {
"sort-packages": true
Expand Down
66 changes: 66 additions & 0 deletions src/container/src/ScanConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

declare(strict_types=1);

namespace Hypervel\Container;

use Hyperf\Di\Annotation\ScanConfig as HyperfScanConfig;
use Hypervel\Config\ProviderConfig;

class ScanConfig extends HyperfScanConfig
{
protected static function initConfigByFile(string $configDir): array
{
$config = [];
$configFromProviders = [];
$cacheable = false;
if (class_exists(ProviderConfig::class)) {
$configFromProviders = ProviderConfig::load();
}

$serverDependencies = $configFromProviders['dependencies'] ?? [];
if (file_exists($dependenciesFile = "{$configDir}/dependencies.php")) {
$definitions = include $dependenciesFile;
$serverDependencies = array_replace($serverDependencies, $definitions ?? []);
}

$config = static::allocateConfigValue($configFromProviders['annotations'] ?? [], $config);

// Load the config/annotations.php and merge the config
if (file_exists($annotationsFile = "{$configDir}/annotations.php")) {
$annotations = include $annotationsFile;
$config = static::allocateConfigValue($annotations, $config);
}

// Load the config/app.php and merge the config
if (file_exists($appFile = "{$configDir}/app.php")) {
$configContent = include $appFile;
$environment = $configContent['env'] ?? 'dev';
$cacheable = value($configContent['scan_cacheable'] ?? $environment === 'production');
if (isset($configContent['annotations'])) {
$config = static::allocateConfigValue($configContent['annotations'], $config);
}
}

return [$config, $serverDependencies, $cacheable];
}

protected static function allocateConfigValue(array $content, array $config): array
{
if (! isset($content['scan'])) {
return $config;
}

foreach ($content['scan'] as $key => $value) {
if (! isset($config[$key])) {
$config[$key] = [];
}
if (! is_array($value)) {
$value = [$value];
}
$config[$key] = array_merge($config[$key], $value);
}

return $config;
}
}
9 changes: 9 additions & 0 deletions src/filesystem/src/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,13 @@

class Filesystem extends HyperfFilesystem
{
/**
* Ensure a directory exists.
*/
public function ensureDirectoryExists(string $path, int $mode = 0755, bool $recursive = true): void
{
if (! $this->isDirectory($path)) {
$this->makeDirectory($path, $mode, $recursive);
}
}
}
2 changes: 1 addition & 1 deletion src/foundation/src/ClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace Hypervel\Foundation;

use Hyperf\Di\Annotation\ScanConfig;
use Hyperf\Di\Annotation\Scanner as AnnotationScanner;
use Hyperf\Di\LazyLoader\LazyLoader;
use Hyperf\Di\ScanHandler\PcntlScanHandler;
use Hyperf\Di\ScanHandler\ScanHandlerInterface;
use Hyperf\Support\DotenvManager;
use Hypervel\Container\ScanConfig;
use Hypervel\Support\Composer;

class ClassLoader
Expand Down
1 change: 0 additions & 1 deletion src/foundation/src/Providers/FoundationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ protected function overrideHyperfConfigs(): void
$configs = [
'app_name' => $this->config->get('app.name'),
'app_env' => $this->config->get('app.env'),
'scan_cacheable' => $this->config->get('app.scan_cacheable'),
StdoutLoggerInterface::class . '.log_level' => $this->config->get('app.stdout_log_level'),
'translation.locale' => $this->config->get('app.locale'),
'translation.fallback_locale' => $this->config->get('app.fallback_locale'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ trait CanConfigureMigrationCommands
{
/**
* The parameters that should be used when running "migrate:fresh".
*
* @return array
*/
protected function migrateFreshUsing()
protected function migrateFreshUsing(): array
{
$seeder = $this->seeder();
$connection = $this->app
Expand All @@ -31,30 +29,24 @@ protected function migrateFreshUsing()

/**
* Determine if views should be dropped when refreshing the database.
*
* @return bool
*/
protected function shouldDropViews()
protected function shouldDropViews(): bool
{
return property_exists($this, 'dropViews') ? $this->dropViews : false;
}

/**
* Determine if the seed task should be run when refreshing the database.
*
* @return bool
*/
protected function shouldSeed()
protected function shouldSeed(): bool
{
return property_exists($this, 'seed') ? $this->seed : false;
}

/**
* Determine the specific seeder class that should be used when refreshing the database.
*
* @return mixed
*/
protected function seeder()
protected function seeder(): mixed
{
return property_exists($this, 'seeder') ? $this->seeder : false;
}
Expand Down
3 changes: 3 additions & 0 deletions src/testbench/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
workbench/.env
workbench/composer.lock
workbench/runtime
33 changes: 33 additions & 0 deletions src/testbench/bin/testbench-sync
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env php
<?php

$workingPath = getcwd();

require "{$workingPath}/vendor/autoload.php";

$files = new Hypervel\Filesystem\Filesystem();
$files->copy("{$workingPath}/vendor/hypervel/testbench/testbench.yaml", "{$workingPath}/testbench.yaml");

Hypervel\Support\Collection::make([
...$files->allFiles("{$workingPath}/vendor/hypervel/testbench/workbench/app/"),
])->flatten()
->filter(static fn ($file) => is_file($file))
->each(static function ($file) use ($files, $workingPath) {
$filename = $workingPath . Hypervel\Support\Str::after((string) $file, "{$workingPath}/vendor/hypervel/testbench/workbench");
$files->ensureDirectoryExists(Hypervel\Support\Str::before($filename, basename($filename)));
$files->copy($file, $filename);
});

Hypervel\Support\Collection::make([
...$files->allFiles("{$workingPath}/vendor/hypervel/testbench/workbench/config/"),
...$files->allFiles("{$workingPath}/vendor/hypervel/testbench/workbench/database/"),
...$files->allFiles("{$workingPath}/vendor/hypervel/testbench/workbench/lang/"),
...$files->allFiles("{$workingPath}/vendor/hypervel/testbench/workbench/routes/"),
...$files->allFiles("{$workingPath}/vendor/hypervel/testbench/workbench/resources/"),
])->flatten()
->filter(static fn ($file) => is_file($file))
->each(static function ($file) use ($files, $workingPath) {
$filename = $workingPath . Hypervel\Support\Str::after((string) $file, "{$workingPath}/vendor/hypervel/testbench/workbench");
$files->ensureDirectoryExists(Hypervel\Support\Str::before($filename, basename($filename)));
$files->copy($file, $filename);
});
51 changes: 51 additions & 0 deletions src/testbench/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "hypervel/testbench",
"description": "The testbench package for Hypervel.",
"license": "MIT",
"keywords": [
"php",
"hyperf",
"testbench",
"swoole",
"hypervel"
],
"support": {
"issues": "https://github.com/hypervel/components/issues",
"source": "https://github.com/hypervel/components"
},
"authors": [
{
"name": "Albert Chen",
"email": "[email protected]"
}
],
"require": {
"php": "^8.2",
"hypervel/framework": "^0.1",
"mockery/mockery": "^1.6.10",
"phpunit/phpunit": "^10.0.7",
"symfony/yaml": "^7.3",
"vlucas/phpdotenv": "^5.6.1"
},
"autoload": {
"psr-4": {
"Hypervel\\Testbench\\": "src/",
"Workbench\\App\\": "workbench/app/"
}
},
"extra": {
"branch-alias": {
"dev-main": "0.1-dev"
}
},
"config": {
"sort-packages": true
},
"bin": [
"bin/testbench-sync"
],
"scripts": {
"sync": "@php bin/testbench-sync"
},
"minimum-stability": "dev"
}
Loading