Skip to content

Commit

Permalink
Merge pull request #315 from AntonShevchuk/develop
Browse files Browse the repository at this point in the history
Migrate to new version of framework
  • Loading branch information
Anton authored Oct 31, 2018
2 parents cb46918 + 51df7bc commit 57b8541
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 56 deletions.
16 changes: 13 additions & 3 deletions application/layouts/partial/grid/pagination.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,21 @@ if (!$grid) {
<?php if ($prev = $grid->prev()) : ?>
<li class="page-item"><a rel="prev" class="page-link" href="<?= $prev ?>">&laquo;</a></li>
<?php else : ?>
<li class="page-item disabled"><a href="#" class="page-link" onclick="javascript:return false;">&laquo;</a></li>
<li class="page-item disabled"><a href="#" class="page-link" onclick="return false;">&laquo;</a></li>
<?php endif; ?>


<?php for ($page = 1; $page <= $grid->pages(); $page++) : ?>
<?php if (
$grid->pages() > 10 // more than 10 pages
&& $page !== 1 // always show first page
&& $page !== $grid->pages() // always show last page
&& abs($page - $grid->getPage()) > 3 // show 3 pages before and after current page
) : ?>
<?php if ($grid->pages() > 10 && ($page === 2 or $page === $grid->pages() - 1)): ?>
<li class="page-item"><a href="#" class="page-link">...</a></li>
<?php endif; ?>
<?php continue;?>
<?php endif; ?>
<li class="page-item <?= ($page === $grid->getPage() ? 'active' : '') ?>">
<a href="<?= $grid->page($page) ?>" class="page-link"><?= $page ?></a>
</li>
Expand All @@ -25,7 +35,7 @@ if (!$grid) {
<?php if ($next = $grid->next()) : ?>
<li class="page-item"><a rel="next" class="page-link" href="<?= $next ?>">&raquo;</a></li>
<?php else : ?>
<li class="page-item disabled"><a href="#" class="page-link" onclick="javascript:return false;">&raquo;</a></li>
<li class="page-item disabled"><a href="#" class="page-link" onclick="return false;">&raquo;</a></li>
<?php endif; ?>
</ul>
</nav>
Expand Down
13 changes: 0 additions & 13 deletions application/library/Application/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,6 @@
*/
class Bootstrap extends Application
{
/**
* {@inheritdoc}
*/
protected function preProcess(): void
{
parent::preProcess();

$path = $this->getPath() . '/modules';
foreach (glob($path .'/*/init.php') as $initial) {
(include $initial)($this);
}
}

/**
* {@inheritdoc}
*
Expand Down
56 changes: 16 additions & 40 deletions application/library/Application/CliBootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Bluz\Application\Application;
use Bluz\Controller\Controller;
use Bluz\Proxy\Auth;
use Bluz\Proxy\Config;
use Bluz\Proxy\Logger;
use Bluz\Proxy\Request;
use Bluz\Proxy\Response;
Expand Down Expand Up @@ -55,7 +54,7 @@ class CliBootstrap extends Application
/**
* @param InputInterface $input
*/
public function setInput(InputInterface $input)
public function setInput(InputInterface $input): void
{
$this->input = $input;
}
Expand All @@ -71,7 +70,7 @@ public function getInput()
/**
* @param OutputInterface $output
*/
public function setOutput(OutputInterface $output)
public function setOutput(OutputInterface $output): void
{
$this->output = $output;
}
Expand All @@ -88,15 +87,14 @@ public function getOutput()
* get CLI Request
*
* @return void
* @throws \Application\Exception
* @throws \InvalidArgumentException
*/
public function initRequest()
public function initRequest(): void
{
$uri = $this->getInput()->getArgument('uri');

$parsedQuery = parse_url($uri, PHP_URL_QUERY);
if (false !== $parsedQuery) {
if (false !== $parsedQuery && null !== $parsedQuery) {
parse_str($parsedQuery, $query);
} else {
$query = [];
Expand All @@ -107,30 +105,12 @@ public function initRequest()
Request::setInstance($request);
}

/**
* initConfig
*
* @return void
* @throws \Bluz\Config\ConfigException
*/
public function initConfig()
{
$config = new \Bluz\Config\Config();
$config->setPath(self::getInstance()->getPath());
$config->setEnvironment(self::getInstance()->getEnvironment());
$config->init();

Config::setInstance($config);

parent::initConfig();
}

/**
* Pre process
*
* @return void
*/
protected function preProcess()
protected function preProcess(): void
{
Router::process();
Response::setType('CLI');
Expand All @@ -142,12 +122,14 @@ protected function preProcess()
* @param Controller $controller
*
* @return void
* @throws \Bluz\Db\Exception\DbException
*/
protected function preDispatch($controller)
protected function preDispatch($controller): void
{
// auth as CLI user
$cliUser = Table::findRowWhere(['login' => 'system']);
Auth::setIdentity($cliUser);
if ($cliUser = Table::findRowWhere(['login' => 'system'])) {
Auth::setIdentity($cliUser);
}

parent::preDispatch($controller);
}
Expand All @@ -157,28 +139,22 @@ protected function preDispatch($controller)
*
* @return void
*/
public function render()
public function render(): void
{
$io = new SymfonyStyle($this->getInput(), $this->getOutput());
$io->title('Bluz CLI');

if ($params = Request::getParams()) {
foreach ($params as $key => $value) {
$key = is_int($key) ? "<comment>$key</comment>" : "<info>$key</info>";
$key = \is_int($key) ? "<comment>$key</comment>" : "<info>$key</info>";
$io->writeln("$key: $value");
}
}

$io->writeln('');
$io->writeln('========');
$io->writeln('');

$data = Response::getBody()->getData()->toArray();

foreach ($data as $key => $value) {
$io->writeln("<info>$key</info>: $value");
}

$io->writeln(json_encode(Response::getBody()));
$io->writeln('');
}

Expand All @@ -187,7 +163,7 @@ public function render()
*
* @return void
*/
public function end()
public function end(): void
{
if ($errors = Logger::get('error')) {
$this->sendErrors($errors);
Expand All @@ -201,13 +177,13 @@ public function end()
}

/**
* sendErrorBody
* Send errors to logger
*
* @param array $errors
*
* @return void
*/
protected function sendErrors($errors)
protected function sendErrors($errors): void
{
foreach ($errors as $message) {
errorLog(new \ErrorException($message, 0, E_USER_ERROR));
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"type": "library",
"require": {
"php": ">=7.1",
"ext-json": "*",
"bluzphp/bluzman": "~2.4",
"bluzphp/framework": "~7.10",
"bluzphp/composer-plugin": "~2.1",
Expand Down

0 comments on commit 57b8541

Please sign in to comment.