diff --git a/REQUIREMENTS.md b/REQUIREMENTS.md new file mode 100644 index 0000000..cf84e2b --- /dev/null +++ b/REQUIREMENTS.md @@ -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 diff --git a/common/Controller/API/Create.php b/common/Controller/API/Create.php new file mode 100644 index 0000000..f9de0a7 --- /dev/null +++ b/common/Controller/API/Create.php @@ -0,0 +1,62 @@ +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); + } +} diff --git a/common/Controller/API/Dependencies.php b/common/Controller/API/Dependencies.php new file mode 100644 index 0000000..db472e5 --- /dev/null +++ b/common/Controller/API/Dependencies.php @@ -0,0 +1,37 @@ +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); + } +} diff --git a/common/Controller/Web/Create.php b/common/Controller/Web/Create.php new file mode 100644 index 0000000..a684aec --- /dev/null +++ b/common/Controller/Web/Create.php @@ -0,0 +1,75 @@ + [ + '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')); + } +} diff --git a/common/Controller/Web/Home.php b/common/Controller/Web/Home.php new file mode 100644 index 0000000..6bc469b --- /dev/null +++ b/common/Controller/Web/Home.php @@ -0,0 +1,14 @@ +list(); + return $view->render($response, 'home', compact('projects')); + } +} diff --git a/common/Controller/Web/Project.php b/common/Controller/Web/Project.php new file mode 100644 index 0000000..48f0656 --- /dev/null +++ b/common/Controller/Web/Project.php @@ -0,0 +1,181 @@ +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 + ])); + } +} diff --git a/common/Factory/Project.php b/common/Factory/Project.php new file mode 100644 index 0000000..fffb855 --- /dev/null +++ b/common/Factory/Project.php @@ -0,0 +1,135 @@ +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; + } +} diff --git a/common/Service/Projects.php b/common/Service/Projects.php new file mode 100644 index 0000000..314a9e2 --- /dev/null +++ b/common/Service/Projects.php @@ -0,0 +1,733 @@ +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 = [ + "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 = [ + '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 = [ + ' 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 = [ + " 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 = [ + " 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 = [ + "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 = [ + "createFile($folder, 'router.php', $content); + } + protected function addRoutesWebFile(string $folder): bool { + $content = [ + "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 = [ + "", + "", + "@include('layout.head')", + "@include('layout.body')", + "", + "" + ]; + $folder = implode(DIRECTORY_SEPARATOR, [ + $folder, + 'resources', + 'views', + 'layout' + ]); + return $this->createFile($folder, 'base.blade.php', $content); + } + protected function addLayoutBodyFile(string $folder): bool { + $content = [ + "", + " @include('layout.header')", + "
", + "
", + " @yield('page_content')", + "
", + "
", + " @include('layout.footer')", + "", + "" + ]; + $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 = [ + "", + " ", + " @yield('page_title')", + " @include('layout.styles')", + "", + "" + ]; + $folder = implode(DIRECTORY_SEPARATOR, [ + $folder, + 'resources', + 'views', + 'layout' + ]); + return $this->createFile($folder, 'head.blade.php', $content); + } + protected function addLayoutHeaderFile(string $folder): bool { + $content = [ + "
", + " @include('layout.menu')", + "
", + "" + ]; + $folder = implode(DIRECTORY_SEPARATOR, [ + $folder, + 'resources', + 'views', + 'layout' + ]); + return $this->createFile($folder, 'header.blade.php', $content); + } + protected function addLayoutMenuFile(string $folder): bool { + $content = [ + "", + "" + ]; + $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)", + " ", + " @endforeach", + "@endif", + "", + "", + "", + "@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)", + " ", + " @endforeach", + "@endif", + "@if (isset(\$assets->fonts))", + " @foreach (\$assets->fonts as \$font)", + " ", + " @endforeach", + "@endif", + "", + "@stack('styles')", + "", + "", + "" + ]; + $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 = [ + '{$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 = [ + 'render(\$response, '{$template}');", + ' }', + '}', + '' + ]; + $folder = implode(DIRECTORY_SEPARATOR, [ + $this->folder, + $project, + 'common', + 'Controller', + ucwords($space) + ]); + return $this->createFile($folder, $name . '.php', $content); + } +} diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..ac0cfd6 --- /dev/null +++ b/composer.json @@ -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" + } + } +} diff --git a/provm/common/Alias/View.php b/provm/common/Alias/View.php new file mode 100644 index 0000000..40dbeee --- /dev/null +++ b/provm/common/Alias/View.php @@ -0,0 +1,8 @@ +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++; + } + } +} diff --git a/provm/common/Define/Controller.php b/provm/common/Define/Controller.php new file mode 100644 index 0000000..bb4a9d5 --- /dev/null +++ b/provm/common/Define/Controller.php @@ -0,0 +1,25 @@ +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); + } +} diff --git a/provm/common/Define/Controller/Json.php b/provm/common/Define/Controller/Json.php new file mode 100644 index 0000000..76dd338 --- /dev/null +++ b/provm/common/Define/Controller/Json.php @@ -0,0 +1,20 @@ +getBody()->write($data); + return $request + ->withHeader('Content-Type', 'application/json') + ->withStatus(201); + } +} diff --git a/provm/common/Define/Controller/Redirect.php b/provm/common/Define/Controller/Redirect.php new file mode 100644 index 0000000..c1b3f79 --- /dev/null +++ b/provm/common/Define/Controller/Redirect.php @@ -0,0 +1,12 @@ +withHeader('Location', $uri) + ->withStatus($status); + } +} diff --git a/provm/common/Define/View.php b/provm/common/Define/View.php new file mode 100644 index 0000000..ef83f64 --- /dev/null +++ b/provm/common/Define/View.php @@ -0,0 +1,8 @@ +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]; + } + } +} diff --git a/public/.htaccess b/public/.htaccess new file mode 100644 index 0000000..66ef8f6 --- /dev/null +++ b/public/.htaccess @@ -0,0 +1,4 @@ +RewriteEngine On +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule ^ index.php [QSA,L] diff --git a/public/api/.htaccess b/public/api/.htaccess new file mode 100644 index 0000000..66ef8f6 --- /dev/null +++ b/public/api/.htaccess @@ -0,0 +1,4 @@ +RewriteEngine On +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule ^ index.php [QSA,L] diff --git a/public/api/index.php b/public/api/index.php new file mode 100644 index 0000000..223ef89 --- /dev/null +++ b/public/api/index.php @@ -0,0 +1,8 @@ +run(); diff --git a/public/index.php b/public/index.php new file mode 100644 index 0000000..c52dc2c --- /dev/null +++ b/public/index.php @@ -0,0 +1,8 @@ +run(); diff --git a/resources/routes/api.php b/resources/routes/api.php new file mode 100644 index 0000000..78a510a --- /dev/null +++ b/resources/routes/api.php @@ -0,0 +1,14 @@ +isDir()) { + continue; + } + include_once $file->getRealPath(); + } +} diff --git a/resources/routes/api/create.php b/resources/routes/api/create.php new file mode 100644 index 0000000..a4569ef --- /dev/null +++ b/resources/routes/api/create.php @@ -0,0 +1,13 @@ +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']); + }); +}); diff --git a/resources/routes/api/dependencies.php b/resources/routes/api/dependencies.php new file mode 100644 index 0000000..7803233 --- /dev/null +++ b/resources/routes/api/dependencies.php @@ -0,0 +1,6 @@ +group('/dependencies', function($app) { + $app->get('/search', [Dependencies::class, 'search']); +}); diff --git a/resources/routes/router.php b/resources/routes/router.php new file mode 100644 index 0000000..04d6ec0 --- /dev/null +++ b/resources/routes/router.php @@ -0,0 +1,2 @@ +isDir()) { + continue; + } + include_once $file->getRealPath(); + } +} + +$app->get('/', Home::class); diff --git a/resources/routes/web/create.php b/resources/routes/web/create.php new file mode 100644 index 0000000..efe52b6 --- /dev/null +++ b/resources/routes/web/create.php @@ -0,0 +1,8 @@ +group('/create', function($app) { + $app->post('/2', [Create::class, 'step2']); + $app->post('/3', [Create::class, 'step3']); + $app->get('[/]', Create::class); +}); diff --git a/resources/routes/web/project.php b/resources/routes/web/project.php new file mode 100644 index 0000000..fae95ad --- /dev/null +++ b/resources/routes/web/project.php @@ -0,0 +1,24 @@ +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); +}); diff --git a/resources/routes/web/steps.php b/resources/routes/web/steps.php new file mode 100644 index 0000000..4fe1071 --- /dev/null +++ b/resources/routes/web/steps.php @@ -0,0 +1,6 @@ +group('/step', function($app) { + $app->post('/2', [Home::class, 'step2']); +}); diff --git a/resources/views/create/base.blade.php b/resources/views/create/base.blade.php new file mode 100644 index 0000000..42810ce --- /dev/null +++ b/resources/views/create/base.blade.php @@ -0,0 +1,26 @@ +@extends('layout.base') + +@section('page_content') +

