jan-wennrich/logic-gates

Library to simulate circuits using gates like AND, OR, XOR.

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/jan-wennrich/logic-gates

1.0.0 2025-10-04 23:10 UTC

This package is auto-updated.

Last update: 2025-10-04 23:14:05 UTC


README

A tiny PHP library for building and simulating digital circuits from simple logic gates (e.g., AND, OR, NOT, XOR) and composing them into larger combinational networks.

โœจ Features

  • All common boolean gates:
    • AND & NAND
    • OR & NOR
    • XOR & XNOR
    • NOT & BUFFER
    • IMPLY & NIMPLY
    • TRUE & FALSE
  • Compose gates into circuits by wiring outputs to inputs
  • Zero dependencies
  • Unit tested

๐Ÿ“ฆ Installation

This project is a standard Composer library.

composer require jan-wennrich/logic-gates

๐Ÿš€ Example

The example shows how the AND gate works:

<?php

require __DIR__ . '/vendor/autoload.php';

use JanW\LogicGates\AndGate;
use JanW\LogicGates\BinaryFalseGate;
use JanW\LogicGates\BinaryTrueGate;

$falseInput = new BinaryFalseGate();
$trueInput = new BinaryTrueGate();

(new AndGate($falseInput, $falseInput))->getOutput()); // returns "false"
(new AndGate($falseInput, $trueInput))->getOutput()); // returns "false"
(new AndGate($trueInput, $falseInput))->getOutput()); // returns "false"
(new AndGate($trueInput, $trueInput))->getOutput()); // returns "true"

๐Ÿงช Testing

This library is thoroughly tested in multiple ways:

  • Unit tests via PHPUnit
  • Static analysis via PHPStan
  • PSR-12 code style via PHP_CodeSniffer
  • Dependency validity via Composer Dependency Analyser
  • composer.json schema via composer validate

The tests can be executed after cloning this repository and installing all dev-dependencies:

git clone git@github.com:JanWennrich/Logic-Gates.git
composer install

All tests can be run via the Composer test script:

composer test

Specific tests can be run via their corresponding binaries in vendor/bin/.
To run PHPUnit for example use this command:

vendor/bin/phpunit

๐Ÿ“„ License

GPL-3.0 - see LICENSE