Skip to content

Commit

Permalink
Merge pull request #19 from giansalex/feature/symfony-api
Browse files Browse the repository at this point in the history
Symfony async api
  • Loading branch information
giansalex authored May 2, 2020
2 parents 94bb74b + d4aa5bb commit 821e631
Show file tree
Hide file tree
Showing 76 changed files with 4,228 additions and 2,777 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.github
docs
tests
var
vendor
.gitattributes
.gitignore
Expand Down
25 changes: 25 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# In all environments, the following files are loaded if they exist,
# the latter taking precedence over the former:
#
# * .env contains default values for the environment variables needed by the app
# * .env.local uncommitted file with local overrides
# * .env.$APP_ENV committed environment-specific defaults
# * .env.$APP_ENV.local uncommitted environment-specific overrides
#
# Real environment variables win over .env files.
#
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
#
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration

###> symfony/framework-bundle ###
APP_ENV=dev
APP_SECRET=7c227fa2152043dfcff04a2ffe103321
#TRUSTED_PROXIES=127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
#TRUSTED_HOSTS='^(localhost|example\.com)$'
###< symfony/framework-bundle ###

###> app ###
API_TOKEN=abcxyz
###> app ###
8 changes: 8 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# define your env variables for the test env here
KERNEL_CLASS='App\Tests\Kernel'
APP_SECRET='$ecretf0rt3st'
SYMFONY_DEPRECATIONS_HELPER=999999
PANTHER_APP_ENV=panther

# App env
API_TOKEN=abcxyz
9 changes: 5 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ jobs:
name: PHP Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
with:
fetch-depth: 1
- name: Setup PHP
uses: shivammathur/setup-php@1.1.1
uses: shivammathur/setup-php@v2
with:
php-version: 7.1
php-version: 7.3
extensions: pcntl
- run: composer install
- run: vendor/bin/phpunit
- run: php bin/phpunit
env:
MOCK_URL: ${{ secrets.MockServer }}
23 changes: 19 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@