Crear Proyecto

+
+
+ +
+ Formulario +
+
+
+ +
+ Confirmar +
+
+
+ +
+ Crear +
+
+
+ @yield('content') +@endsection diff --git a/resources/views/create/step1.blade.php b/resources/views/create/step1.blade.php new file mode 100644 index 0000000..b636837 --- /dev/null +++ b/resources/views/create/step1.blade.php @@ -0,0 +1,68 @@ +@extends('create.base') + +@section('content') +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+@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 diff --git a/resources/views/create/step2.blade.php b/resources/views/create/step2.blade.php new file mode 100644 index 0000000..b4c54fb --- /dev/null +++ b/resources/views/create/step2.blade.php @@ -0,0 +1,30 @@ +@extends('create.base') + +@section('content') + @if (!$exists) +
+ + No existe +
+ @else +
+ + Proyecto ya existe +
+ @endif +
+
+ composer.json +
+
{{$composer}}
+
+ @if (!$exists) +
+ + +
+ @endif +@endsection diff --git a/resources/views/create/step3.blade.php b/resources/views/create/step3.blade.php new file mode 100644 index 0000000..273bf82 --- /dev/null +++ b/resources/views/create/step3.blade.php @@ -0,0 +1,140 @@ +@extends('create.base') + +@section('content') +
+
+
+
+
+
+
+@endsection + +@push('scripts') + +@endpush diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php new file mode 100644 index 0000000..a3e8e85 --- /dev/null +++ b/resources/views/home.blade.php @@ -0,0 +1,10 @@ +@extends('layout.base') + +@section('page_content') +

