Skip to content

Commit

Permalink
NEW Refactor CLI interaction with Silverstripe app
Browse files Browse the repository at this point in the history
- Turn sake into a symfony/console app
- Avoid using HTTPRequest for CLI interaction
- Implement abstract hybrid execution path
  • Loading branch information
GuySartorelli committed Sep 2, 2024
1 parent e3508d4 commit d3cb726
Show file tree
Hide file tree
Showing 78 changed files with 2,984 additions and 1,603 deletions.
13 changes: 13 additions & 0 deletions _config/cli.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
Name: cli-config
---
SilverStripe\Core\Injector\Injector:
Symfony\Contracts\EventDispatcher\EventDispatcherInterface.sake:
class: 'Symfony\Component\EventDispatcher\EventDispatcher'
Symfony\Component\Console\Formatter\OutputFormatterInterface:
class: 'Symfony\Component\Console\Formatter\OutputFormatter'
calls:
- ['setDecorated', [true]]
SilverStripe\Dev\HybridExecution\HtmlOutputFormatter:
constructor:
formatter: '%$Symfony\Component\Console\Formatter\OutputFormatterInterface'
6 changes: 1 addition & 5 deletions _config/confirmation-middleware.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,10 @@ SilverStripe\Core\Injector\Injector:
class: SilverStripe\Control\Middleware\ConfirmationMiddleware\EnvironmentBypass
type: prototype

SilverStripe\Control\Middleware\ConfirmationMiddleware\CliBypass:
class: SilverStripe\Control\Middleware\ConfirmationMiddleware\CliBypass
type: prototype

SilverStripe\Control\Middleware\ConfirmationMiddleware\HttpMethodBypass:
class: SilverStripe\Control\Middleware\ConfirmationMiddleware\HttpMethodBypass
type: prototype

SilverStripe\Control\Middleware\ConfirmationMiddleware\Url:
class: SilverStripe\Control\Middleware\ConfirmationMiddleware\Url
type: prototype
type: prototype
25 changes: 12 additions & 13 deletions _config/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@
Name: DevelopmentAdmin
---
SilverStripe\Dev\DevelopmentAdmin:
registered_controllers:
build:
controller: SilverStripe\Dev\DevBuildController
links:
build: 'Build/rebuild this environment. Call this whenever you have updated your project sources'
commands:
build: 'SilverStripe\Dev\HybridExecution\Command\DevBuild'
'build/cleanup': 'SilverStripe\Dev\HybridExecution\Command\DevBuildCleanup'
'build/defaults': 'SilverStripe\Dev\HybridExecution\Command\DevBuildDefaults'
config: 'SilverStripe\Dev\HybridExecution\Command\DevConfig'
'config/audit': 'SilverStripe\Dev\HybridExecution\Command\DevConfigAudit'
generatesecuretoken: 'SilverStripe\Dev\HybridExecution\Command\DevSecureToken'
controllers:
tasks:
controller: SilverStripe\Dev\TaskRunner
links:
tasks: 'See a list of build tasks to run'
class: 'SilverStripe\Dev\TaskRunner'
description: 'See a list of build tasks to run'
confirm:
controller: SilverStripe\Dev\DevConfirmationController
config:
controller: Silverstripe\Dev\DevConfigController
links:
config: 'View the current config, useful for debugging'
class: 'SilverStripe\Dev\DevConfirmationController'
skipLink: true

