Download the PHP package ssitu/euclid without Composer
On this page you can find all versions of the php package ssitu/euclid. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package euclid
Short Description A PHP tool to map your classes and methods, so you can execute them from the comfort of your command line interface.
License MIT
Homepage https://github.com/I-is-as-I-does/Euclid
Informations about the package euclid
Euclid
Simple PHP tool to map your classes and methods, so you can execute them from the comfort of your command line interface.
Includes:
-
the core Euclid class that will handle your commands, offering a direct mode and a guided one;
-
a Parser, mainly to decipher direct commands;
-
something resembling a CRUD class to configure your commands map: set hooks to filter through methods; operate permanent or per-instance edits; save edits, possibly to another config file; etc -- the list of available commands will updated itself;
-
a companion class that will handle input, output and formatting, and can be used independently of Euclid;
- a sample nano bin script, allowing you to edit CLI arguments before passing them to Euclid, if you do so wish.
Getting Started
Prerequisites
- Very basic knowledge of CLI (CLI is awesome – like a lot of things made in the sixties)
- PHP 8.0.3 (probably works with earlier versions; but untested)
- Composer
Install
Set up a bin/euclid file
, and a euclid-config.json
to suit your needs.
Sample files are available in samples/
.
Setup
-
bin/euclid
file: - CLI:
Second case requires that EuclidCore was called with either a valid path to your config file, or an instance of EuclidMap.
CLI
Exit anytime by entering $
.
Guided Mode
Easily navigate through classes and methods, and then enter arguments if any. Just follow the prompts!
Direct Mode
Commands will look like this:
Your list of commands is available by entering #
;
a nano readme by entering ?
;
and you can switch to guided mode with %
.
Result
After passing a command: result will be displayed, and you can pick what to do next.
Escaping Arguments
Strings
To escape strings: you can wrap them in double quotes,
or if you're automating Euclid jobs you may use urlencode()
.
Examples:
- If you need to pass
$
as an argument without Euclid exiting, use quotes:"$"
. -
In direct mode:
Quotes here will prevent
"some string with spaces"
to be considered as four different arguments.
Arrays
You can use method parseArrayArgm($array)
available in EuclidCompanion,
or pass them as follow:
It will be parsed into:
Config
Concept
For each of your classes you wish to call from Euclid, you will need to set:
-
the class "key name", that will constitute the first part of your CLI command; Example: for a class named
DemoDoer
: its key name can bedemo
(or... whatever) -
the class full name, preceded by any applicable namespace; Example:
SSITU\Euclid\Demo\DemoDoer
- optionally, a "method hook", aka a method name, or a prefix / suffix found in the names of methods you wish to target – because not all methods are meant for CLI.
- If it's a sufix, prepend your hook with an
*
:*yourHook
; - if it's a prefix:
yourHook*
. - Example:
aforementioned
DemoDoer
class has 3 methods:buildDirTree
,buildFile
,setBobName
; method hook can be set tobuild*
;setBobName
will therefore not be listed in commands list.
- If it's a sufix, prepend your hook with an
Please note that protected and private function cannot be listed or called from CLI.
JSON File
If you have a set list of classes to call, a dedicated JSON file will be used to store their keys/names/hooks (and their auto-built list of commands).
Handling
You can set up your config:
- by manually editing the JSON file if you do so wish;
- in CLI with Euclid (menu 'edit', key *);
- or by using
EuclidMap
class and its CRUD-like methods.
Purposes
Well, I personally use that lib to automate my "build jobs" : compiling, editing, minifying, moving assets around, and sending me a message if something went wrong.
Contributing
Yes please! You can take a loot at CONTRIBUTING. This repo also features a Discussions tab.
License
This project is under the MIT License; cf. LICENSE for details.