Proyectos

+
+ @foreach ($projects as $project) + {{$project->name}} + @endforeach +
+@endsection diff --git a/resources/views/layout/base.blade.php b/resources/views/layout/base.blade.php new file mode 100644 index 0000000..9deb8c1 --- /dev/null +++ b/resources/views/layout/base.blade.php @@ -0,0 +1,5 @@ + + +@include('layout.head') +@include('layout.body') + diff --git a/resources/views/layout/body.blade.php b/resources/views/layout/body.blade.php new file mode 100644 index 0000000..08e95ae --- /dev/null +++ b/resources/views/layout/body.blade.php @@ -0,0 +1,9 @@ + + @include('layout.header') +
+
+ @yield('page_content') +
+
+ @include('layout.footer') + diff --git a/resources/views/layout/footer.blade.php b/resources/views/layout/footer.blade.php new file mode 100644 index 0000000..8d5c71e --- /dev/null +++ b/resources/views/layout/footer.blade.php @@ -0,0 +1 @@ +@include('layout.scripts') diff --git a/resources/views/layout/head.blade.php b/resources/views/layout/head.blade.php new file mode 100644 index 0000000..5774b8d --- /dev/null +++ b/resources/views/layout/head.blade.php @@ -0,0 +1,5 @@ + + + @yield('page_title') + @include('layout.styles') + diff --git a/resources/views/layout/header.blade.php b/resources/views/layout/header.blade.php new file mode 100644 index 0000000..5afb243 --- /dev/null +++ b/resources/views/layout/header.blade.php @@ -0,0 +1,3 @@ +
+ @include('layout.menu') +
diff --git a/resources/views/layout/menu.blade.php b/resources/views/layout/menu.blade.php new file mode 100644 index 0000000..fbfd208 --- /dev/null +++ b/resources/views/layout/menu.blade.php @@ -0,0 +1,4 @@ + diff --git a/resources/views/layout/scripts.blade.php b/resources/views/layout/scripts.blade.php new file mode 100644 index 0000000..b6b604c --- /dev/null +++ b/resources/views/layout/scripts.blade.php @@ -0,0 +1,13 @@ +@if (isset($assets->scripts)) + @foreach ($assets->scripts as $script) + + @endforeach +@endif + + + +@stack('scripts') diff --git a/resources/views/layout/styles.blade.php b/resources/views/layout/styles.blade.php new file mode 100644 index 0000000..2eb95dc --- /dev/null +++ b/resources/views/layout/styles.blade.php @@ -0,0 +1,16 @@ +@if (isset($assets->styles)) + @foreach ($assets->styles as $style) + + @endforeach +@endif +@if (isset($assets->fonts)) + @foreach ($assets->fonts as $font) + + @endforeach +@endif + +@stack('styles') + + diff --git a/resources/views/projects/base.blade.php b/resources/views/projects/base.blade.php new file mode 100644 index 0000000..f00e97a --- /dev/null +++ b/resources/views/projects/base.blade.php @@ -0,0 +1,9 @@ +@extends('layout.base') + +@section('page_content') +

+ Proyecto - {{$project->name ?? $project}} + @yield('title') +

