Download the PHP package flsouto/obj2cli without Composer

On this page you can find all versions of the php package flsouto/obj2cli. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package obj2cli

obj2cli

Overview

This library allows you to create an interactive shell application from a plain php object. Commands are routed to instance methods, and command arguments are passed over as method arguments.

Installation

You can simply download obj2cli.php file to your project's folder or install it via composer:

Notice: in both cases you will have to include the file manually, since it will not be autoloaded!

Usage

Let's say we want to create an app that has two available commands:

This is how you could implement it using obj2cli:

That's all! Save it as my_app.php and run it through the command line:

A new session will start with the name of your app (which by default is the name of your object's class):

Now let's play around with it and see if it works as expected:

Notice: command arguments are separated by space.

Optional parameters

If you provide a default value to a parameter it will work as expected:

Especial Commands

help

The help command, if not defined in your class, will list all methods/commands available:

command --help

Shows usage of one specific command:

exit

Exists the app.

Notice: this is not the same as hitting CTRL+C. The exit command returns to the parent context (see below) while CTRL+C exists the entire app.

Creating child contexts

If a command returns another object, control will be passed to that object. See an example:

Notice how the "exit" command finished the "Multiply" context and brought us back to the "MyApp" parent context. CTRL+C would have closed both contexts.

Naming contexts

While the example above worked, it would be nice to customize the name of the "Multiply" context so that it read "Multiply 3...>". By default, the object's class name is used as name for the context, but this can be changed by implementing a method called getObj2cliName:

Running any class from the command line

This repository comes with a script called "run.php" which allows you to instantiate any class into an interactive shell program:

If the class you want to work with is autoloaded by composer's autoloader, you should provide the path to vendor/autoload.php:

Final thoughts

This is a useful tool for building interactive shell programs very quickly and also can be used to test/debug classes on the fly.


All versions of obj2cli with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package flsouto/obj2cli contains the following files

Loading the files please wait ....