Skip to content

Commit

Permalink
Merge pull request #286 from AntonShevchuk/master
Browse files Browse the repository at this point in the history
Migrate to Bluzman v.2.1.3
  • Loading branch information
Anton committed Apr 11, 2017
2 parents c9e0219 + 266affa commit a2d9061
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 100 deletions.
25 changes: 13 additions & 12 deletions .travis.yml
Expand Up @@ -6,30 +6,31 @@ before_install:
- nvm install stable
- npm update -g npm
install:
# Newman
- npm install -g newman
# Composer
- composer self-update
- COMPOSER_ROOT_VERSION=dev-master composer install
# Scrutinizer
- wget https://scrutinizer-ci.com/ocular.phar
before_script:
# Database
- mysql -e 'CREATE DATABASE bluz;'
# Newman
- npm install -g newman
before_script:
# Migrations
- php vendor/bin/bluzman db:migrate
- php vendor/bin/bluzman db:seed:run
# Scrutinizer
- wget https://scrutinizer-ci.com/ocular.phar
script:
# Make directory for reports
- mkdir .reports
# Code style
script:
# Check code style
- php vendor/bin/phpcs ./application --standard=PSR1,PSR2 --encoding=utf-8 --ignore=./application/_loader.php
# WebServer run
- nohup bash -c "php -S 127.0.0.1:8000 -t ./public/ ./public/routing.php 2>&1 &" && sleep 1; cat nohup.out
# CodeCeption
# Run built-in web-server
- php vendor/bin/bluzman server:start --host 127.0.0.1 -b
# Run CodeCeption tests
- php vendor/bin/codecept run --coverage --coverage-xml -v
# Newman run
# Run postman/newman tests
- newman run tests/postman/collection.json -e tests/postman/environment.json
after_script:
after_success:
- php vendor/bin/coveralls -v
- php ocular.phar code-coverage:upload --format=php-clover tests/_output/coverage.xml
notifications:
Expand Down
105 changes: 99 additions & 6 deletions application/library/Application/CliBootstrap.php
Expand Up @@ -14,13 +14,17 @@
use Application\Users\Table;
use Bluz\Application\Application;
use Bluz\Application\Exception\ApplicationException;
use Bluz\Cli;
use Bluz\Proxy\Auth;
use Bluz\Proxy\Config;
use Bluz\Proxy\Logger;
use Bluz\Proxy\Request;
use Bluz\Proxy\Response;
use Bluz\Proxy\Router;
use Bluz\Request\RequestFactory;
use function GuzzleHttp\Psr7\parse_query;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

/**
* Bootstrap for CLI
Expand All @@ -39,26 +43,86 @@ class CliBootstrap extends Application
*/
protected $layoutFlag = false;

/**
* @var InputInterface
*/
protected $input;

/**
* @var OutputInterface
*/
protected $output;

/**
* @param InputInterface $input
*/
public function setInput(InputInterface $input)
{
$this->input = $input;
}

/**
* @return InputInterface
*/
public function getInput()
{
return $this->input;
}

/**
* @param OutputInterface $output
*/
public function setOutput(OutputInterface $output)
{
$this->output = $output;
}

/**
* @return OutputInterface
*/
public function getOutput()
{
return $this->output;
}

/**
* get CLI Request
* @return void
* @throws ApplicationException
*/
public function initRequest()
{
$arguments = getopt("u:", ["uri:"]);
$uri = $this->getInput()->getArgument('uri');

if (!array_key_exists('u', $arguments) && !array_key_exists('uri', $arguments)) {
throw new ApplicationException('Attribute `--uri` is required');
if (!$parsedQuery = parse_url($uri, PHP_URL_QUERY)) {
$this->getOutput()->writeln('<error>ERROR: unvalid URI format</error>');
}

$uri = $arguments['u'] ?? $arguments['uri'];
parse_str($parsedQuery, $query);

$request = RequestFactory::fromGlobals(['REQUEST_URI' => $uri, 'REQUEST_METHOD' => 'CLI']);
$request = RequestFactory::fromGlobals(['REQUEST_URI' => $uri, 'REQUEST_METHOD' => 'CLI'], $query);

Request::setInstance($request);
}

/**
* initConfig
*
* @return void
*/
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
Expand Down Expand Up @@ -86,6 +150,35 @@ protected function preDispatch($module, $controller, $params = array())
parent::preDispatch($module, $controller, $params);
}

/**
* Render, is send Response
*
* @return void
*/
public function render()
{
$io = new SymfonyStyle($this->getInput(), $this->getOutput());
$io->title('Bluz CLI');

if ($params = Request::getParams()) {
foreach ($params as $key => $value) {
$io->writeln("<info>$key</info>: $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('');
}

/**
* @return void
*/
Expand Down
4 changes: 3 additions & 1 deletion application/modules/acl/controllers/save.php
Expand Up @@ -46,7 +46,9 @@
if (empty($acl)) {
Messages::addError('Privileges set is empty. You can\'t remove all of them');
} elseif (Db::transaction($callback)) {
Cache::clearTags(['privileges']);
if (!Cache::clearTags(['privileges'])) {
Cache::clear();
}
Messages::addSuccess('All data was saved');
} else {
Messages::addError('Internal Server Error');
Expand Down
81 changes: 0 additions & 81 deletions bin/cli.php

This file was deleted.

0 comments on commit a2d9061

Please sign in to comment.