Sistema web para crear proyecto web nuevo
This commit is contained in:
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 {
|
||||
}
|
Reference in New Issue
Block a user