+ @yield('content') +@endsection diff --git a/resources/views/projects/controllers/add.blade.php b/resources/views/projects/controllers/add.blade.php new file mode 100644 index 0000000..ecb165c --- /dev/null +++ b/resources/views/projects/controllers/add.blade.php @@ -0,0 +1,50 @@ +@extends('projects.base') + +@section('title') + - Agregar Controlador +@endsection + +@section('content') +
+
+ + +
+
+
+ + +
+
+ + +
+
+
+ +
+
+@endsection + +@push('global_script') + $('#space').dropdown() + $('#views').dropdown() +@endpush diff --git a/resources/views/projects/routes/add.blade.php b/resources/views/projects/routes/add.blade.php new file mode 100644 index 0000000..483773a --- /dev/null +++ b/resources/views/projects/routes/add.blade.php @@ -0,0 +1,63 @@ +@extends('projects.base') + +@section('title') + - Agregar Ruta +@endsection + +@section('content') +
+
+ + +
+
+
+ + +
+
+ + +
+
+ + +
+
+
+ +
+
+@endsection + +@push('global_script') + $('#space').dropdown() + $('#group').dropdown({ + allowAdditions: true + }) + $('#controller').dropdown() +@endpush diff --git a/resources/views/projects/show.blade.php b/resources/views/projects/show.blade.php new file mode 100644 index 0000000..91a8573 --- /dev/null +++ b/resources/views/projects/show.blade.php @@ -0,0 +1,123 @@ +@extends('projects.base') + +@section('content') +
+

+ GIT +

+
{{implode(PHP_EOL, $project->git)}}
+
+
+

+ Composer +

+
{{json_encode($project->composer, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)}}
+
+
+

+ Config +

+
+ @foreach ($project->config as $config) +
+ {{$config}} +
+ @endforeach +
+
+
+

+
+
+ Controllers +
+
+ + + +
+
+

+ @if ($project->controllers !== null and count((array) $project->controllers) > 0) +
+ @foreach ($project->controllers as $path => $controller) +
+ {{$controller}} +
+ @endforeach +
+ @endif +
+
+

+
+
+ Services +
+
+ + + +
+
+

+ @if ($project->services !== null and count((array) $project->services) > 0) +
+ @foreach ($project->services as $path => $service) +
+ {{$path}} +
{{json_encode($service, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)}}
+
+ @endforeach +
+ @endif +
+
+

+
+
+ Routes +
+
+ + + +
+
+

+ @if ($project->routes !== null and count((array) $project->routes) > 0) +
+ @foreach ($project->routes as $path => $routes) + @foreach ($routes as $route) +
+ {{$route}} +
+ @endforeach + @endforeach +
+ @endif +
+
+

+
+
+ Views +
+
+ + + +
+
+

+ @if ($project->views !== null and count((array) $project->views) > 0) +
+ @foreach ($project->views as $path => $view) +
+ {{$view}} +
+ @endforeach +
+ @endif +
+@endsection diff --git a/resources/views/projects/views/add.blade.php b/resources/views/projects/views/add.blade.php new file mode 100644 index 0000000..fe6ebb1 --- /dev/null +++ b/resources/views/projects/views/add.blade.php @@ -0,0 +1,58 @@ +@extends('projects.base') + +@section('title') + - Agregar Vista +@endsection + +@section('content') +
+
+ + +
+
+
+ + +
+
+ + +
+
+ + +
+
+
+ +
+
+@endsection + +@push('global_script') + $('#subcarpetas').dropdown({ + allowAdditions: true + }) + $('#extends').dropdown() +@endpush diff --git a/setup/api/config.php b/setup/api/config.php new file mode 100644 index 0000000..afdecc0 --- /dev/null +++ b/setup/api/config.php @@ -0,0 +1,16 @@ + 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; + }) +]; diff --git a/setup/app.php b/setup/app.php new file mode 100644 index 0000000..5b47da8 --- /dev/null +++ b/setup/app.php @@ -0,0 +1,60 @@ +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; diff --git a/setup/common/config.php b/setup/common/config.php new file mode 100644 index 0000000..987d494 --- /dev/null +++ b/setup/common/config.php @@ -0,0 +1,33 @@ + '/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; + } +]; diff --git a/setup/common/setup.php b/setup/common/setup.php new file mode 100644 index 0000000..0974cf1 --- /dev/null +++ b/setup/common/setup.php @@ -0,0 +1,14 @@ + 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'])); + } +]; diff --git a/setup/composer.php b/setup/composer.php new file mode 100644 index 0000000..9dd600d --- /dev/null +++ b/setup/composer.php @@ -0,0 +1,10 @@ + 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' + ] + ] +]; diff --git a/setup/web/setup.php b/setup/web/setup.php new file mode 100644 index 0000000..37f4aaa --- /dev/null +++ b/setup/web/setup.php @@ -0,0 +1,16 @@ + 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') + ] + ); + } +];