Giter VIP home page Giter VIP logo

symfony-order-processor's Introduction

symfony-order-processor

A single command Symfony application built to process orders line-by-line and produce summary output.

Table of Contents

Usage

The CLI accepts optional input and output arguments:

  • input: the path to the input file (can be a URL or a path to a local file). default: orders.jsonl
  • output: the path to the output file - the program will also determine the desired output format based on the file extension (*.csv and *.jsonl are supported). default: out.csv

Makefile/Docker

For convenience, a Makefile is provided which allows for use within a containerized environment.

Requirements

Commands

For standard usage:

  • make run: runs the CLI, installing dependencies if they haven't been already. You can optionally provide input/output arguments by setting the INPUT and OUTPUT environment variables. When used with local files, paths must be relative to the project root in order to ensure they are accessible from within the container - this applies to both input and output paths.
    • Examples:
      • INPUT="my-orders.jsonl" OUTPUT="processed-orders.jsonl" make run
      • INPUT="https://example.com/orders.jsonl" OUTPUT="processed-orders.csv" make run

Running tests:

  • make test: runs all tests using PHPUnit.

Formatting code:

Manually

If you'd prefer to set up/run the CLI yourself you may do so.

Requirements

  • PHP 8.1 or later
  • Composer 2

Commands

For standard usage:

  • composer install in the project root to install required dependencies.
  • php src/app.php to run the CLI, optionally providing the input/output arguments described previously.
    • Examples:
      • php src/app.php my-orders.jsonl processed-orders.jsonl
      • php src/app.php https://example.com/orders.jsonl processed-orders.csv

Running tests:

  • bin/phpunit tests: runs all tests using PHPUnit

Formatting code:

  • composer install --working-dir=tools/php-cs-fixer: installs the required dependencies for php-cs-fixer.
  • tools/php-cs-fixer/vendor/bin/php-cs-fixer fix src: uses php-cs-fixer to format the src directory.

Extending Functionality

Adding a new input source

Create a new service in src/Services which extends the App\Services\AbstractStreamReader class and implement the abstract methods defined within (supports, readBytes and close) - the docblocks in AbstractStreamReader describe the expected inputs/outputs for these methods. Once your new service is built you can add it to the $inputStream match block in src/app.php so that it can automatically be resolved based on the input provided to the CLI. You can look at the existing *StreamReader services for inspiration.

Adding a new output format

Create a new service in src/Services which extends the App\Services\AbstractStreamWriter class and implement the abstract methods defined within (supports and writeLine) - the docblocks in AbstractStreamWriter describe the expected inputs/outputs for these methods. Once your new service is built you can add it to the $outputStream match block in src/app.php so that it can automatically be resolved based on the output provided to the CLI. You can look at the existing *StreamWriter services for inspiration.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.