- Added a new Email defintion (which will soon see it's components changed)
- Added a new post-install script for composer which adds a project skeleton "ready to use". - Error 500 are now handled properly in production; waiting to see if adjustements will be required before adding other code pages.
This commit is contained in:
1 parent
09b3e47c19
commit
01bb926ca7
30 files changed
+887
-2
No files matched your search
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace Lean;
|
||||
|
||||
use Composer\EventDispatcher\Event;
|
||||
|
||||
class Composer
|
||||
{
|
||||
public static function postInstall(Event $event) : void
|
||||
{
|
||||
$event->getIO()->write("post-install script executing ...");
|
||||
|
||||
if ( $event->getIO()->askConfirmation("Do you want to install Lean's Project Skeleton ? ( 'yes' or 'no' (default) ): ", false) ) {
|
||||
$ns = trim(static::getNamespaceFromAutoload($event), '\\');
|
||||
|
||||
$replace = [
|
||||
'%NAMESPACE%' => $ns,
|
||||
'%ESCAPED_NAMESPACE%' => addslashes($ns),
|
||||
'%APPKEY%' => strtolower(str_replace('\\', '.', $ns)),
|
||||
'%RAND64%' => substr(base64_encode(random_bytes(100)), 0, 64),
|
||||
];
|
||||
|
||||
$dir = static::createPath();
|
||||
|
||||
if ( is_writable($dir) ) {
|
||||
$source = static::createPath('vendor', 'mcnd', 'lean', 'skeleton');
|
||||
$dest = static::createPath('skeleton');
|
||||
|
||||
`cp -a $source $dest`;
|
||||
|
||||
$iterator = new \RecursiveDirectoryIterator($dest);
|
||||
$iterator->setFlags(\RecursiveDirectoryIterator::SKIP_DOTS);
|
||||
|
||||
foreach (new \RecursiveIteratorIterator($iterator) as $file) {
|
||||
if ( in_array($file->getExtension(), [ 'php', 'phtml', 'env' ]) ) {
|
||||
$content = str_replace(array_keys($replace), array_values($replace), file_get_contents($file->getPathname()));
|
||||
|
||||
file_put_contents($file->getPathname(), $content);
|
||||
}
|
||||
}
|
||||
|
||||
foreach(scandir(static::createPath('skeleton')) as $item) {
|
||||
if ( in_array($item, [ '.', '..' ]) ) continue;
|
||||
|
||||
rename(static::createPath('skeleton', $item), static::createPath($item));
|
||||
}
|
||||
|
||||
rmdir($dest);
|
||||
|
||||
$event->getIO()->write("Installation completed.");
|
||||
}
|
||||
else {
|
||||
$event->getIO()->writeError(sprintf("The user you are running this script with doesn't seem to have a writable permission on directory %s", static::createPath()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static function readComposerJson(Event $event) : ? array
|
||||
{
|
||||
$path = static::createPath('composer.json');
|
||||
|
||||
return file_exists($path) ? json_decode(file_get_contents($path), true) : null;
|
||||
}
|
||||
|
||||
protected static function getNamespaceFromAutoload(Event $event) : ? string
|
||||
{
|
||||
if ( null !== $composerJson = static::readComposerJson($event) ) {
|
||||
if ( $psr4 = $composerJson['autoload']['psr-4'] ?? false ) {
|
||||
foreach($psr4 as $ns => $directory) {
|
||||
if ($directory === 'src/') {
|
||||
return $ns;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$event->getIO()->writeError("Your composer file do not seem to contains a valid psr-4 project of it's autoload array.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
$event->getIO()->writeError("Composer.json file not found. Have this script been launch from the Composer CLI at the root of your project ?");
|
||||
}
|
||||
|
||||
$event->getIO()->writeError("Your composer file do not seem to contains a valid psr-4 project pointing to the src folder.");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static function createPath(... $path) : string
|
||||
{
|
||||
return implode(DIRECTORY_SEPARATOR, array_merge([ $_SERVER['PWD'] ], $path));
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace Lean;
|
||||
|
||||
use CSLSJ\Common\RequestResponse\DownloadResponse;
|
||||
use CSLSJ\Common\RequestResponse\ImageResponse;
|
||||
use CSLSJ\Common\RequestResponse\{ PdfResponse, ImageResponse, DownloadResponse };
|
||||
|
||||
use Picea,
|
||||
Picea\Ui\Method\FormContext;
|
||||
|
||||
@@ -63,6 +63,11 @@ trait ControllerTrait {
|
||||
return new RedirectResponse($url, $code, $headers);
|
||||
}
|
||||
|
||||
public function renderPdf($rawdata, int $status = 200, array $headers = []) : PdfResponse
|
||||
{
|
||||
return new PdfResponse($rawdata, $status, $headers);
|
||||
}
|
||||
|
||||
public static function renderText(string $html, int $code = 200, array $headers = []) : ResponseInterface
|
||||
{
|
||||
return new TextResponse($html, $code, $headers);
|
||||
|
||||
@@ -107,6 +107,7 @@ class Lean
|
||||
$path = dirname(__DIR__) . "/meta/definitions/";
|
||||
|
||||
return array_merge(
|
||||
require($path . "email.php"),
|
||||
require($path . "http.php"),
|
||||
require($path . "language.php"),
|
||||
require($path . "routes.php"),
|
||||
|
||||
Reference in new issue
Block a user