Skip to content

Commit

Permalink
Merge 522effd into 63f8c09
Browse files Browse the repository at this point in the history
  • Loading branch information
crynobone committed Sep 14, 2023
2 parents 63f8c09 + 522effd commit 11e7696
Show file tree
Hide file tree
Showing 179 changed files with 1,972 additions and 6,588 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: false
matrix:
os:
- "ubuntu-latest"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Which will output the following as `canvas.yaml`:
preset: package

namespace: PackageName
user-auth-provider: App\User
user-auth-model: App\User

paths:
src: src
Expand Down
61 changes: 10 additions & 51 deletions canvas
Original file line number Diff line number Diff line change
@@ -1,60 +1,19 @@
#!/usr/bin/env php
<?php

$workingPath = getcwd();

define('CANVAS_WORKING_PATH', $workingPath);
define('CANVAS_WORKING_PATH', $workingPath = getcwd());
define('TESTBENCH_WORKING_PATH', $workingPath);

require $_composer_autoload_path ?? __DIR__.'/vendor/autoload.php';

$config = ['preset' => Orchestra\Canvas\Canvas::presetFromEnvironment($workingPath)];

if (file_exists($workingPath.DIRECTORY_SEPARATOR.'canvas.yaml')) {
$config = Symfony\Component\Yaml\Yaml::parseFile($workingPath.DIRECTORY_SEPARATOR.'canvas.yaml');
}

$files = new Illuminate\Filesystem\Filesystem();