###> symfony/framework-bundle ###
/.env.local
/.env.local.php
/.env.*.local
/config/secrets/prod/prod.decrypt.private.php
/public/bundles/
/var/
/vendor/
/logs/*
!/logs/README.md
/.php_cs.cache
###< symfony/framework-bundle ###

###> symfony/phpunit-bridge ###
.phpunit
.phpunit.result.cache
/phpunit.xml
###< symfony/phpunit-bridge ###

###> App ###
/.idea/
/phpunit.xml
/.php_cs.cache
###< App ###
25 changes: 11 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:7.3-alpine AS build-env
FROM php:7.4-alpine AS build-env

LABEL owner="Giancarlos Salas"
LABEL maintainer="giansalex@gmail.com"
Expand All @@ -13,28 +13,25 @@ RUN apk update && apk add --no-cache \

COPY . .

RUN cp -f docker/.htaccess . && \
cp -f docker/settings.php src/ && \
rm -rf docker

RUN composer install --no-interaction --no-dev --optimize-autoloader --ignore-platform-reqs && \
composer dump-autoload --optimize --no-dev --classmap-authoritative && \
find vendor/ -type f ! -name "*.php" -delete
composer dump-autoload --optimize --no-dev --classmap-authoritative

FROM php:7.3-apache
FROM php:7.4-alpine

ENV APP_ENV prod
ENV API_TOKEN abcxyz
EXPOSE 8080
WORKDIR /var/www

RUN apt-get update && \
RUN apk update && \
docker-php-ext-configure opcache --enable-opcache && \
docker-php-ext-install opcache && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
docker-php-ext-install pcntl

# Copy configuration
COPY docker/config/opcache.ini $PHP_INI_DIR/conf.d/
RUN a2enmod rewrite
COPY docker/docker-entrypoint.sh .

COPY --from=build-env /app /var/www/html
COPY --from=build-env /app .

VOLUME /var/www/html/logs
CMD ["sh", "./docker-entrypoint.sh"]
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ API para consultar el DNI y RUC - Perú, empleando [peru-consult](https://github

## Requerimientos

- PHP 7.1 o superior.
- ext-dom
- PHP 7.3 o superior.
- `ext-pcntl`

## Instalar

### Docker

Usar la imagen desde [Docker Hub](https://hub.docker.com/r/giansalex/peru-consult-api/)
```bash
docker pull giansalex/peru-consult-api
docker run -d -p 8080:8080 --name peru-consult -e API_TOKEN=your_key giansalex/peru-consult-api
```

### Clonar Repositorio
Expand All @@ -27,7 +27,7 @@ docker pull giansalex/peru-consult-api
git clone https://github.com/giansalex/peru-consult-api.git
cd peru-consult-api
composer install
php -S 127.0.0.1:8090 -t public
vendor/bin/server watch 0.0.0.0:8080 --adapter=App\\AppKernelAdapter
```

### Desplegar en Heroku
Expand Down Expand Up @@ -74,7 +74,7 @@ Respuesta:
### DNI
Ejecutar usando Curl.
```bash
curl -H "Accept: application/json" http://localhost:8090/api/v1/dni/48004836?token=abcxyz
curl -H "Accept: application/json" http://localhost:8080/api/v1/dni/48004836?token=abcxyz
```

Respuesta:
Expand All @@ -92,7 +92,7 @@ Respuesta:
### RUC
Ejecutar usando Curl.
```bash
curl -H "Accept: application/json" http://localhost:8090/api/v1/ruc/20131312955?token=abcxyz
curl -H "Accept: application/json" http://localhost:8080/api/v1/ruc/20131312955?token=abcxyz
```

Respuesta:
Expand Down Expand Up @@ -151,7 +151,7 @@ Respuesta:
### Consulta Validez Usuario SOL
Ejecutar usando Curl.
```bash
curl http://localhost:8090/api/v1/user-sol/20000000001/GMABCI?token=abcxyz
curl http://localhost:8080/api/v1/user-sol/20000000001/GMABCI?token=abcxyz
```

Respuesta:
Expand Down
42 changes: 42 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env php
<?php

use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\ErrorHandler\Debug;

if (!in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
echo 'Warning: The console should be invoked via the CLI version of PHP, not the '.PHP_SAPI.' SAPI'.PHP_EOL;
}

set_time_limit(0);

require dirname(__DIR__).'/vendor/autoload.php';

if (!class_exists(Application::class)) {
throw new LogicException('You need to add "symfony/framework-bundle" as a Composer dependency.');
}

$input = new ArgvInput();
if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) {
putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env);
}

if ($input->hasParameterOption('--no-debug', true)) {
putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0');
}

require dirname(__DIR__).'/config/bootstrap.php';

if ($_SERVER['APP_DEBUG']) {
umask(0000);

if (class_exists(Debug::class)) {
Debug::enable();
}
}

$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$application = new Application($kernel);
$application->run($input);
13 changes: 13 additions & 0 deletions bin/phpunit
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env php
<?php

if (!file_exists(dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php')) {
echo "Unable to find the `simple-phpunit.php` script in `vendor/symfony/phpunit-bridge/bin/`.\n";
exit(1);
}

if (false === getenv('SYMFONY_PHPUNIT_DIR')) {
putenv('SYMFONY_PHPUNIT_DIR='.__DIR__.'/.phpunit');
}

require dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php';
72 changes: 51 additions & 21 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,71 @@
"description": "Consulta RUC, DNI - Perú",
"keywords": ["peru", "rest", "ruc", "dni", "graphql"],
"homepage": "https://github.com/giansalex/peru-consult-api",
"type": "project",
"license": "MIT",
"authors": [
{
"name": "Giancarlos Salas",
"email": "giansalex@gmail.com"
}
],
"require": {
"php": "^7.1",
"slim/slim": "^3.1",
"slim/php-view": "^2.0",
"katzgrau/klogger": "^1.2",
"giansalex/peru-consult": "^4.0",
"tuupola/cors-middleware": "^0.9.2",
"webonyx/graphql-php": "^0.13.4"
"php": "^7.3",
"ext-ctype": "*",
"ext-iconv": "*",
"ext-json": "*",
"drift/http-kernel": "^0.1.10",
"drift/server": "^0.1.12",
"giansalex/peru-consult": "^4.1",
"symfony/console": "5.0.*",
"symfony/dotenv": "5.0.*",
"symfony/flex": "^1.3.1",
"symfony/framework-bundle": "5.0.*",
"symfony/yaml": "5.0.*",
"webonyx/graphql-php": "^0.13.8"
},
"require-dev": {
"phpunit/phpunit": "^7",
"clue/block-react": "^1.3"
"symfony/browser-kit": "5.0.*",
"symfony/phpunit-bridge": "^5.0"
},
"config": {
"preferred-install": {
"*": "dist"
},
"sort-packages": true
},
"autoload": {
"psr-4": {
"Peru\\Api\\": "src/app/"
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
"App\\Tests\\": "tests/"
}
},
"config": {
"process-timeout" : 0
"replace": {
"paragonie/random_compat": "2.*",
"symfony/polyfill-ctype": "*",
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php72": "*",
"symfony/polyfill-php71": "*",
"symfony/polyfill-php70": "*",
"symfony/polyfill-php56": "*"
},
"scripts": {
"test": "phpunit"
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"@auto-scripts"
],
"post-update-cmd": [
"@auto-scripts"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"allow-contrib": false,
"require": "5.0.*"
}
}

}
Loading

0 comments on commit 821e631

Please sign in to comment.