Sistema web para crear proyecto web nuevo
This commit is contained in:
20
REQUIREMENTS.md
Normal file
20
REQUIREMENTS.md
Normal file
@ -0,0 +1,20 @@
|
||||
# Requerimientos
|
||||
|
||||
1. [x] Creacion de nuevos proyectos
|
||||
1. [x] Seleccion de dependencias
|
||||
2. [x] Creacion de carpetas
|
||||
3. [x] Creacion de composer.json
|
||||
4. [x] Creacion de archivos "minimos"
|
||||
5. [x] Git init
|
||||
6. [x] Git .gitignore
|
||||
7. [x] Git commit inicial "Inicio de Git"
|
||||
8. [x] Git checkout develop branch
|
||||
9. [x] Git commit archivos "Seteo inicial"
|
||||
10. [x] Composer install
|
||||
2. [x] Agregar controlador
|
||||
1. [x] Web
|
||||
2. [x] API
|
||||
3. [x] CLI
|
||||
3. [x] Agregar template
|
||||
1. [x] Elegir seccion
|
||||
4. [ ] Agregar librerias
|
62
common/Controller/API/Create.php
Normal file
62
common/Controller/API/Create.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
namespace ProVM\Projects\Common\Controller\API;
|
||||
|
||||
use Psr\Http\Message\RequestInterface as Request;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use ProVM\Common\Define\Controller\Json;
|
||||
use ProVM\Projects\Common\Service\Projects;
|
||||
|
||||
class Create {
|
||||
use Json;
|
||||
|
||||
public function createFolder(Request $request, Response $response, Projects $service, $project): Response {
|
||||
$estado = $service->createFolder($project);
|
||||
$output = [
|
||||
'project' => $project,
|
||||
'estado' => $estado
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function createSubfolders(Request $request, Response $response, Projects $service, $project): Response {
|
||||
$estado = $service->createSubfolders($project);
|
||||
$output = [
|
||||
'project' => $project,
|
||||
'estado' => $estado
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function gitInit(Request $request, Response $response, Projects $service, $project): Response {
|
||||
$estado = $service->gitInit($project);
|
||||
$output = [
|
||||
'project' => $project,
|
||||
'estado' => $estado
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function addComposer(Request $request, Response $response, Projects $service, $project): Response {
|
||||
$post = $request->getParsedBody();
|
||||
$estado = $service->addComposer($project, $post['composer']);
|
||||
$output = [
|
||||
'project' => $project,
|
||||
'estado' => $estado
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function addFiles(Request $request, Response $response, Projects $service, $project): Response {
|
||||
$estado = $service->addFiles($project);
|
||||
$output = [
|
||||
'project' => $project,
|
||||
'estado' => $estado
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function gitPush(Request $request, Response $response, Projects $service, $project): Response {
|
||||
$estado = $service->gitPush($project);
|
||||
$output = [
|
||||
'project' => $project,
|
||||
'estado' => $estado['estado'],
|
||||
'error' => $estado['error']
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
37
common/Controller/API/Dependencies.php
Normal file
37
common/Controller/API/Dependencies.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
namespace ProVM\Projects\Common\Controller\API;
|
||||
|
||||
use Psr\Container\ContainerInterface as Container;
|
||||
use Psr\Http\Message\RequestInterface as Request;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use ProVM\Common\Define\Controller\Json;
|
||||
use ProVM\Common\Service\Composer;
|
||||
|
||||
class Dependencies {
|
||||
use Json;
|
||||
|
||||
public function search(Request $request, Response $response, Composer $composer): Response {
|
||||
$get = $request->getQueryParams();
|
||||
$query = $get['query'];
|
||||
if (strlen($query) < 3) {
|
||||
$output = [
|
||||
'success' => false,
|
||||
'results' => []
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
$results = $composer->search($query);
|
||||
$output = [
|
||||
'success' => (count($results) > 0),
|
||||
'results' => []
|
||||
];
|
||||
foreach ($results as $result) {
|
||||
$output['results'] []= [
|
||||
'value' => $result->name,
|
||||
'name' => implode(': ', (array) $result),
|
||||
'text' => $result->name
|
||||
];
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
75
common/Controller/Web/Create.php
Normal file
75
common/Controller/Web/Create.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
namespace ProVM\Projects\Common\Controller\Web;
|
||||
|
||||
use Psr\Http\Message\RequestInterface as Request;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use ProVM\Common\Alias\View;
|
||||
use ProVM\Common\Service\Composer;
|
||||
use ProVM\Projects\Common\Service\Projects;
|
||||
|
||||
class Create {
|
||||
/**
|
||||
* Step 1
|
||||
* Formulario de datos
|
||||
*/
|
||||
public function __invoke(Request $request, Response $response, View $view): Response {
|
||||
$defaults = (object) [
|
||||
'require' => [
|
||||
'slim/slim',
|
||||
'nyholm/psr7',
|
||||
'nyholm/psr7-server',
|
||||
'php-di/slim-bridge',
|
||||
'rubellum/slim-blade-view',
|
||||
'nesbot/carbon'
|
||||
],
|
||||
'require-dev' => [
|
||||
'phpunit/phpunit',
|
||||
'kint-php/kint'
|
||||
]
|
||||
];
|
||||
return $view->render($response, 'create.step1', compact('defaults'));
|
||||
}
|
||||
/**
|
||||
* Step 2
|
||||
* Revision y confirmacion de datos
|
||||
*/
|
||||
public function step2(Request $request, Response $response, Composer $composer, Projects $service, View $view): Response {
|
||||
$post = $request->getParsedBody();
|
||||
$name = $post['nombre'];
|
||||
$exists = $service->exists($name);
|
||||
$require = explode(',', $post['dependencias'][0]);
|
||||
$require = $composer->getLatest($require, Composer::MAYOR);
|
||||
$require_dev = explode(',', $post['dependencias-dev'][0]);
|
||||
$require_dev = $composer->getLatest($require_dev, Composer::MAYOR);
|
||||
$json = json_encode([
|
||||
'name' => implode('/', ['provm', $name]),
|
||||
'descripcion' => $post['descripcion'],
|
||||
'type' => 'project',
|
||||
'require' => $require,
|
||||
'require-dev' => $require_dev,
|
||||
'authors' => [
|
||||
[
|
||||
'name' => 'Aldarien',
|
||||
'email' => 'aldarien85@gmail.com'
|
||||
]
|
||||
],
|
||||
'autoload' => [
|
||||
'psr-4' => [
|
||||
implode("\\", [
|
||||
'ProVM',
|
||||
ucwords($post['nombre']),
|
||||
'Common'
|
||||
]) . "\\" => 'common'
|
||||
]
|
||||
]
|
||||
], \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE);
|
||||
return $view->render($response, 'create.step2', ['step' => 2, 'exists' => $exists, 'composer' => $json]);
|
||||
}
|
||||
public function step3(Request $request, Response $response, Projects $service, View $view): Response {
|
||||
$post = $request->getParsedBody();
|
||||
$name = explode('/', json_decode($post['composer'])->name)[1];
|
||||
$composer = $post['composer'];
|
||||
$step = 3;
|
||||
return $view->render($response, 'create.step3', compact('step', 'name', 'composer'));
|
||||
}
|
||||
}
|
14
common/Controller/Web/Home.php
Normal file
14
common/Controller/Web/Home.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
namespace ProVM\Projects\Common\Controller\Web;
|
||||
|
||||
use Psr\Http\Message\RequestInterface as Request;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use ProVM\Common\Alias\View;
|
||||
use ProVM\Projects\Common\Service\Projects;
|
||||
|
||||
class Home {
|
||||
public function __invoke(Request $request, Response $response, Projects $service, View $view): Response {
|
||||
$projects = $service->list();
|
||||
return $view->render($response, 'home', compact('projects'));
|
||||
}
|
||||
}
|
181
common/Controller/Web/Project.php
Normal file
181
common/Controller/Web/Project.php
Normal file
@ -0,0 +1,181 @@
|
||||
<?php
|
||||
namespace ProVM\Projects\Common\Controller\Web;
|
||||
|
||||
use Psr\Container\ContainerInterface as Container;
|
||||
use Psr\Http\Message\RequestInterface as Request;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use ProVM\Common\Alias\View;
|
||||
use ProVM\Common\Define\Controller\Redirect;
|
||||
use ProVM\Projects\Common\Service\Projects;
|
||||
use ProVM\Projects\Common\Factory\Project as Factory;
|
||||
|
||||
class Project {
|
||||
use Redirect;
|
||||
|
||||
public function __invoke(Request $request, Response $response, Projects $service, View $view, $project): Response {
|
||||
$p = $service->get($project);
|
||||
$p->config = $this->reduceFiles($p->config, '/setup', '', '/');
|
||||
$p->controllers = $this->reduceFiles($p->controllers, ['/common', 'ProVM/' . ucwords($project) . '/Common'], '.php', '/');
|
||||
foreach ($p->routes as $space => $routes) {
|
||||
$p->routes->$space = $this->reduceFiles($routes, '/resources/routes', '', '/');
|
||||
}
|
||||
$p->views = $this->reduceFiles($p->views, '/resources/views/', '.blade.php', '.');
|
||||
return $view->render($response, 'projects.show', ['project' => $p]);
|
||||
}
|
||||
protected function reduceFiles($array, $prefix, $suffix, $glue) {
|
||||
if (!is_array($prefix)) {
|
||||
$prefix = [$prefix];
|
||||
}
|
||||
if (!is_array($suffix)) {
|
||||
$suffix = [$suffix];
|
||||
}
|
||||
$arr = [];
|
||||
$it = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($array), \RecursiveIteratorIterator::SELF_FIRST);
|
||||
$pk = '';
|
||||
foreach ($it as $k => $v) {
|
||||
if (is_array($v)) {
|
||||
$pk = str_replace($prefix[0], $prefix[1] ?? '', $k);
|
||||
continue;
|
||||
}
|
||||
$arr []= str_replace($suffix[0], $suffix[1] ?? '', implode($glue, [$pk, $v]));
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
public function addView(Request $request, Response $response, Projects $service, View $view, $project): Response {
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [
|
||||
$service->getFolder($project),
|
||||
'resources',
|
||||
'views'
|
||||
]);
|
||||
$files = new \DirectoryIterator($folder);
|
||||
$subfolders = [];
|
||||
foreach ($files as $file) {
|
||||
if (!$file->isDir() or $file->isDot()) {
|
||||
continue;
|
||||
}
|
||||
$subfolders []= $file->getBasename();
|
||||
}
|
||||
$factory = new Factory();
|
||||
$p = $factory->find($service->getFolder($project))->getViews()->build();
|
||||
$views = [];
|
||||
$it = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($p->views), \RecursiveIteratorIterator::SELF_FIRST);
|
||||
$pk = '';
|
||||
foreach ($it as $k => $v) {
|
||||
if (is_array($v)) {
|
||||
$pk = str_replace('/resources/views/', '', $k);
|
||||
continue;
|
||||
}
|
||||
$views []= str_replace('.blade.php', '', implode('.', [$pk, $v]));
|
||||
}
|
||||
$project = $p;
|
||||
return $view->render($response, 'projects.views.add', compact('project', 'subfolders', 'views'));
|
||||
}
|
||||
public function doAddView(Request $request, Response $response, Container $container, Projects $service, $project): Response {
|
||||
$post = $request->getParsedBody();
|
||||
$options = [];
|
||||
if (trim($post['extends']) != '') {
|
||||
$options['extends'] = $post['extends'];
|
||||
}
|
||||
if (trim($post['seccion']) != '') {
|
||||
$options['section'] = $post['seccion'];
|
||||
}
|
||||
$location = $post['location'];
|
||||
$status = $service->addView($project, $post['name'], $location, $options);
|
||||
return $this->withRedirect($response, implode('/', [
|
||||
$container->get('urls')->base,
|
||||
'project',
|
||||
$project
|
||||
]));
|
||||
}
|
||||
public function addController(Request $request, Response $response, Projects $service, View $view, $project): Response {
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [
|
||||
$service->getFolder($project),
|
||||
'common',
|
||||
'Controller'
|
||||
]);
|
||||
$files = new \DirectoryIterator($folder);
|
||||
$subfolders = [];
|
||||
foreach ($files as $file) {
|
||||
if (!$file->isDir() or $file->isDot()) {
|
||||
continue;
|
||||
}
|
||||
$subfolders []= $file->getBasename();
|
||||
}
|
||||
$factory = new Factory();
|
||||
$p = $factory->find($service->getFolder($project))->getViews()->build();
|
||||
$views = [];
|
||||
$it = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($p->views), \RecursiveIteratorIterator::SELF_FIRST);
|
||||
$pk = '';
|
||||
foreach ($it as $k => $v) {
|
||||
if (is_array($v)) {
|
||||
$pk = str_replace('/resources/views/', '', $k);
|
||||
continue;
|
||||
}
|
||||
$views []= str_replace('.blade.php', '', implode('.', [$pk, $v]));
|
||||
}
|
||||
$project = $p;
|
||||
return $view->render($response, 'projects.controllers.add', compact('project', 'subfolders', 'views'));
|
||||
}
|
||||
public function doAddController(Request $request, Response $response, Container $container, Projects $service, $project): Response {
|
||||
$post = $request->getParsedBody();
|
||||
$name = str_replace(' ', '', ucwords($post['name']));
|
||||
$status = $service->addController($project, $post['space'], $name, $post['template']);
|
||||
return $this->withRedirect($response, implode('/', [
|
||||
$container->get('urls')->base,
|
||||
'project',
|
||||
$project
|
||||
]));
|
||||
}
|
||||
public function addRoute(Request $request, Response $response, Projects $service, View $view, $project): Response {
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [
|
||||
$service->getFolder($project),
|
||||
'resources',
|
||||
'routes'
|
||||
]);
|
||||
$files = new \DirectoryIterator($folder);
|
||||
$subfolders = [];
|
||||
foreach ($files as $file) {
|
||||
if (!$file->isDir() or $file->isDot()) {
|
||||
continue;
|
||||
}
|
||||
$subfolders []= $file->getBasename();
|
||||
}
|
||||
$factory = new Factory();
|
||||
$p = $factory->find($service->getFolder($project))->getViews()->getControllers()->build();
|
||||
$views = [];
|
||||
$it = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($p->views), \RecursiveIteratorIterator::SELF_FIRST);
|
||||
$pk = '';
|
||||
foreach ($it as $k => $v) {
|
||||
if (is_array($v)) {
|
||||
$pk = str_replace('/resources/views/', '', $k);
|
||||
continue;
|
||||
}
|
||||
$views []= str_replace('.blade.php', '', implode('.', [$pk, $v]));
|
||||
}
|
||||
$controllers = [];
|
||||
$it = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($p->controllers), \RecursiveIteratorIterator::SELF_FIRST);
|
||||
$pk = '';
|
||||
foreach ($it as $k => $v) {
|
||||
if (is_array($v)) {
|
||||
$pk = str_replace('/common', 'ProVM/Projects/Common', $k);
|
||||
continue;
|
||||
}
|
||||
$controllers []= str_replace(['/', '.php'], ["\\", ''], implode('/', [$pk, $v]));
|
||||
}
|
||||
$project = $p;
|
||||
return $view->render($response, 'projects.routes.add', compact('project', 'subfolders', 'views', 'controllers'));
|
||||
}
|
||||
public function doAddRoute(Request $request, Response $response, Container $container, Projects $service, $project): Response {
|
||||
$post = $request->getParsedBody();
|
||||
$space = $post['space'];
|
||||
$name = $post['group'];
|
||||
$route = $post['name'];
|
||||
$callback = $post['controller'] . '::class';
|
||||
$service->addRoute($project, $space, $name, $route, $callback);
|
||||
return $this->withRedirect($response, implode('/', [
|
||||
$container->get('urls')->base,
|
||||
'project',
|
||||
$project
|
||||
]));
|
||||
}
|
||||
}
|
135
common/Factory/Project.php
Normal file
135
common/Factory/Project.php
Normal file
@ -0,0 +1,135 @@
|
||||
<?php
|
||||
namespace ProVM\Projects\Common\Factory;
|
||||
|
||||
use Cz\Git\GitRepository;
|
||||
|
||||
class Project {
|
||||
protected $folder;
|
||||
protected $data;
|
||||
public function find(string $folder): Project {
|
||||
if (!file_exists($folder)) {
|
||||
throw new \Exception('Proyecto no existe. ' . $folder);
|
||||
}
|
||||
$this->folder = realpath($folder);
|
||||
$name = array_pop(explode(DIRECTORY_SEPARATOR, $this->folder));
|
||||
$this->data = [
|
||||
'name' => implode('/', ['provm', $name]),
|
||||
'base_name' => $name,
|
||||
'folder' => $this->folder
|
||||
];
|
||||
return $this;
|
||||
}
|
||||
public function build() {
|
||||
return json_decode(json_encode($this->data));
|
||||
}
|
||||
public function getAll(): Project {
|
||||
return $this
|
||||
->getGit()
|
||||
->getComposer()
|
||||
->getConfig()
|
||||
->getControllers()
|
||||
->getServices()
|
||||
->getRoutes()
|
||||
->getViews();
|
||||
}
|
||||
public function getGit(): Project {
|
||||
$repo = new GitRepository($this->folder);
|
||||
$status = $repo->execute('status');
|
||||
$this->data['git'] = $status;
|
||||
return $this;
|
||||
}
|
||||
public function getComposer(): Project {
|
||||
$filename = implode(DIRECTORY_SEPARATOR, [$this->folder, 'composer.json']);
|
||||
$this->data['composer'] = json_decode(trim(file_get_contents($filename)));
|
||||
return $this;
|
||||
}
|
||||
protected function getFolderFiles(string $name, string $folder) {
|
||||
if (!file_exists($folder)) {
|
||||
return $this;
|
||||
}
|
||||
$files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($folder));
|
||||
$output = [];
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir()) {
|
||||
continue;
|
||||
}
|
||||
$dir = rtrim(str_replace([$file->getBasename(), $this->folder, "\\"], ['', '', '/'], $file->getRealPath()), '/');
|
||||
if (!isset($output[$dir])) {
|
||||
$output[$dir] = [];
|
||||
}
|
||||
$output[$dir] []= $file->getBasename();
|
||||
}
|
||||
ksort($output);
|
||||
$this->data[$name] = $output;
|
||||
}
|
||||
public function getConfig(): Project {
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [
|
||||
$this->folder,
|
||||
'setup'
|
||||
]);
|
||||
$this->getFolderFiles('config', $folder);
|
||||
return $this;
|
||||
}
|
||||
public function getControllers(): Project {
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [$this->folder, 'common', 'Controller']);
|
||||
$this->getFolderFiles('controllers', $folder);
|
||||
return $this;
|
||||
}
|
||||
public function getServices(): Project {
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [$this->folder, 'common', 'Service']);
|
||||
$this->getFolderFiles('services', $folder);
|
||||
return $this;
|
||||
}
|
||||
public function getRoutes(): Project {
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [
|
||||
$this->folder,
|
||||
'resources',
|
||||
'routes'
|
||||
]);
|
||||
$output = [];
|
||||
$folders = new \DirectoryIterator($folder);
|
||||
foreach ($folders as $folder) {
|
||||
if (!$folder->isDir() or $folder->isDot()) {
|
||||
continue;
|
||||
}
|
||||
$output[$folder->getBasename()] = $this->getSpaceRoutes($folder->getRealPath());
|
||||
}
|
||||
$this->data['routes'] = $output;
|
||||
return $this;
|
||||
}
|
||||
protected function getSpaceRoutes(string $folder) {
|
||||
if (!file_exists($folder)) {
|
||||
return [];
|
||||
}
|
||||
$files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($folder));
|
||||
$output = [];
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir()) {
|
||||
continue;
|
||||
}
|
||||
$dir = rtrim(str_replace([$file->getBasename(), $this->folder, "\\"], ['', '', '/'], $file->getRealPath()), '/');
|
||||
if (!isset($output[$dir])) {
|
||||
$output[$dir] = [];
|
||||
}
|
||||
$output[$dir] []= $file->getBasename();
|
||||
}
|
||||
ksort($output);
|
||||
return $output;
|
||||
}
|
||||
public function getViews(): Project {
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [
|
||||
$this->folder,
|
||||
'resources',
|
||||
'views'
|
||||
]);
|
||||
$this->getFolderFiles('views', $folder);
|
||||
/*array_walk($this->data['views'], function(&$item) {
|
||||
if (is_array($item)) {
|
||||
array_walk($item, function(&$i) {
|
||||
$i = str_replace('.blade', '', $i);
|
||||
});
|
||||
}
|
||||
});*/
|
||||
return $this;
|
||||
}
|
||||
}
|
733
common/Service/Projects.php
Normal file
733
common/Service/Projects.php
Normal file
@ -0,0 +1,733 @@
|
||||
<?php
|
||||
namespace ProVM\Projects\Common\Service;
|
||||
|
||||
use Cz\Git\GitRepository;
|
||||
use ProVM\Projects\Common\Factory\Project as Factory;
|
||||
|
||||
class Projects {
|
||||
protected $folder;
|
||||
public function __construct(string $projects_folder) {
|
||||
$this->folder = $projects_folder;
|
||||
}
|
||||
public function getFolder(string $project = ''): string {
|
||||
if (trim($project) == '') {
|
||||
return $this->folder;
|
||||
}
|
||||
return implode(DIRECTORY_SEPARATOR, [
|
||||
$this->folder,
|
||||
$project
|
||||
]);
|
||||
}
|
||||
protected $projects;
|
||||
public function list(): array {
|
||||
if ($this->projects === null) {
|
||||
$folders = [];
|
||||
$files = new \DirectoryIterator($this->folder);
|
||||
foreach ($files as $file) {
|
||||
if (!$file->isDir() or $file->isDot()) {
|
||||
continue;
|
||||
}
|
||||
$folders []= (object) [
|
||||
'name' => $file->getBasename(),
|
||||
'folder' => $file->getRealPath()
|
||||
];
|
||||
}
|
||||
$this->projects = $folders;
|
||||
}
|
||||
return $this->projects;
|
||||
}
|
||||
public function exists(string $project): bool {
|
||||
$folder = $this->getFolder($project);
|
||||
return file_exists($folder);
|
||||
}
|
||||
public function get(string $project) {
|
||||
$folder = $this->getFolder($project);
|
||||
$factory = new Factory();
|
||||
return $factory
|
||||
->find($folder)
|
||||
->getAll()
|
||||
->build();
|
||||
}
|
||||
|
||||
public function create(string $project) {
|
||||
$this->createFolder($project);
|
||||
}
|
||||
public function createFolder(string $project): bool {
|
||||
if ($this->exists($project)) {
|
||||
return false;
|
||||
}
|
||||
$folder = $this->getFolder($project);
|
||||
$status = mkdir($folder);
|
||||
$status &= file_exists($folder);
|
||||
return $status;
|
||||
}
|
||||
public function createSubfolders(string $project): bool {
|
||||
if (!$this->exists($project)) {
|
||||
return false;
|
||||
}
|
||||
$folders = [
|
||||
'cache',
|
||||
'common',
|
||||
'common/Controller',
|
||||
'common/Controller/Web',
|
||||
'public',
|
||||
'resources',
|
||||
'resources/routes',
|
||||
'resources/routes/web',
|
||||
'resources/views',
|
||||
'resources/views/layout',
|
||||
'setup',
|
||||
'setup/env',
|
||||
'setup/common',
|
||||
'setup/web'
|
||||
];
|
||||
$status = false;
|
||||
foreach ($folders as $folder) {
|
||||
$f = implode(DIRECTORY_SEPARATOR, [
|
||||
$this->folder,
|
||||
$project,
|
||||
$folder
|
||||
]);
|
||||
if (file_exists($f)) {
|
||||
continue;
|
||||
}
|
||||
$status |= mkdir($f);
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
public function gitInit(string $project): bool {
|
||||
if (!$this->exists($project)) {
|
||||
return false;
|
||||
}
|
||||
$content = [
|
||||
'# Composer',
|
||||
'/vendor/',
|
||||
'composer.lock',
|
||||
'',
|
||||
'# Blade',
|
||||
'/cache/',
|
||||
'',
|
||||
'# Env',
|
||||
'/setup/env/'
|
||||
];
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [
|
||||
$this->folder,
|
||||
$project
|
||||
]);
|
||||
$filename = implode(DIRECTORY_SEPARATOR, [
|
||||
$folder,
|
||||
'.gitignore'
|
||||
]);
|
||||
$status = (file_put_contents($filename, implode(PHP_EOL, $content)) !== false);
|
||||
$repo = GitRepository::init($folder);
|
||||
$repo->execute([
|
||||
'config',
|
||||
'--global',
|
||||
'user.name',
|
||||
'Aldarien'
|
||||
]);
|
||||
$repo->execute([
|
||||
'config',
|
||||
'--global',
|
||||
'user.email',
|
||||
'aldarien85@gmail.com'
|
||||
]);
|
||||
$repo->addFile('.gitignore');
|
||||
$repo->commit('Inicio de Git');
|
||||
$repo->createBranch('develop', true);
|
||||
return $status;
|
||||
}
|
||||
public function addComposer(string $project, string $json): bool {
|
||||
if (!$this->exists($project)) {
|
||||
return false;
|
||||
}
|
||||
$folder = $this->getFolder($project);
|
||||
$filename = implode(DIRECTORY_SEPARATOR, [
|
||||
$folder,
|
||||
'composer.json'
|
||||
]);
|
||||
$status = (file_put_contents($filename, $json) !== false);
|
||||
$current = getcwd();
|
||||
$s = chdir($folder);
|
||||
if ($s) {
|
||||
exec('composer install');
|
||||
$status &= (file_exists(implode(DIRECTORY_SEPARATOR, [$folder, 'vendor'])));
|
||||
chdir($current);
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
public function addFiles(string $project): bool {
|
||||
if (!$this->exists($project)) {
|
||||
return false;
|
||||
}
|
||||
$folder = $this->getFolder($project);
|
||||
$methods = [
|
||||
'SetupApp',
|
||||
'SetupComposer',
|
||||
'SetupCommonConfig',
|
||||
'SetupWebConfig',
|
||||
'SetupWebSetup',
|
||||
'PublicIndex',
|
||||
'PublicHtaccess',
|
||||
'RoutesRouter',
|
||||
'RoutesWeb',
|
||||
'LayoutBase',
|
||||
'LayoutBody',
|
||||
'LayoutFooter',
|
||||
'LayoutHead',
|
||||
'LayoutHeader',
|
||||
'LayoutMenu',
|
||||
'LayoutScripts',
|
||||
'LayoutStyles'
|
||||
];
|
||||
$status = true;
|
||||
foreach ($methods as $method) {
|
||||
$m = 'add' . $method . 'File';
|
||||
$status &= $this->$m($folder);
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
protected function createFile(string $folder, string $file_name, array $content): bool {
|
||||
$filename = implode(DIRECTORY_SEPARATOR, [
|
||||
$folder,
|
||||
$file_name
|
||||
]);
|
||||
$status = (file_put_contents($filename, implode(PHP_EOL, $content)) !== false);
|
||||
$status &= file_exists($filename);
|
||||
return $status;
|
||||
}
|
||||
protected function addSetupAppFile(string $folder): bool {
|
||||
$content = [
|
||||
"<?php",
|
||||
"use DI\ContainerBuilder as Builder;",
|
||||
"use DI\Bridge\Slim\Bridge;",
|
||||
'',
|
||||
"if (!isset(\$__environment)) {",
|
||||
" throw new Exception('Missing __environment variable');",
|
||||
"}",
|
||||
'',
|
||||
"include_once 'composer.php';",
|
||||
'',
|
||||
"\$builder = new Builder();",
|
||||
'',
|
||||
"\$files = [",
|
||||
" 'config',",
|
||||
" 'setup'",
|
||||
"];",
|
||||
"\$folders = [",
|
||||
" 'common',",
|
||||
" \$__environment",
|
||||
"];",
|
||||
'',
|
||||
"foreach (\$files as \$file) {",
|
||||
" foreach (\$folders as \$folder) {",
|
||||
" \$filename = implode(DIRECTORY_SEPARATOR, [",
|
||||
" __DIR__,",
|
||||
" \$folder,",
|
||||
" \$file . '.php'",
|
||||
" ]);",
|
||||
" if (file_exists(\$filename)) {",
|
||||
" \$builder->addDefinitions(\$filename);",
|
||||
" }",
|
||||
" }",
|
||||
"}",
|
||||
'',
|
||||
"\$container = \$builder->build();",
|
||||
"\$app = Bridge::create(\$container);",
|
||||
"try {",
|
||||
" \$app->setBasePath(\$container->get('base_url'));",
|
||||
"} catch (Exception \$e) {",
|
||||
"}",
|
||||
'',
|
||||
"foreach (\$folders as \$folder) {",
|
||||
" \$filename = implode(DIRECTORY_SEPARATOR, [",
|
||||
" __DIR__,",
|
||||
" \$folder,",
|
||||
" 'middleware.php'",
|
||||
" ]);",
|
||||
" if (file_exists(\$filename)) {",
|
||||
" include_once \$filename;",
|
||||
" }",
|
||||
"}",
|
||||
'',
|
||||
"\$filename = implode(DIRECTORY_SEPARATOR, [",
|
||||
" \$container->get('folders')->routes,",
|
||||
" 'router.php'",
|
||||
"]);",
|
||||
"if (!file_exists(\$filename)) {",
|
||||
" throw new Exception('Missing router file.');",
|
||||
"}",
|
||||
"include_once \$filename;"
|
||||
];
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [
|
||||
$folder,
|
||||
'setup'
|
||||
]);
|
||||
return $this->createFile($folder, 'app.php', $content);
|
||||
}
|
||||
protected function addSetupComposerFile(string $folder): bool {
|
||||
$content = [
|
||||
'<?php',
|
||||
"\$filename = implode(DIRECTORY_SEPARATOR, [",
|
||||
" dirname(__DIR__)",
|
||||
" 'vendor'",
|
||||
" 'autoload.php'",
|
||||
"])",
|
||||
"if (!file_exists(\$filename)) {",
|
||||
" throw new Exception('Missing composer install.');",
|
||||
"}",
|
||||
"include_once \$filename;"
|
||||
];
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [
|
||||
$folder,
|
||||
'setup'
|
||||
]);
|
||||
return $this->createFile($folder, 'composer.php', $content);
|
||||
}
|
||||
protected function addSetupCommonConfigFile(string $folder): bool {
|
||||
$project = explode(DIRECTORY_SEPARATOR, $folder);
|
||||
array_pop($project); // common
|
||||
array_pop($project); // setup
|
||||
$project = array_pop($project);
|
||||
$content = [
|
||||
'<?php',
|
||||
'return [',
|
||||
" 'base_url' => dirname(__DIR__),",
|
||||
" 'urls' => function() {",
|
||||
" \$arr = [];",
|
||||
" \$arr['base'] = '/provm/demos/{$project}';",
|
||||
" return (object) \$arr;",
|
||||
" },",
|
||||
" 'folders' => function() {",
|
||||
" \$arr = [];",
|
||||
" \$arr['base'] = dirname(__DIR__, 2);",
|
||||
" \$arr['resources'] = implode(DIRECTORY_SEPARATOR, [",
|
||||
" \$arr['base'],",
|
||||
" 'resources'",
|
||||
" ]);",
|
||||
" \$arr['routes'] = implode(DIRECTORY_SEPARATOR, [",
|
||||
" \$arr['resources'],",
|
||||
" 'routes'",
|
||||
" ]);",
|
||||
" return (object) \$arr;",
|
||||
" }",
|
||||
'];'
|
||||
];
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [
|
||||
$folder,
|
||||
'setup',
|
||||
'common'
|
||||
]);
|
||||
return $this->createFile($folder, 'config.php', $content);
|
||||
}
|
||||
protected function addSetupWebConfigFile(string $folder): bool {
|
||||
$content = [
|
||||
"<?php",
|
||||
"use Psr\Container\ContainerInterface as Container;",
|
||||
'',
|
||||
"return [",
|
||||
" 'folders' => DI\decorate(function(\$prev, Container \$c) {",
|
||||
" \$arr = (array) \$prev;",
|
||||
" \$arr['templates'] = implode(DIRECTORY_SEPARATOR, [",
|
||||
" \$prev->resources,",
|
||||
" 'views'",
|
||||
" ]);",
|
||||
" \$arr['cache'] = implode(DIRECTORY_SEPARATOR, [",
|
||||
" \$prev->base,",
|
||||
" 'cache'",
|
||||
" ]);",
|
||||
" return (object) \$arr;",
|
||||
" }),",
|
||||
" 'assets' => (object) [",
|
||||
" 'styles' => [",
|
||||
" 'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.6/semantic.min.css'",
|
||||
" ],",
|
||||
" 'scripts' => [",
|
||||
" 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js',",
|
||||
" 'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.6/semantic.min.js'",
|
||||
" ],",
|
||||
" 'fonts' => [",
|
||||
" 'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.6/themes/default/assets/fonts/brand-icons.woff',",
|
||||
" 'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.6/themes/default/assets/fonts/brand-icons.woff2',",
|
||||
" 'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.6/themes/default/assets/fonts/icons.woff',",
|
||||
" 'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.6/themes/default/assets/fonts/icons.woff2',",
|
||||
" 'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.6/themes/default/assets/fonts/outline-icons.woff',",
|
||||
" 'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.6/themes/default/assets/fonts/outline-icons.woff2'",
|
||||
" ]",
|
||||
" ]",
|
||||
"];"
|
||||
];
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [
|
||||
$folder,
|
||||
'setup',
|
||||
'web'
|
||||
]);
|
||||
return $this->createFile($folder, 'config.app', $content);
|
||||
}
|
||||
protected function addSetupWebSetupFile(string $folder): bool {
|
||||
$content = [
|
||||
"<?php",
|
||||
"use Psr\Container\ContainerInterface as Container;",
|
||||
'',
|
||||
"return [",
|
||||
" ProVM\Common\Alias\View::class => function(Container \$c) {",
|
||||
" return new ProVM\Common\Define\View(",
|
||||
" \$c->get('folders')->templates,",
|
||||
" \$c->get('folders')->cache,",
|
||||
" null,",
|
||||
" [",
|
||||
" 'urls' => \$c->get('urls'),",
|
||||
" 'assets' => \$c->get('assets')",
|
||||
" ]",
|
||||
" );",
|
||||
" }",
|
||||
"];"
|
||||
];
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [
|
||||
$folder,
|
||||
'setup',
|
||||
'web'
|
||||
]);
|
||||
return $this->createFile($folder, 'setup.php', $content);
|
||||
}
|
||||
protected function addPublicIndexFile(string $folder): bool {
|
||||
$content = [
|
||||
"<?php",
|
||||
"\$__environment = 'web';",
|
||||
"include_once implode(DIRECTORY_SEPARATOR, [",
|
||||
" dirname(__DIR__),",
|
||||
" 'setup',",
|
||||
" 'app.php'",
|
||||
"]);",
|
||||
"\$app->run();",
|
||||
""
|
||||
];
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [
|
||||
$folder,
|
||||
'public'
|
||||
]);
|
||||
return $this->createFile($folder, 'index.php', $content);
|
||||
}
|
||||
protected function addPublicHtaccessFile(string $folder): bool {
|
||||
$content = [
|
||||
"RewriteEngine On",
|
||||
"RewriteCond %{REQUEST_FILENAME} !-f",
|
||||
"RewriteCond %{REQUEST_FILENAME} !-d",
|
||||
"RewriteRule ^ index.php [QSA,L]"
|
||||
];
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [
|
||||
$folder,
|
||||
'public'
|
||||
]);
|
||||
return $this->createFile($folder, '.htaccess', $content);
|
||||
}
|
||||
protected function addRoutesRouterFile(string $folder): bool {
|
||||
$content = [
|
||||
"<?php",
|
||||
"include_once $__environment . '.php';",
|
||||
""
|
||||
];
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [
|
||||
$folder,
|
||||
'resources',
|
||||
'routes'
|
||||
]);
|
||||
return $this->createFile($folder, 'router.php', $content);
|
||||
}
|
||||
protected function addRoutesWebFile(string $folder): bool {
|
||||
$content = [
|
||||
"<?php",
|
||||
"\$folder = implode(DIRECTORY_SEPARATOR, [",
|
||||
" __DIR__,",
|
||||
" 'web'",
|
||||
"]);",
|
||||
"if (file_exists(\$folder)) {",
|
||||
" \$files = new DirectoryIterator(\$folder);",
|
||||
" foreach (\$files as \$file) {",
|
||||
" if (\$file->isDir()) {",
|
||||
" continue;",
|
||||
" }",
|
||||
" include_once \$file->getRealPath();",
|
||||
" }",
|
||||
"}"
|
||||
];
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [
|
||||
$folder,
|
||||
'resources',
|
||||
'routes'
|
||||
]);
|
||||
return $this->createFile($folder, 'web.php', $content);
|
||||
}
|
||||
protected function addLayoutBaseFile(string $folder): bool {
|
||||
$content = [
|
||||
"<!DOCTYPE html>",
|
||||
"<html lang=\"es\">",
|
||||
"@include('layout.head')",
|
||||
"@include('layout.body')",
|
||||
"</html>",
|
||||
""
|
||||
];
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [
|
||||
$folder,
|
||||
'resources',
|
||||
'views',
|
||||
'layout'
|
||||
]);
|
||||
return $this->createFile($folder, 'base.blade.php', $content);
|
||||
}
|
||||
protected function addLayoutBodyFile(string $folder): bool {
|
||||
$content = [
|
||||
"<body>",
|
||||
" @include('layout.header')",
|
||||
" <div class=\"ui container\">",
|
||||
" <div class=\"ui basic segment\">",
|
||||
" @yield('page_content')",
|
||||
" </div>",
|
||||
" </div>",
|
||||
" @include('layout.footer')",
|
||||
"</body>",
|
||||
""
|
||||
];
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [
|
||||
$folder,
|
||||
'resources',
|
||||
'views',
|
||||
'layout'
|
||||
]);
|
||||
return $this->createFile($folder, 'body.blade.php', $content);
|
||||
}
|
||||
protected function addLayoutFooterFile(string $folder): bool {
|
||||
$content = ["@include('layout.scripts')"];
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [
|
||||
$folder,
|
||||
'resources',
|
||||
'views',
|
||||
'layout'
|
||||
]);
|
||||
return $this->createFile($folder, 'footer.blade.php', $content);
|
||||
}
|
||||
protected function addLayoutHeadFile(string $folder): bool {
|
||||
$content = [
|
||||
"<head>",
|
||||
" <meta charset=\"utf8\" />",
|
||||
" <title>@yield('page_title')</title>",
|
||||
" @include('layout.styles')",
|
||||
"</head>",
|
||||
""
|
||||
];
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [
|
||||
$folder,
|
||||
'resources',
|
||||
'views',
|
||||
'layout'
|
||||
]);
|
||||
return $this->createFile($folder, 'head.blade.php', $content);
|
||||
}
|
||||
protected function addLayoutHeaderFile(string $folder): bool {
|
||||
$content = [
|
||||
"<header class=\"ui container\">",
|
||||
" @include('layout.menu')",
|
||||
"</header>",
|
||||
""
|
||||
];
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [
|
||||
$folder,
|
||||
'resources',
|
||||
'views',
|
||||
'layout'
|
||||
]);
|
||||
return $this->createFile($folder, 'header.blade.php', $content);
|
||||
}
|
||||
protected function addLayoutMenuFile(string $folder): bool {
|
||||
$content = [
|
||||
"<nav class=\"ui menu\">",
|
||||
" <a class=\"item\" href=\"{{$urls->base}}\">Inicio</a>",
|
||||
" <a class=\"item\" href=\"{{$urls->base}}/create\">Crear</a>",
|
||||
"</nav>",
|
||||
""
|
||||
];
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [
|
||||
$folder,
|
||||
'resources',
|
||||
'views',
|
||||
'layout'
|
||||
]);
|
||||
return $this->createFile($folder, 'menu.blade.php', $content);
|
||||
}
|
||||
protected function addLayoutScriptsFile(string $folder): bool {
|
||||
$content = [
|
||||
"@if (isset(\$assets->scripts))",
|
||||
" @foreach (\$assets->scripts as \$script)",
|
||||
" <script type=\"text/javascript\" src=\"{{\$script}}\"></script>",
|
||||
" @endforeach",
|
||||
"@endif",
|
||||
"",
|
||||
"<script type=\"text/javascript\">",
|
||||
" \$(document).ready(() => {",
|
||||
" @stack('global_script')",
|
||||
" })",
|
||||
"</script>",
|
||||
"",
|
||||
"@stack('scripts')",
|
||||
""
|
||||
];
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [
|
||||
$folder,
|
||||
'resources',
|
||||
'views',
|
||||
'layout'
|
||||
]);
|
||||
return $this->createFile($folder, 'scripts.blade.php', $content);
|
||||
}
|
||||
protected function addLayoutStylesFile(string $folder): bool {
|
||||
$content = [
|
||||
"@if (isset(\$assets->styles))",
|
||||
" @foreach (\$assets->styles as \$style)",
|
||||
" <link rel=\"stylesheet\" type=\"text/css\" href=\"{{\$style}}\" />",
|
||||
" @endforeach",
|
||||
"@endif",
|
||||
"@if (isset(\$assets->fonts))",
|
||||
" @foreach (\$assets->fonts as \$font)",
|
||||
" <link href=\"{{\$font}}\" />",
|
||||
" @endforeach",
|
||||
"@endif",
|
||||
"",
|
||||
"@stack('styles')",
|
||||
"",
|
||||
"<style type=\"text/css\">",
|
||||
" @stack('global_style')",
|
||||
"</style>",
|
||||
""
|
||||
];
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [
|
||||
$folder,
|
||||
'resources',
|
||||
'views',
|
||||
'layout'
|
||||
]);
|
||||
return $this->createFile($folder, 'styles.blade.php', $content);
|
||||
}
|
||||
public function gitPush(string $project): bool {
|
||||
if (!$this->exists($project)) {
|
||||
return false;
|
||||
}
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [
|
||||
$this->folder,
|
||||
$project
|
||||
]);
|
||||
$repo = new GitRepository($folder);
|
||||
$repo->execute([
|
||||
'config',
|
||||
'--global',
|
||||
'user.name',
|
||||
'Aldarien'
|
||||
]);
|
||||
$repo->execute([
|
||||
'config',
|
||||
'--global',
|
||||
'user.email',
|
||||
'aldarien85@gmail.com'
|
||||
]);
|
||||
$repo->addAllChanges();
|
||||
$repo->commit('Seteo inicial');
|
||||
|
||||
$repo->addRemote('provm', 'http://git.provm.cl/ProVM/' . $project . '.git');
|
||||
$repo->push('provm', ['develop', '-u']);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function addView(string $project, string $name, string $location = '', array $options = []): bool {
|
||||
$content = [];
|
||||
if (isset($options['extends'])) {
|
||||
$content []= '@extends("' . $options['extends'] . '")';
|
||||
}
|
||||
if (isset($options['section'])) {
|
||||
$content []= '@section("' . $options['section'] . '")';
|
||||
$content []= '@endsection';
|
||||
}
|
||||
$folder = [
|
||||
$this->folder,
|
||||
$project,
|
||||
'resources',
|
||||
'views'
|
||||
];
|
||||
if (trim($location) != '') {
|
||||
$folder []= trim($location);
|
||||
}
|
||||
$folder = implode(DIRECTORY_SEPARATOR, $folder);
|
||||
if (!file_exists($folder)) {
|
||||
mkdir($folder);
|
||||
}
|
||||
$filename = $name . '.blade.php';
|
||||
return $this->createFile($folder, $filename, $content);
|
||||
}
|
||||
public function addRoute(string $project, string $space, string $file_name, string $route, $callback, string $method = 'get'): bool {
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [
|
||||
$this->folder,
|
||||
$project,
|
||||
'resources',
|
||||
'routes',
|
||||
$space
|
||||
]);
|
||||
$content = [
|
||||
'<?php'
|
||||
];
|
||||
$filename = implode(DIRECTORY_SEPARATOR, [$folder, $file_name . '.php']);
|
||||
if (file_exists($filename)) {
|
||||
$content = trim(file_get_contents($filename));
|
||||
if (strpos($content, $route) !== false) {
|
||||
return false;
|
||||
}
|
||||
$content = explode(PHP_EOL, $content);
|
||||
}
|
||||
$content []= "\$app->{$method}('{$route}', {$callback});";
|
||||
return $this->createFile($folder, $file_name . '.php', $content);
|
||||
}
|
||||
public function addController(string $project, string $space, string $name, string $template): bool {
|
||||
$name = str_replace(' ', '', ucwords($name));
|
||||
$content = [
|
||||
'<?php',
|
||||
'namespace ' . implode("\\", [
|
||||
'ProVM',
|
||||
ucwords($project),
|
||||
'Common',
|
||||
'Controller',
|
||||
ucwords($space)
|
||||
]) . ';',
|
||||
'',
|
||||
'use ' . implode("\\", [
|
||||
'Psr',
|
||||
'Http',
|
||||
'Message',
|
||||
'RequestInterface'
|
||||
]) . ' as Request;',
|
||||
'use ' . implode("\\", [
|
||||
'Psr',
|
||||
'Http',
|
||||
'Message',
|
||||
'ResponseInterface'
|
||||
]) . ' as Response;',
|
||||
'use ' . implode("\\", [
|
||||
'ProVM',
|
||||
'Common',
|
||||
'Define',
|
||||
'View'
|
||||
]) . ';',
|
||||
'',
|
||||
"class {$name} {",
|
||||
" public function __invoke(Request \$request, Response \$response, View \$view): Response {",
|
||||
" return \$view->render(\$response, '{$template}');",
|
||||
' }',
|
||||
'}',
|
||||
''
|
||||
];
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [
|
||||
$this->folder,
|
||||
$project,
|
||||
'common',
|
||||
'Controller',
|
||||
ucwords($space)
|
||||
]);
|
||||
return $this->createFile($folder, $name . '.php', $content);
|
||||
}
|
||||
}
|
31
composer.json
Normal file
31
composer.json
Normal file
@ -0,0 +1,31 @@
|
||||
{
|
||||
"name": "provm/projects",
|
||||
"description": "Project bootstrapper",
|
||||
"type": "project",
|
||||
"require": {
|
||||
"slim/slim": "^4.5",
|
||||
"php-di/slim-bridge": "^3.0",
|
||||
"nyholm/psr7": "^1.3",
|
||||
"nyholm/psr7-server": "^1.0",
|
||||
"nesbot/carbon": "^2.35",
|
||||
"rubellum/slim-blade-view": "^0.1.1",
|
||||
"composer/composer": "^1.10",
|
||||
"czproject/git-php": "^3.18"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^8.5",
|
||||
"kint-php/kint": "^3.3"
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Aldarien",
|
||||
"email": "aldarien85@gmail.com"
|
||||
}
|
||||
],
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"ProVM\\Common\\": "provm/common",
|
||||
"ProVM\\Projects\\Common\\": "common"
|
||||
}
|
||||
}
|
||||
}
|
8
provm/common/Alias/View.php
Normal file
8
provm/common/Alias/View.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace ProVM\Common\Alias;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
|
||||
interface View {
|
||||
public function render(Response $response, $template, array $data = []);
|
||||
}
|
43
provm/common/Define/ArrayOutput.php
Normal file
43
provm/common/Define/ArrayOutput.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace ProVM\Common\Define;
|
||||
|
||||
use Symfony\Component\Console\Output\Output;
|
||||
|
||||
class ArrayOutput extends Output {
|
||||
private $lines;
|
||||
private $delta;
|
||||
|
||||
public function clear() {
|
||||
$this->lines = [];
|
||||
$this->delta = 0;
|
||||
}
|
||||
|
||||
public function fetch() {
|
||||
return $this->lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = false, $formatter = null) {
|
||||
parent::__construct($verbosity, $decorated, $formatter);
|
||||
$this->lines = [];
|
||||
$this->delta = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doWrite($message, $newline) {
|
||||
if (empty($this->lines[$this->delta])) {
|
||||
$this->lines[$this->delta] = [];
|
||||
}
|
||||
if ($message) {
|
||||
$this->lines[$this->delta][] = trim($message);
|
||||
}
|
||||
if ($newline) {
|
||||
$this->delta++;
|
||||
}
|
||||
}
|
||||
}
|
25
provm/common/Define/Controller.php
Normal file
25
provm/common/Define/Controller.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace ProVM\Common\Define;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
|
||||
abstract class Controller {
|
||||
public function withJSON(Response $request, $data, bool $format = true): Response {
|
||||
if (!is_string($data)) {
|
||||
$enc = 0;
|
||||
if ($format) {
|
||||
$enc = \JSON_PRETTY_PRINT | \JSON_UNESCAPED_UNICODE | \JSON_UNESCAPED_SLASHES;
|
||||
}
|
||||
$data = json_encode($data, $enc);
|
||||
}
|
||||
$request->getBody()->write($data);
|
||||
return $request
|
||||
->withHeader('Content-Type', 'application/json')
|
||||
->withStatus(201);
|
||||
}
|
||||
public function withRedirect(Response $request, string $uri, int $status = 301): Response {
|
||||
return $response
|
||||
->withHeader('Location', $uri)
|
||||
->withStatus($status);
|
||||
}
|
||||
}
|
20
provm/common/Define/Controller/Json.php
Normal file
20
provm/common/Define/Controller/Json.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace ProVM\Common\Define\Controller;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
|
||||
trait Json {
|
||||
public function withJSON(Response $request, $data, bool $format = true): Response {
|
||||
if (!is_string($data)) {
|
||||
$enc = 0;
|
||||
if ($format) {
|
||||
$enc = \JSON_PRETTY_PRINT | \JSON_UNESCAPED_UNICODE | \JSON_UNESCAPED_SLASHES;
|
||||
}
|
||||
$data = json_encode($data, $enc);
|
||||
}
|
||||
$request->getBody()->write($data);
|
||||
return $request
|
||||
->withHeader('Content-Type', 'application/json')
|
||||
->withStatus(201);
|
||||
}
|
||||
}
|
12
provm/common/Define/Controller/Redirect.php
Normal file
12
provm/common/Define/Controller/Redirect.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
namespace ProVM\Common\Define\Controller;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
|
||||
trait Redirect {
|
||||
public function withRedirect(Response $response, string $uri, int $status = 301): Response {
|
||||
return $response
|
||||
->withHeader('Location', $uri)
|
||||
->withStatus($status);
|
||||
}
|
||||
}
|
8
provm/common/Define/View.php
Normal file
8
provm/common/Define/View.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace ProVM\Common\Define;
|
||||
|
||||
use Slim\Views\Blade;
|
||||
use ProVM\Common\Alias\View as ViewInterface;
|
||||
|
||||
class View extends Blade implements ViewInterface {
|
||||
}
|
102
provm/common/Service/Composer.php
Normal file
102
provm/common/Service/Composer.php
Normal file
@ -0,0 +1,102 @@
|
||||
<?php
|
||||
namespace ProVM\Common\Service;
|
||||
|
||||
use Psr\Container\ContainerInterface as Container;
|
||||
use Composer\Console\Application;
|
||||
use Symfony\Component\Console\Input\ArrayInput as Input;
|
||||
use ProVM\Common\Define\ArrayOutput as Output;
|
||||
|
||||
class Composer {
|
||||
const MAYOR = 0;
|
||||
const MINOR = 1;
|
||||
const PATCH = 2;
|
||||
const RELEASE = 3;
|
||||
|
||||
protected $composer_file;
|
||||
public function __construct(string $composer_file) {
|
||||
$this->composer_file = $composer_file;
|
||||
}
|
||||
|
||||
public function search($query): array {
|
||||
putenv('COMPOSER=' . $this->composer_file);
|
||||
$input = new Input([
|
||||
'command' => 'search',
|
||||
'tokens' => [$query]
|
||||
]);
|
||||
$output = new Output();
|
||||
$app = new Application();
|
||||
$app->setAutoExit(false);
|
||||
$app->run($input, $output);
|
||||
return $this->parseOutput($output->fetch());
|
||||
}
|
||||
protected function parseOutput(array $input): array {
|
||||
$output = [];
|
||||
foreach ($input as $line) {
|
||||
if (strpos($line[0], '<') !== false) {
|
||||
continue;
|
||||
}
|
||||
$pos = strpos($line[0], ' ');
|
||||
$name = substr($line[0], 0, $pos);
|
||||
$desc = substr($line[0], $pos + 1);
|
||||
$output []= (object) compact('name', 'desc');
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
public function latest(string $package): string {
|
||||
putenv('COMPOSER=' . $this->composer_file);
|
||||
$input = new Input([
|
||||
'command' => 'show',
|
||||
'--all' => true,
|
||||
'--latest' => true,
|
||||
'package' => $package
|
||||
]);
|
||||
$output = new Output();
|
||||
$app = new Application();
|
||||
$app->setAutoExit(false);
|
||||
$app->run($input, $output);
|
||||
$arr = $output->fetch();
|
||||
$latest = '*';
|
||||
foreach ($arr as $line) {
|
||||
if (strpos($line[0], 'latest') === false) {
|
||||
continue;
|
||||
}
|
||||
list($option, $value) = explode(':', $line[0]);
|
||||
if (trim($option) == 'latest') {
|
||||
$latest = trim($value);
|
||||
}
|
||||
}
|
||||
return $latest;
|
||||
}
|
||||
public function getLatest(array $packages, int $semver = Composer::MINOR): array {
|
||||
$output = [];
|
||||
foreach ($packages as $package) {
|
||||
$latest = $this->semver($this->latest($package), $semver);
|
||||
$output[$package] = $latest;
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
protected function semver(string $version, int $semver) {
|
||||
switch ($semver) {
|
||||
case Composer::PATCH:
|
||||
case Composer::RELEASE:
|
||||
return $version;
|
||||
case Composer::MINOR:
|
||||
if (strpos($version, '.') === false) {
|
||||
return $version;
|
||||
}
|
||||
$v = explode('.', $version);
|
||||
if (count($v) < 3) {
|
||||
return '^' . $version;
|
||||
}
|
||||
array_pop($v);
|
||||
$version = '^' . implode('.', $v);
|
||||
return $version;
|
||||
case Composer::MAYOR:
|
||||
if (strpos($version, '.') === false) {
|
||||
return $version;
|
||||
}
|
||||
$v = explode('.', $version);
|
||||
return '^' . $v[0];
|
||||
}
|
||||
}
|
||||
}
|
4
public/.htaccess
Normal file
4
public/.htaccess
Normal file
@ -0,0 +1,4 @@
|
||||
RewriteEngine On
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteRule ^ index.php [QSA,L]
|
4
public/api/.htaccess
Normal file
4
public/api/.htaccess
Normal file
@ -0,0 +1,4 @@
|
||||
RewriteEngine On
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteRule ^ index.php [QSA,L]
|
8
public/api/index.php
Normal file
8
public/api/index.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
$__environment = 'api';
|
||||
include_once implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__DIR__, 2),
|
||||
'setup',
|
||||
'app.php'
|
||||
]);
|
||||
$app->run();
|
8
public/index.php
Normal file
8
public/index.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
$__environment = 'web';
|
||||
include_once implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__DIR__),
|
||||
'setup',
|
||||
'app.php'
|
||||
]);
|
||||
$app->run();
|
14
resources/routes/api.php
Normal file
14
resources/routes/api.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [
|
||||
__DIR__,
|
||||
'api'
|
||||
]);
|
||||
if (file_exists($folder)) {
|
||||
$files = new DirectoryIterator($folder);
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir()) {
|
||||
continue;
|
||||
}
|
||||
include_once $file->getRealPath();
|
||||
}
|
||||
}
|
13
resources/routes/api/create.php
Normal file
13
resources/routes/api/create.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
use ProVM\Projects\Common\Controller\API\Create;
|
||||
|
||||
$app->group('/create/{project}', function($app) {
|
||||
$app->get('/folder', [Create::class, 'createFolder']);
|
||||
$app->get('/subfolders', [Create::class, 'createSubfolders']);
|
||||
$app->post('/composer', [Create::class, 'addComposer']);
|
||||
$app->get('/files', [Create::class, 'addFiles']);
|
||||
$app->group('/git', function($app) {
|
||||
$app->get('/init', [Create::class, 'gitInit']);
|
||||
$app->get('/push', [Create::class, 'gitPush']);
|
||||
});
|
||||
});
|
6
resources/routes/api/dependencies.php
Normal file
6
resources/routes/api/dependencies.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
use ProVM\Projects\Common\Controller\API\Dependencies;
|
||||
|
||||
$app->group('/dependencies', function($app) {
|
||||
$app->get('/search', [Dependencies::class, 'search']);
|
||||
});
|
2
resources/routes/router.php
Normal file
2
resources/routes/router.php
Normal file
@ -0,0 +1,2 @@
|
||||
<?php
|
||||
include_once $__environment . '.php';
|
18
resources/routes/web.php
Normal file
18
resources/routes/web.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
use ProVM\Projects\Common\Controller\Web\Home;
|
||||
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [
|
||||
__DIR__,
|
||||
'web'
|
||||
]);
|
||||
if (file_exists($folder)) {
|
||||
$files = new DirectoryIterator($folder);
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir()) {
|
||||
continue;
|
||||
}
|
||||
include_once $file->getRealPath();
|
||||
}
|
||||
}
|
||||
|
||||
$app->get('/', Home::class);
|
8
resources/routes/web/create.php
Normal file
8
resources/routes/web/create.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
use ProVM\Projects\Common\Controller\Web\Create;
|
||||
|
||||
$app->group('/create', function($app) {
|
||||
$app->post('/2', [Create::class, 'step2']);
|
||||
$app->post('/3', [Create::class, 'step3']);
|
||||
$app->get('[/]', Create::class);
|
||||
});
|
24
resources/routes/web/project.php
Normal file
24
resources/routes/web/project.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
use ProVM\Projects\Common\Controller\Web\Project;
|
||||
|
||||
$app->group('/project/{project}', function($app) {
|
||||
$app->group('/views', function($app) {
|
||||
$app->group('/add', function($app) {
|
||||
$app->get('[/]', [Project::class, 'addView']);
|
||||
$app->post('[/]', [Project::class, 'doAddView']);
|
||||
});
|
||||
});
|
||||
$app->group('/controllers', function($app) {
|
||||
$app->group('/add', function($app) {
|
||||
$app->get('[/]', [Project::class, 'addController']);
|
||||
$app->post('[/]', [Project::class, 'doAddController']);
|
||||
});
|
||||
});
|
||||
$app->group('/routes', function($app) {
|
||||
$app->group('/add', function($app) {
|
||||
$app->get('[/]', [Project::class, 'addRoute']);
|
||||
$app->post('[/]', [Project::class, 'doAddRoute']);
|
||||
});
|
||||
});
|
||||
$app->get('[/]', Project::class);
|
||||
});
|
6
resources/routes/web/steps.php
Normal file
6
resources/routes/web/steps.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
use ProVM\Projects\Common\Controller\Web\Home;
|
||||
|
||||
$app->group('/step', function($app) {
|
||||
$app->post('/2', [Home::class, 'step2']);
|
||||
});
|
26
resources/views/create/base.blade.php
Normal file
26
resources/views/create/base.blade.php
Normal file
@ -0,0 +1,26 @@
|
||||
@extends('layout.base')
|
||||
|
||||
@section('page_content')
|
||||
<h1 class="ui header">Crear Proyecto</h1>
|
||||
<div class="ui steps">
|
||||
<div class="@if (!isset($step) or $step == 1) active @elseif($step > 1) completed @endif step">
|
||||
<i class="clipboard icon"></i>
|
||||
<div class="content">
|
||||
Formulario
|
||||
</div>
|
||||
</div>
|
||||
<div class="@if (isset($step) and $step == 2) active @elseif(isset($step) and $step > 2) completed @endif step">
|
||||
<i class="tasks icon"></i>
|
||||
<div class="content">
|
||||
Confirmar
|
||||
</div>
|
||||
</div>
|
||||
<div class="@if (isset($step) and $step == 3) active @endif step">
|
||||
<i class="cogs icon"></i>
|
||||
<div class="content">
|
||||
Crear
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@yield('content')
|
||||
@endsection
|
68
resources/views/create/step1.blade.php
Normal file
68
resources/views/create/step1.blade.php
Normal file
@ -0,0 +1,68 @@
|
||||
@extends('create.base')
|
||||
|
||||
@section('content')
|
||||
<form class="ui form" method="post" action="{{$urls->base}}/create/2">
|
||||
<div class="field">
|
||||
<label>Nombre</label>
|
||||
<input type="text" name="nombre" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Descripción</label>
|
||||
<input type="text" name="descripcion" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Dependencias</label>
|
||||
<div class="ui multiple search selection dropdown" id="dependencias">
|
||||
<i class="dropdown icon"></i>
|
||||
<input type="hidden" name="dependencias[]" multiple="multiple" value="{{implode(',', $defaults->require)}}" />
|
||||
<div class="default text">Dependencias</div>
|
||||
<div class="menu">
|
||||
@foreach ($defaults->require as $dep)
|
||||
<div class="item" data-value="{{$dep}}">{{$dep}}</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Dependencias Dev</label>
|
||||
<div class="ui multiple search selection dropdown" id="dependencias-dev">
|
||||
<input type="hidden" name="dependencias-dev[]" multiple="multiple" value="{{implode(',', $defaults->{'require-dev'})}}"/>
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="default text">Dependencias</div>
|
||||
<div class="menu">
|
||||
@foreach ($defaults->{'require-dev'} as $dep)
|
||||
<div class="item" data-value="{{$dep}}">{{$dep}}</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<button class="ui button">
|
||||
Siguiente
|
||||
<i class="right chevron icon"></i>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
@endsection
|
||||
|
||||
@push('global_script')
|
||||
let step1 = {
|
||||
id: '#dependencias',
|
||||
id2: '#dependencias-dev',
|
||||
setup: function() {
|
||||
$(this.id).dropdown({
|
||||
apiSettings: {
|
||||
preserveHTML: false,
|
||||
url: '{{$urls->api}}/dependencies/search?query={query}'
|
||||
}
|
||||
})
|
||||
$(this.id2).dropdown({
|
||||
apiSettings: {
|
||||
preserveHTML: false,
|
||||
url: '{{$urls->api}}/dependencies/search?query={query}'
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
step1.setup()
|
||||
@endpush
|
30
resources/views/create/step2.blade.php
Normal file
30
resources/views/create/step2.blade.php
Normal file
@ -0,0 +1,30 @@
|
||||
@extends('create.base')
|
||||
|
||||
@section('content')
|
||||
@if (!$exists)
|
||||
<div class="ui success icon message">
|
||||
<i class="check icon"></i>
|
||||
No existe
|
||||
</div>
|
||||
@else
|
||||
<div class="ui error icon message">
|
||||
<i class="times icon"></i>
|
||||
Proyecto ya existe
|
||||
</div>
|
||||
@endif
|
||||
<div class="ui segment">
|
||||
<div class="header">
|
||||
composer.json
|
||||
</div>
|
||||
<pre class="content">{{$composer}}</pre>
|
||||
</div>
|
||||
@if (!$exists)
|
||||
<form class="ui form" method="post" action="{{$urls->base}}/create/3">
|
||||
<input type="hidden" name="composer" value="{{$composer}}" />
|
||||
<button class="ui button">
|
||||
Siguiente
|
||||
<i class="right chevron icon"></i>
|
||||
</button>
|
||||
</form>
|
||||
@endif
|
||||
@endsection
|
140
resources/views/create/step3.blade.php
Normal file
140
resources/views/create/step3.blade.php
Normal file
@ -0,0 +1,140 @@
|
||||
@extends('create.base')
|
||||
|
||||
@section('content')
|
||||
<div class="ui indicating progress" id="progress">
|
||||
<div class="bar">
|
||||
<div class="progress"></div>
|
||||
</div>
|
||||
<div class="label">
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('scripts')
|
||||
<script type="text/javascript">
|
||||
let project = {
|
||||
progress: '#progress',
|
||||
bar: null,
|
||||
setup: function() {
|
||||
this.bar = $(this.progress)
|
||||
this.bar.progress()
|
||||
this.start()
|
||||
},
|
||||
advanceProgress: function(percent, Total, length, start) {
|
||||
start = (typeof start === 'undefined') ? 0 : start
|
||||
let p = (percent / Total) * 100 * length / 100 + start
|
||||
this.bar.progress('set percent', p)
|
||||
},
|
||||
buildXHR: function(length, start) {
|
||||
start = (typeof start === 'undefined') ? 0 : start
|
||||
let xhr = new window.XMLHttpRequest()
|
||||
xhr.upload.addEventListener('progress', (e) => {
|
||||
if (e.lengthComputable) {
|
||||
this.advanceProgress(e.loaded, e.total, 2, start)
|
||||
}
|
||||
}, false)
|
||||
xhr.addEventListener('progress', (e) => {
|
||||
if (e.lengthComputable) {
|
||||
this.advanceProgress(e.loaded, e.total, length - 2, start + 2)
|
||||
}
|
||||
}, false)
|
||||
return xhr
|
||||
},
|
||||
send: function(messages, url, next, length, start, method, data) {
|
||||
this.bar.progress('set label', messages.init)
|
||||
method = (typeof method === 'undefined') ? 'GET' : method
|
||||
start = (typeof start === 'undefined') ? 0 : start
|
||||
let settings = {
|
||||
type: method,
|
||||
url: url,
|
||||
xhr: () => {
|
||||
return this.buildXHR(length, start)
|
||||
},
|
||||
success: (data) => {
|
||||
if (data.estado) {
|
||||
this.bar.progress('set label', messages.success)
|
||||
if (typeof next !== 'undefined' || next !== null) {
|
||||
next(start + length)
|
||||
}
|
||||
return
|
||||
}
|
||||
this.error(messages.error)
|
||||
console.debug(data)
|
||||
},
|
||||
error: (xhr) => {
|
||||
this.error('No se pudo conectar a ' + url + '. ' + xhr.statusText)
|
||||
}
|
||||
}
|
||||
if (method.toLowerCase() == 'post') {
|
||||
settings['data'] = data
|
||||
}
|
||||
return $.ajax(settings)
|
||||
},
|
||||
start: function() {
|
||||
project.send({
|
||||
init: 'Creando repo',
|
||||
success: 'Repo creado',
|
||||
error: 'No se pudo crear repo'
|
||||
}, '{{$urls->gitea->url}}/user/repos?token={{$urls->gitea->api_key}}', project.createFolder, 5, 0, 'POST', {
|
||||
auto_init: true,
|
||||
default_branch: 'master',
|
||||
name: '{{$name}}'
|
||||
})
|
||||
}, // 5
|
||||
createFolder: function(start) {
|
||||
project.send({
|
||||
init: 'Creando carpeta principal',
|
||||
success: 'Carpeta principal creada',
|
||||
error: 'No se pudo crear la carpeta principal.'
|
||||
}, '{{$urls->api}}/create/{{$name}}/folder', project.createSubfolders, 5, start)
|
||||
}
|
||||
createSubfolders: function(start) {
|
||||
project.send({
|
||||
init: 'Creando subcarpetas',
|
||||
success: 'Subcarpetas creadas',
|
||||
error: 'No se pudo crear las subcarpetas'
|
||||
}, '{{$urls->api}}/create/{{$name}}/subfolders', project.gitInit, 5, start)
|
||||
}, // 5 + 5: 10
|
||||
gitInit: function(start) {
|
||||
project.send({
|
||||
init: 'Iniciando Git',
|
||||
success: 'Git iniciado',
|
||||
error: 'No se pudo iniciar Git'
|
||||
}, '{{$urls->api}}/create/{{$name}}/git/init', project.addComposer, 5, start)
|
||||
}, // 10 + 5: 15
|
||||
addComposer: function(start) {
|
||||
project.send({
|
||||
init: 'Agregando e instalando Composer',
|
||||
success: 'Composer instalado',
|
||||
error: 'No se pudo instalar composer'
|
||||
}, '{{$urls->api}}/create/{{$name}}/composer', project.addFiles, 10, start, 'POST', {composer: {!!json_encode($composer)!!}})
|
||||
}, // 15 + 10: 25
|
||||
addFiles: function(start) {
|
||||
project.send({
|
||||
init: 'Creando archivos',
|
||||
success: 'Archivos creados',
|
||||
error: 'No se pudo crear los archivos'
|
||||
}, '{{$urls->api}}/create/{{$name}}/files', project.gitPush, 65, start)
|
||||
}, // 25 + 65: 90
|
||||
gitPush: function(start) {
|
||||
project.send({
|
||||
init: 'Git Push',
|
||||
success: 'Proyecto listo y en repo',
|
||||
error: 'No se pudo subir el proyecto al repo'
|
||||
}, '{{$urls->api}}/create/{{$name}}/git/push', null, 10, start).then(() => {
|
||||
project.end()
|
||||
})
|
||||
}, // 90 + 10: 100
|
||||
end: function() {
|
||||
window.location = '{{$urls->base}}'
|
||||
return
|
||||
},
|
||||
error: function(msg) {
|
||||
this.bar.progress('set error', 'Se ha producido un error. ' + msg)
|
||||
}
|
||||
}
|
||||
$(document).ready(() => {
|
||||
project.setup()
|
||||
})
|
||||
</script>
|
||||
@endpush
|
10
resources/views/home.blade.php
Normal file
10
resources/views/home.blade.php
Normal file
@ -0,0 +1,10 @@
|
||||
@extends('layout.base')
|
||||
|
||||
@section('page_content')
|
||||
<h1 class="ui header">Proyectos</h1>
|
||||
<div class="ui celled list">
|
||||
@foreach ($projects as $project)
|
||||
<a class="item" href="{{$urls->base}}/project/{{$project->name}}">{{$project->name}}</a>
|
||||
@endforeach
|
||||
</div>
|
||||
@endsection
|
5
resources/views/layout/base.blade.php
Normal file
5
resources/views/layout/base.blade.php
Normal file
@ -0,0 +1,5 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="es">
|
||||
@include('layout.head')
|
||||
@include('layout.body')
|
||||
</html>
|
9
resources/views/layout/body.blade.php
Normal file
9
resources/views/layout/body.blade.php
Normal file
@ -0,0 +1,9 @@
|
||||
<body>
|
||||
@include('layout.header')
|
||||
<div class="ui container">
|
||||
<div class="ui basic segment">
|
||||
@yield('page_content')
|
||||
</div>
|
||||
</div>
|
||||
@include('layout.footer')
|
||||
</body>
|
1
resources/views/layout/footer.blade.php
Normal file
1
resources/views/layout/footer.blade.php
Normal file
@ -0,0 +1 @@
|
||||
@include('layout.scripts')
|
5
resources/views/layout/head.blade.php
Normal file
5
resources/views/layout/head.blade.php
Normal file
@ -0,0 +1,5 @@
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>@yield('page_title')</title>
|
||||
@include('layout.styles')
|
||||
</head>
|
3
resources/views/layout/header.blade.php
Normal file
3
resources/views/layout/header.blade.php
Normal file
@ -0,0 +1,3 @@
|
||||
<header class="ui container">
|
||||
@include('layout.menu')
|
||||
</header>
|
4
resources/views/layout/menu.blade.php
Normal file
4
resources/views/layout/menu.blade.php
Normal file
@ -0,0 +1,4 @@
|
||||
<nav class="ui menu">
|
||||
<a class="item" href="{{$urls->base}}">Inicio</a>
|
||||
<a class="item" href="{{$urls->base}}/create">Crear</a>
|
||||
</nav>
|
13
resources/views/layout/scripts.blade.php
Normal file
13
resources/views/layout/scripts.blade.php
Normal file
@ -0,0 +1,13 @@
|
||||
@if (isset($assets->scripts))
|
||||
@foreach ($assets->scripts as $script)
|
||||
<script type="text/javascript" src="{{$script}}"></script>
|
||||
@endforeach
|
||||
@endif
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(() => {
|
||||
@stack('global_script')
|
||||
})
|
||||
</script>
|
||||
|
||||
@stack('scripts')
|
16
resources/views/layout/styles.blade.php
Normal file
16
resources/views/layout/styles.blade.php
Normal file
@ -0,0 +1,16 @@
|
||||
@if (isset($assets->styles))
|
||||
@foreach ($assets->styles as $style)
|
||||
<link rel="stylesheet" type="text/css" href="{{$style}}" />
|
||||
@endforeach
|
||||
@endif
|
||||
@if (isset($assets->fonts))
|
||||
@foreach ($assets->fonts as $font)
|
||||
<link href="{{$font}}" />
|
||||
@endforeach
|
||||
@endif
|
||||
|
||||
@stack('styles')
|
||||
|
||||
<style type="text/css">
|
||||
@stack('global_style')
|
||||
</style>
|
9
resources/views/projects/base.blade.php
Normal file
9
resources/views/projects/base.blade.php
Normal file
@ -0,0 +1,9 @@
|
||||
@extends('layout.base')
|
||||
|
||||
@section('page_content')
|
||||
<h1 class="ui header">
|
||||
Proyecto - {{$project->name ?? $project}}
|
||||
@yield('title')
|
||||
</h1>
|
||||
@yield('content')
|
||||
@endsection
|
50
resources/views/projects/controllers/add.blade.php
Normal file
50
resources/views/projects/controllers/add.blade.php
Normal file
@ -0,0 +1,50 @@
|
||||
@extends('projects.base')
|
||||
|
||||
@section('title')
|
||||
- Agregar Controlador
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<form class="ui form" method="post" action="{{$urls->base}}/project/{{$project->base_name}}/controllers/add">
|
||||
<div class="field">
|
||||
<label>Nombre</label>
|
||||
<input type="text" name="name" />
|
||||
</div>
|
||||
<div class="two fields">
|
||||
<div class="field">
|
||||
<label>Espacio</label>
|
||||
<div class="ui selection dropdown" id="space">
|
||||
<input type="hidden" name="space" />
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="default text">Espacio</div>
|
||||
<div class="menu">
|
||||
@foreach ($subfolders as $folder)
|
||||
<div class="item" data-value="{{$folder}}">{{$folder}}</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Vista</label>
|
||||
<div class="ui selection dropdown" id="views">
|
||||
<input type="hidden" name="template" />
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="default text">Vista</div>
|
||||
<div class="menu">
|
||||
@foreach ($views as $view)
|
||||
<div class="item" data-value="{{$view}}">{{$view}}</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<button class="ui button">Agregar</button>
|
||||
</div>
|
||||
</form>
|
||||
@endsection
|
||||
|
||||
@push('global_script')
|
||||
$('#space').dropdown()
|
||||
$('#views').dropdown()
|
||||
@endpush
|
63
resources/views/projects/routes/add.blade.php
Normal file
63
resources/views/projects/routes/add.blade.php
Normal file
@ -0,0 +1,63 @@
|
||||
@extends('projects.base')
|
||||
|
||||
@section('title')
|
||||
- Agregar Ruta
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<form class="ui form" method="post" action="{{$urls->base}}/project/{{$project->base_name}}/routes/add">
|
||||
<div class="field">
|
||||
<label>Ruta</label>
|
||||
<input type="text" name="name" />
|
||||
</div>
|
||||
<div class="three fields">
|
||||
<div class="field">
|
||||
<label>Espacio</label>
|
||||
<div class="ui selection dropdown" id="space">
|
||||
<input type="hidden" name="space" />
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="default text">Espacio</div>
|
||||
<div class="menu">
|
||||
@foreach ($subfolders as $subfolder)
|
||||
<div class="item" data-value="{{$subfolder}}">{{$subfolder}}</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Grupo</label>
|
||||
<div class="ui search selection dropdown" id="group">
|
||||
<input type="hidden" name="group" />
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="default text">Grupo</div>
|
||||
<div class="menu">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Controlador</label>
|
||||
<div class="ui selection dropdown" id="controller">
|
||||
<input type="hidden" name="controller" />
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="default text">Controlador</div>
|
||||
<div class="menu">
|
||||
@foreach ($controllers as $controller)
|
||||
<div class="item" data-value="{{$controller}}">{{$controller}}</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<button class="ui button">Agregar</button>
|
||||
</div>
|
||||
</form>
|
||||
@endsection
|
||||
|
||||
@push('global_script')
|
||||
$('#space').dropdown()
|
||||
$('#group').dropdown({
|
||||
allowAdditions: true
|
||||
})
|
||||
$('#controller').dropdown()
|
||||
@endpush
|
123
resources/views/projects/show.blade.php
Normal file
123
resources/views/projects/show.blade.php
Normal file
@ -0,0 +1,123 @@
|
||||
@extends('projects.base')
|
||||
|
||||
@section('content')
|
||||
<div class="ui segment">
|
||||
<h3 class="header">
|
||||
GIT
|
||||
</h3>
|
||||
<pre>{{implode(PHP_EOL, $project->git)}}</pre>
|
||||
</div>
|
||||
<div class="ui segment">
|
||||
<h3 class="header">
|
||||
Composer
|
||||
</h3>
|
||||
<pre>{{json_encode($project->composer, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)}}</pre>
|
||||
</div>
|
||||
<div class="ui segment">
|
||||
<h3 class="header">
|
||||
Config
|
||||
</h3>
|
||||
<div class="ui celled list">
|
||||
@foreach ($project->config as $config)
|
||||
<div class="item">
|
||||
{{$config}}
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
<div class="ui segment">
|
||||
<h3 class="header">
|
||||
<div class="ui grid">
|
||||
<div class="ten wide column">
|
||||
Controllers
|
||||
</div>
|
||||
<div class="six wide right aligned column">
|
||||
<a href="{{$urls->base}}/project/{{$project->base_name}}/controllers/add">
|
||||
<i class="plus icon"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</h3>
|
||||
@if ($project->controllers !== null and count((array) $project->controllers) > 0)
|
||||
<div class="ui celled list">
|
||||
@foreach ($project->controllers as $path => $controller)
|
||||
<div class="item">
|
||||
{{$controller}}
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
<div class="ui segment">
|
||||
<h3 class="header">
|
||||
<div class="ui grid">
|
||||
<div class="ten wide column">
|
||||
Services
|
||||
</div>
|
||||
<div class="six wide right aligned column">
|
||||
<a href="{{$urls->base}}/project/{{$project->base_name}}/service/add">
|
||||
<i class="plus icon"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</h3>
|
||||
@if ($project->services !== null and count((array) $project->services) > 0)
|
||||
<div class="ui list">
|
||||
@foreach ($project->services as $path => $service)
|
||||
<div class="item">
|
||||
{{$path}}
|
||||
<pre>{{json_encode($service, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)}}</pre>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
<div class="ui segment">
|
||||
<h3 class="header">
|
||||
<div class="ui grid">
|
||||
<div class="ten wide column">
|
||||
Routes
|
||||
</div>
|
||||
<div class="six wide right aligned column">
|
||||
<a href="{{$urls->base}}/project/{{$project->base_name}}/routes/add">
|
||||
<i class="plus icon"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</h3>
|
||||
@if ($project->routes !== null and count((array) $project->routes) > 0)
|
||||
<div class="ui list">
|
||||
@foreach ($project->routes as $path => $routes)
|
||||
@foreach ($routes as $route)
|
||||
<div class="item">
|
||||
{{$route}}
|
||||
</div>
|
||||
@endforeach
|
||||
@endforeach
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
<div class="ui segment">
|
||||
<h3 class="header">
|
||||
<div class="ui grid">
|
||||
<div class="ten wide column">
|
||||
Views
|
||||
</div>
|
||||
<div class="six wide right aligned column">
|
||||
<a href="{{$urls->base}}/project/{{$project->base_name}}/views/add">
|
||||
<i class="plus icon"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</h3>
|
||||
@if ($project->views !== null and count((array) $project->views) > 0)
|
||||
<div class="ui list">
|
||||
@foreach ($project->views as $path => $view)
|
||||
<div class="item">
|
||||
{{$view}}
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
@endsection
|
58
resources/views/projects/views/add.blade.php
Normal file
58
resources/views/projects/views/add.blade.php
Normal file
@ -0,0 +1,58 @@
|
||||
@extends('projects.base')
|
||||
|
||||
@section('title')
|
||||
- Agregar Vista
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<form class="ui form" method="post" action="{{$urls->base}}/project/{{$project->base_name}}/views/add">
|
||||
<div class="field">
|
||||
<label>Nombre</label>
|
||||
<input type="text" name="name" />
|
||||
</div>
|
||||
<div class="three fields">
|
||||
<div class="field">
|
||||
<label>Subcarpeta *</label>
|
||||
<div class="ui search selection dropdown" id="subcarpetas">
|
||||
<input type="hidden" name="location" />
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="default text">Subcarpeta</div>
|
||||
<div class="menu">
|
||||
@foreach ($subfolders as $subcarpeta)
|
||||
<div class="item" data-value="{{$subcarpeta}}">{{$subcarpeta}}</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Extiende *</label>
|
||||
<div class="ui selection dropdown" id="extends">
|
||||
<input type="hidden" name="extends" />
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="default text">Extiende</div>
|
||||
<div class="menu">
|
||||
@foreach ($views as $view)
|
||||
<div class="item" data-value="{{$view}}">{{$view}}</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>Sección *</label>
|
||||
<input type="text" name="seccion" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<button class="ui button">
|
||||
Agregar
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
@endsection
|
||||
|
||||
@push('global_script')
|
||||
$('#subcarpetas').dropdown({
|
||||
allowAdditions: true
|
||||
})
|
||||
$('#extends').dropdown()
|
||||
@endpush
|
16
setup/api/config.php
Normal file
16
setup/api/config.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface as Container;
|
||||
|
||||
return [
|
||||
'base_url' => DI\decorate(function($prev, Container $c) {
|
||||
return implode('/', [
|
||||
$prev,
|
||||
'api'
|
||||
]);
|
||||
}),
|
||||
'urls' => DI\decorate(function($prev, Container $c) {
|
||||
$arr = (array) $prev;
|
||||
$arr['gitea'] = $c->get('gitea');
|
||||
return (object) $arr;
|
||||
})
|
||||
];
|
60
setup/app.php
Normal file
60
setup/app.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
use DI\ContainerBuilder as Builder;
|
||||
use DI\Bridge\Slim\Bridge;
|
||||
|
||||
if (!isset($__environment)) {
|
||||
throw new Exception('Missing __environment variable');
|
||||
}
|
||||
|
||||
include_once 'composer.php';
|
||||
|
||||
$builder = new Builder();
|
||||
|
||||
$files = [
|
||||
'config',
|
||||
'setup'
|
||||
];
|
||||
$folders = [
|
||||
'common',
|
||||
$__environment
|
||||
];
|
||||
|
||||
foreach ($files as $file) {
|
||||
foreach ($folders as $folder) {
|
||||
$filename = implode(DIRECTORY_SEPARATOR, [
|
||||
__DIR__,
|
||||
$folder,
|
||||
$file . '.php'
|
||||
]);
|
||||
if (file_exists($filename)) {
|
||||
$builder->addDefinitions($filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$container = $builder->build();
|
||||
$app = Bridge::create($container);
|
||||
try {
|
||||
$app->setBasePath($container->get('base_url'));
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
|
||||
foreach ($folders as $folder) {
|
||||
$filename = implode(DIRECTORY_SEPARATOR, [
|
||||
__DIR__,
|
||||
$folder,
|
||||
'middleware.php'
|
||||
]);
|
||||
if (file_exists($filename)) {
|
||||
include_once $filename;
|
||||
}
|
||||
}
|
||||
|
||||
$filename = implode(DIRECTORY_SEPARATOR, [
|
||||
$container->get('folders')->routes,
|
||||
'router.php'
|
||||
]);
|
||||
if (!file_exists($filename)) {
|
||||
throw new Exception('Missing router file.');
|
||||
}
|
||||
include_once $filename;
|
33
setup/common/config.php
Normal file
33
setup/common/config.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
return [
|
||||
'base_url' => '/provm/projects',
|
||||
'gitea' => function() {
|
||||
$arr = [];
|
||||
$arr['url'] = 'https://git.provm.cl/api/swagger';
|
||||
$arr['api_key'] = 'd877e5ce64352c914657fa491fa7ae1722ad734f';
|
||||
return (object) $arr;
|
||||
},
|
||||
'urls' => function() {
|
||||
$arr = [
|
||||
'base' => '/provm/projects'
|
||||
];
|
||||
$arr['api'] = implode('/', [
|
||||
$arr['base'],
|
||||
'api'
|
||||
]);
|
||||
return (object) $arr;
|
||||
},
|
||||
'folders' => function() {
|
||||
$arr = [];
|
||||
$arr['base'] = dirname(__DIR__, 2);
|
||||
$arr['resources'] = implode(DIRECTORY_SEPARATOR, [
|
||||
$arr['base'],
|
||||
'resources'
|
||||
]);
|
||||
$arr['routes'] = implode(DIRECTORY_SEPARATOR, [
|
||||
$arr['resources'],
|
||||
'routes'
|
||||
]);
|
||||
return (object) $arr;
|
||||
}
|
||||
];
|
14
setup/common/setup.php
Normal file
14
setup/common/setup.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface as Container;
|
||||
|
||||
return [
|
||||
ProVM\Common\Service\Composer::class => function(Container $c) {
|
||||
return new ProVM\Common\Service\Composer(implode(DIRECTORY_SEPARATOR, [
|
||||
$c->get('folders')->base,
|
||||
'composer.json'
|
||||
]));
|
||||
},
|
||||
ProVM\Projects\Common\Service\Projects::class => function(Container $c) {
|
||||
return new ProVM\Projects\Common\Service\Projects(implode(DIRECTORY_SEPARATOR, [dirname($c->get('folders')->base), 'demos']));
|
||||
}
|
||||
];
|
10
setup/composer.php
Normal file
10
setup/composer.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
$filename = implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__DIR__),
|
||||
'vendor',
|
||||
'autoload.php'
|
||||
]);
|
||||
if (!file_exists($filename)) {
|
||||
throw new Exception('Missing composer install.');
|
||||
}
|
||||
include_once $filename;
|
34
setup/web/config.php
Normal file
34
setup/web/config.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface as Container;
|
||||
|
||||
return [
|
||||
'folders' => DI\decorate(function($prev, Container $c) {
|
||||
$arr = (array) $prev;
|
||||
$arr['templates'] = implode(DIRECTORY_SEPARATOR, [
|
||||
$prev->resources,
|
||||
'views'
|
||||
]);
|
||||
$arr['cache'] = implode(DIRECTORY_SEPARATOR, [
|
||||
$prev->base,
|
||||
'cache'
|
||||
]);
|
||||
return (object) $arr;
|
||||
}),
|
||||
'assets' => (object) [
|
||||
'styles' => [
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.6/semantic.min.css'
|
||||
],
|
||||
'scripts' => [
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js',
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.6/semantic.min.js'
|
||||
],
|
||||
'fonts' => [
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.6/themes/default/assets/fonts/brand-icons.woff',
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.6/themes/default/assets/fonts/brand-icons.woff2',
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.6/themes/default/assets/fonts/icons.woff',
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.6/themes/default/assets/fonts/icons.woff2',
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.6/themes/default/assets/fonts/outline-icons.woff',
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.6/themes/default/assets/fonts/outline-icons.woff2'
|
||||
]
|
||||
]
|
||||
];
|
16
setup/web/setup.php
Normal file
16
setup/web/setup.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface as Container;
|
||||
|
||||
return [
|
||||
ProVM\Common\Alias\View::class => function(Container $c) {
|
||||
return new ProVM\Common\Define\View(
|
||||
$c->get('folders')->templates,
|
||||
$c->get('folders')->cache,
|
||||
null,
|
||||
[
|
||||
'urls' => $c->get('urls'),
|
||||
'assets' => $c->get('assets')
|
||||
]
|
||||
);
|
||||
}
|
||||
];
|
Reference in New Issue
Block a user