SilverStripe\Dev\CSSContentParser:
disable_xml_external_entities: true
4 changes: 2 additions & 2 deletions _config/extensions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ SilverStripe\Security\Member:
SilverStripe\Security\Group:
extensions:
- SilverStripe\Security\InheritedPermissionFlusher
SilverStripe\ORM\DatabaseAdmin:
SilverStripe\Dev\HybridExecution\Command\DevBuild:
extensions:
- SilverStripe\Dev\Validation\DatabaseAdminExtension
- SilverStripe\Dev\Validation\DevBuildExtension
4 changes: 2 additions & 2 deletions _config/logging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Only:
# Dev handler outputs detailed information including notices
SilverStripe\Core\Injector\Injector:
Monolog\Handler\HandlerInterface:
class: SilverStripe\Logging\HTTPOutputHandler
class: SilverStripe\Logging\ErrorOutputHandler
constructor:
- "notice"
properties:
Expand All @@ -66,7 +66,7 @@ Except:
# CLI errors still show full details
SilverStripe\Core\Injector\Injector:
Monolog\Handler\HandlerInterface:
class: SilverStripe\Logging\HTTPOutputHandler
class: SilverStripe\Logging\ErrorOutputHandler
constructor:
- "error"
properties:
Expand Down
4 changes: 2 additions & 2 deletions _config/mailer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ SilverStripe\Core\Injector\Injector:
class: Symfony\Component\Mailer\Mailer
constructor:
transport: '%$Symfony\Component\Mailer\Transport\TransportInterface'
Symfony\Component\EventDispatcher\EventDispatcherInterface.mailer:
Symfony\Contracts\EventDispatcher\EventDispatcherInterface.mailer:
class: Symfony\Component\EventDispatcher\EventDispatcher
calls:
- [addSubscriber, ['%$SilverStripe\Control\Email\MailerSubscriber']]
Symfony\Component\Mailer\Transport\TransportInterface:
factory: SilverStripe\Control\Email\TransportFactory
constructor:
dsn: 'sendmail://default'
dispatcher: '%$Symfony\Component\EventDispatcher\EventDispatcherInterface.mailer'
dispatcher: '%$Symfony\Contracts\EventDispatcher\EventDispatcherInterface.mailer'
2 changes: 0 additions & 2 deletions _config/requestprocessors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ SilverStripe\Core\Injector\Injector:
ConfirmationStorageId: 'url-specials'
ConfirmationFormUrl: '/dev/confirm'
Bypasses:
- '%$SilverStripe\Control\Middleware\ConfirmationMiddleware\CliBypass'
- '%$SilverStripe\Control\Middleware\ConfirmationMiddleware\EnvironmentBypass("dev")'
- '%$SilverStripe\Control\Middleware\ConfirmationMiddleware\UrlPathStartswith("dev/confirm")'
EnforceAuthentication: true
Expand Down Expand Up @@ -94,7 +93,6 @@ SilverStripe\Core\Injector\Injector:
ConfirmationStorageId: 'dev-urls'
ConfirmationFormUrl: '/dev/confirm'
Bypasses:
- '%$SilverStripe\Control\Middleware\ConfirmationMiddleware\CliBypass'
- '%$SilverStripe\Control\Middleware\ConfirmationMiddleware\EnvironmentBypass("dev")'
EnforceAuthentication: false

Expand Down
21 changes: 21 additions & 0 deletions bin/sake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env php
<?php

use SilverStripe\Cli\Sake;

// Ensure that people can't access this from a web-server
if (!in_array(PHP_SAPI, ['cli', 'cgi', 'cgi-fcgi'])) {
echo 'sake cannot be run from a web request, you have to run it on the command-line.';
die();
}

require_once __DIR__ . '/../src/includes/autoload.php';

$sake = new Sake();
$sake->addCommands([
// probably do this inside the sake app itself though
// TODO:
// - flush
// - navigate (use HTTPRequest and spin off a "web" request from CLI)
]);
$sake->run();
35 changes: 0 additions & 35 deletions cli-script.php

This file was deleted.

34 changes: 29 additions & 5 deletions client/styles/debug.css
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ a:active {
}

/* Content types */
.build,
.options,
.trace {
position: relative;
Expand All @@ -128,19 +127,19 @@ a:active {
line-height: 1.3;
}

.build .success {
.options .success {
color: #2b6c2d;
}

.build .error {
.options .error {
color: #d30000;
}

.build .warning {
.options .warning {
color: #8a6d3b;
}

.build .info {
.options .info {
color: #0073c1;
}

Expand All @@ -162,3 +161,28 @@ pre span {
pre .error {
color: #d30000;
}

.params {
margin-top: 0;
margin-left: 10px;
}

.param {
display: flex;
align-items: baseline;
}

.param__name {
display: inline-block;
font-weight: 200;
}

.param__name::after {
content: ": ";
}

.param__description {
display: inline-block;
margin-left: 0.5em;
font-style: italic;
}
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}
],
"bin": [
"sake"
"bin/sake"
],
"require": {
"php": "^8.3",
Expand All @@ -36,12 +36,14 @@
"psr/container": "^1.1 || ^2.0",
"psr/http-message": "^1",
"sebastian/diff": "^4.0",
"sensiolabs/ansi-to-html": "^1.2",
"silverstripe/config": "^3",
"silverstripe/assets": "^3",
"silverstripe/vendor-plugin": "^2",
"sminnee/callbacklist": "^0.1.1",
"symfony/cache": "^6.1",
"symfony/config": "^6.1",
"symfony/console": "^7.0",
"symfony/dom-crawler": "^6.1",
"symfony/filesystem": "^6.1",
"symfony/http-foundation": "^6.1",
Expand Down Expand Up @@ -85,6 +87,7 @@
},
"autoload": {
"psr-4": {
"SilverStripe\\Cli\\": "src/Cli/",
"SilverStripe\\Control\\": "src/Control/",
"SilverStripe\\Control\\Tests\\": "tests/php/Control/",
"SilverStripe\\Core\\": "src/Core/",
Expand Down
119 changes: 0 additions & 119 deletions sake

This file was deleted.

Loading

0 comments on commit d3cb726

Please sign in to comment.