PHPackages                             vertwo/plite - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. vertwo/plite

ActiveLibrary

vertwo/plite
============

Version2 PHP Framework

1266PHP

Since Oct 19Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/vertwo-oss/plite)[ Packagist](https://packagist.org/packages/vertwo/plite)[ RSS](/packages/vertwo-plite/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (3)Used By (0)

plite
=====

[](#plite)

PHP Lite Framework

This little project started out as a simple pretty-printer for arrays and maps. Really simple. It grew into this mini meta-project where I collected a bunch of PHP I've built over the years.

Adds some basic libraries for working with console-viewed logging, PHP as a CLI tool, handling basic backend stuff, a very small Postgres abstraction, as well as a small framework for abstracting a few AWS services ( S3, SecretsManager) and Twilio/Sinch/Plivo. Also comes with tools to help with ETL.

TL;DR
-----

[](#tldr)

At its core, `plite` has a few parts:

1. Some convenience functions, including a pretty-printer for arrays and maps.
2. A CLI framework to make command-line PHP easier.
3. A Web framework to make it easy to have both a dev and prod (especially a system like AWS ElasticBeanstalk) simpler, and to allow both local- and cloud-based dev.
4. An abstraction framework for AWS S3, SecretsManager, SES, etc, to build command-line tools.

It does this by providing local analogues to S3 and SecretsManager and SES which allows for local dev while offline. S3 is pretty easy to mimic with the filesystem (especially if we're just talking about BLUB CRUD), and SecretsManager is just a service that serves JSON BLOBs.

`plite` also adds a bunch of utility functions which I've found useful over the years, including debugging/logging output utility functions and time-handling functions, all of which are properly namespaced.

**BUT, one thing to note: it clogs the global namespace with a function called `clog`.**

If you hate it, extends `BoringCLI`, which does not call `clog()`, and you can avoid it and its overhead by doing `echo` or `printf` or `error_log()`or whatever yourself. See below. It doesn't remove the pollution, but you can avoid the overhead.

Why do I do this, by default? Because:

1. I'm opinionated AF, so the library is opinionated AF.
2. Every language needs a good pretty printer in the global scope.

`plite` forces this symbol to be named `clog`. This was actually the first thing I built, before it grew into all this other stuff. There are other global level functions: functions to color strings using ANSI escape sequences, and two functions `isCLI()` and `isWeb()`.

As a Command Line "framework"
-----------------------------

[](#as-a-command-line-framework)

If you are using this to create a command-line script (e.g., executable with a shebang), then your starting point is the class `vertwo\plite\CommandLine\CLI`.

Just extend the `CLI` class (or `BoringCLI`), and implement two methods:

- `main()`
- `getShortOpts()`

and add a third method, if you want to work with long options (e.g., `--verbose`):

- `getLongOpts()`

The latter two methods are for unix-style options-handling can return empty string and an empty array. So, for a hello-world, just this will do:

```
class HelloWorld extends CLI
{
    protected function getShortOpts () { return ""; }

    public function main () {    // This gets called by the framework...
        echo "Hello, world!\n";  //
        return 0;                //
    }                            //
}                                //
                                 //
HelloWorld::run();               // ...here, by CLI::run().
```

And, if you add a shebang, a PHP tag, a `use` statement, and a `require`statement, and then make the script executable, you'll be able to just execute this php file on the CLI (and, obviously, making sure to chmod +x or whatever your OS needs to make things runnable).

Now, obviously, that's a LOT of lines of code for a file that could have just been this (12 lines vs 1):

```
#! /usr/bin/php