$preset = Orchestra\Canvas\Canvas::preset(
$config, $workingPath, $files
$config = Orchestra\Testbench\Foundation\Config::loadFromYaml(
workingPath: $workingPath,
defaults: [
'providers' => [],
'dont-discover' => [],
],
);

$app = new Symfony\Component\Console\Application('Canvas for Laravel');

$app->setVersion(Composer\InstalledVersions::getPrettyVersion('orchestra/canvas'));

Illuminate\Support\Collection::make([
Orchestra\Canvas\Commands\Channel::class => true,
Orchestra\Canvas\Commands\Component::class => true,
Orchestra\Canvas\Commands\Console::class => true,
Orchestra\Canvas\Commands\ConsoleGenerator::class => true,
Orchestra\Canvas\Commands\Database\Cast::class => true,
Orchestra\Canvas\Commands\Database\Eloquent::class => true,
Orchestra\Canvas\Commands\Database\Factory::class => true,
Orchestra\Canvas\Commands\Database\Migration::class => true,
Orchestra\Canvas\Commands\Database\Observer::class => true,
Orchestra\Canvas\Commands\Database\Seeder::class => $preset->is('laravel'),
Orchestra\Canvas\Commands\Event::class => true,
Orchestra\Canvas\Commands\Exception::class => true,
Orchestra\Canvas\Commands\Job::class => true,
Orchestra\Canvas\Commands\Listener::class => true,
Orchestra\Canvas\Commands\Mail::class => true,
Orchestra\Canvas\Commands\Notification::class => true,
Orchestra\Canvas\Commands\Policy::class => true,
Orchestra\Canvas\Commands\Preset::class => ! file_exists("{$workingPath}/canvas.yaml"),
Orchestra\Canvas\Commands\Provider::class => true,
Orchestra\Canvas\Commands\Request::class => true,
Orchestra\Canvas\Commands\Resource::class => true,
Orchestra\Canvas\Commands\Routing\Controller::class => true,
Orchestra\Canvas\Commands\Routing\Middleware::class => true,
Orchestra\Canvas\Commands\Rule::class => true,
Orchestra\Canvas\Commands\Testing::class => true,
Orchestra\Canvas\Commands\StubPublish::class => true,
Orchestra\Canvas\Commands\View::class => true,
])->filter(fn ($value) => $value === true)
->keys()
->each(fn ($command) => $app->add(new $command($preset)));

$preset->addAdditionalCommands($app);
$commander = new Orchestra\Canvas\Console\Commander($config->getAttributes(), $workingPath);

$app->run();
$commander->handle();
21 changes: 0 additions & 21 deletions canvas.yaml

This file was deleted.

19 changes: 8 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,35 @@
},
"autoload-dev": {
"psr-4": {
"Orchestra\\Canvas\\Tests\\": "tests/"
"Orchestra\\Canvas\\Tests\\": "tests/",
"Illuminate\\Tests\\Integration\\Generators\\": "workbench/tests/"
}
},
"require": {
"php": "^8.1",
"composer-runtime-api": "^2.2",
"composer/semver": "^3.0",
"illuminate/database": "^10.17",
"illuminate/support": "^10.17",
"orchestra/canvas-core": "^8.7",
"laravel/framework": "dev-generator-presets as 10.x-dev",
"orchestra/testbench-core": "^8.10.2",
"symfony/yaml": "^6.2"
},
"require-dev": {
"laravel/framework": "^10.17",
"laravel/pint": "^1.6",
"mockery/mockery": "^1.5.1",
"orchestra/testbench-core": "^8.9.1",
"phpstan/phpstan": "^1.10.5",
"phpunit/phpunit": "^10.1",
"spatie/laravel-ray": "^1.32.4"
},
"config": {
"preferred-install": {
"laravel/framework": "source",
"*": "auto"
},
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-master": "9.0-dev"
},
"laravel": {
"providers": [
"Orchestra\\Canvas\\LaravelServiceProvider"
]
}
},
"scripts": {
Expand Down
11 changes: 11 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
parameters:
ignoreErrors:
-
message: "#^Unable to resolve the template type TMakeKey in call to method static method Illuminate\\\\Support\\\\Collection\\<\\(int\\|string\\),mixed\\>\\:\\:make\\(\\)$#"
count: 1
path: src/Console/Commander.php

-
message: "#^Unable to resolve the template type TMakeValue in call to method static method Illuminate\\\\Support\\\\Collection\\<\\(int\\|string\\),mixed\\>\\:\\:make\\(\\)$#"
count: 1
path: src/Console/Commander.php
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
includes:
- phpstan-baseline.neon
parameters:

paths:
Expand Down
4 changes: 3 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
</source>
<testsuites>
<testsuite name="Canvas Test Suite">
<directory suffix="Test.php">./tests/</directory>
<directory suffix="Test.php">tests/Feature/</directory>
<directory suffix="Test.php">tests/Unit/</directory>
<directory suffix="Test.php">workbench/tests/</directory>
</testsuite>
</testsuites>
<php>
Expand Down
18 changes: 9 additions & 9 deletions src/Canvas.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Orchestra\Canvas;

use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Orchestra\Canvas\Core\Presets\Preset;

class Canvas
{
Expand Down Expand Up @@ -37,9 +37,9 @@ public static function presetFromEnvironment(string $basePath): string
* Make Preset from configuration.
*
* @param array<string, mixed> $config
* @return \Orchestra\Canvas\Core\Presets\Preset
* @return \Orchestra\Canvas\Presets\Preset
*/
public static function preset(array $config, string $basePath, Filesystem $files): Core\Presets\Preset
public static function preset(array $config, string $basePath): Presets\Preset
{
/** @var array<string, mixed> $configuration */
$configuration = Arr::except($config, 'preset');
Expand All @@ -48,20 +48,20 @@ public static function preset(array $config, string $basePath, Filesystem $files

switch ($preset) {
case 'package':
return new Core\Presets\Package($configuration, $basePath, $files);
return new Presets\Package($configuration, $basePath);
case 'laravel':
return new Core\Presets\Laravel($configuration, $basePath, $files);
return new Presets\Laravel($configuration, $basePath);
default:
if (class_exists($preset)) {
/**
* @var class-string<\Orchestra\Canvas\Core\Presets\Preset> $preset
* @var class-string<\Orchestra\Canvas\Presets\Preset> $preset
*
* @return \Orchestra\Canvas\Core\Presets\Preset
* @return \Orchestra\Canvas\Presets\Preset
*/
return new $preset($configuration, $basePath, $files);
return new $preset($configuration, $basePath);
}

return new Core\Presets\Laravel($configuration, $basePath, $files);
return new Presets\Laravel($configuration, $basePath);
}
}
}
78 changes: 78 additions & 0 deletions src/CanvasServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

namespace Orchestra\Canvas;

use Illuminate\Console\Generators\PresetManager;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\Support\DeferrableProvider;
use Illuminate\Support\Arr;
use Illuminate\Support\ServiceProvider;
use Symfony\Component\Yaml\Yaml;

class CanvasServiceProvider extends ServiceProvider implements DeferrableProvider
{
/**
* Register services.
*
* @return void
*/
public function register(): void
{
if (class_exists(PresetManager::class)) {
$this->callAfterResolving(PresetManager::class, function ($manager, $app) {
$manager->extend('canvas', function ($app) {
return new GeneratorPreset($app);
});

$manager->setDefaultDriver('canvas');
});
}

$this->app->singleton('orchestra.canvas', function (Application $app) {
$workingPath = \defined('CANVAS_WORKING_PATH') ? CANVAS_WORKING_PATH : $this->app->basePath();

$filesystem = $app->make('files');

$config = ['preset' => 'laravel'];

if (file_exists($workingPath.DIRECTORY_SEPARATOR.'canvas.yaml')) {
$config = Yaml::parseFile($workingPath.DIRECTORY_SEPARATOR.'canvas.yaml');
} else {
Arr::set($config, 'testing.extends', [
'unit' => 'PHPUnit\Framework\TestCase',
'feature' => 'Tests\TestCase',
]);

$config['namespace'] = rescue(fn () => rtrim($this->app->getNamespace(), '\\'), null, false);
}

return Canvas::preset($config, $workingPath);
});
}

/**
* Bootstrap services.
*/
public function boot(): void
{
if ($this->app->runningInConsole()) {
$this->commands([
Console\CodeMakeCommand::class,
Console\FactoryMakeCommand::class,
Console\GeneratorMakeCommand::class,
Console\TestMakeCommand::class,
Console\ViewMakeCommand::class,
]);
}
}

/**
* Get the services provided by the provider.
*
* @return array<int, string>
*/
public function provides()
{
return ['orchestra.canvas'];
}
}
48 changes: 0 additions & 48 deletions src/Commands/Channel.php

This file was deleted.

11 changes: 0 additions & 11 deletions src/Commands/Code.php

This file was deleted.

0 comments on commit 11e7696

Please sign in to comment.