Skip to content

ixnode/php-json-beautifier

Repository files navigation

PHPJsonBeautifier

CI workflow Release PHP PHPStan PHPStan LICENSE

An example project that uses the following techniques:

Run the app

Create a docker-compose.yml

Create a file named docker-compose.yml with the following content:

# ===========================================
# ❯ mkdir docker-compose && cd docker-compose
# ❯ vi docker-compose.yml
# ===========================================

version: "3.8"

# Configure services
services:

  # Nginx to serve the app.
  nginx:
    image: "nginx:latest"
    container_name: "de.ixno.php-json-beautifier.nginx"
    hostname: "de-ixno-php-json-beautifier-nginx"
    restart: always
    ports:
      - 8000:80
    volumes:
      # Server static pages (uses the data from php service)
      - data:/var/www/web
      # Add nginx configuration (uses the data from php service)
      - nginx_config:/etc/nginx/conf.d
    depends_on:
      - php
      - composer

  # Use ixnode/php-json-beautifier:latest image (originated from image php:8.0.11-fpm) with the data it contains
  php:
    image: "ixnode/php-json-beautifier:latest"
    container_name: "de.ixno.php-json-beautifier.php"
    hostname: "de-ixno-php-json-beautifier-php"
    restart: always
    volumes:
      # This container shares the folder /var/www/web via volume data, because the container starts
      # first and the content already exists
      - data:/var/www/web
      # This container shares the folder /var/www/web/docker/nginx/conf.d via volume nginx_config, because
      # the container starts first and the content already exists
      - nginx_config:/var/www/web/docker/nginx/conf.d

  # Composer image: This container is executed once and performs a composer install.
  composer:
    image: "composer:latest"
    container_name: "de.ixno.php-json-beautifier.composer"
    hostname: "de-ixno-php-json-beautifier-composer"
    command: ["composer", "install"]
    volumes:
      - data:/app # This container shares the folder /app via volume data, because it already exists

# Configure volumes
volumes:
  data:
    name: "de.ixno.php-json-beautifier.volume.data"
  nginx_config:
    name: "de.ixno.php-json-beautifier.volume.nginx.config"

Create a .env file

If you like nicely named projects, use the .env file

# @see https://docs.docker.com/compose/reference/envvars/#compose_project_name
# ❯ vi docker-compose/.env
COMPOSE_PROJECT_NAME=de-ixno-php-json-beautifier

Start containers

❯ docker-compose up -d

Open browser

Or use command line

Via parameter

❯ docker-compose exec php bin/console app:json:beautify '{"value": "123"}'
{
    "value": "123"
}

Via STDIN

echo '{"value": "123"}' | docker-compose exec php bin/console app:json:beautify
{
    "value": "123"
}

Other tasks