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
Requires
- php: >=8
Requires (Dev)
- ergebnis/composer-normalize: ^2.48
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: 2.1.30
- phpstan/phpstan-deprecation-rules: 2.0.3
- phpstan/phpstan-phpunit: 2.0.7
- phpstan/phpstan-strict-rules: 2.0.7
- phpunit/phpunit: ^12.4
- shipmonk/composer-dependency-analyser: ^1.8
- squizlabs/php_codesniffer: ^4.0
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 viaPHP_CodeSniffer
- Dependency validity via
Composer Dependency Analyser
composer.json
schema viacomposer 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