Download the PHP package phpixie/console without Composer

On this page you can find all versions of the php package phpixie/console. 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 console

Console

PHPixie console command component

Author Source Code Software License

PHPixie Console allows you to define and run commands in the command line. The main benefit as opposed to just keeping a folder with PHP scripts are the ability to define options and arguments, validate them, generate command usage etc.

Migrating an Existing PHPixie Project

If you create a fresh PHPixie project you are already ready to go, otherwise you need to do a few small modifications to the project, by updating some files from the new project skeleton:

  1. https://github.com/PHPixie/Project/blob/master/console
  2. https://github.com/PHPixie/Project/blob/master/src/Project/Framework/Bundles.php
  3. Add "phpixie/framework-bundle": "~3.0" to composer.json

Optionally also copy the Console factory and the example Greet Command:

  1. https://github.com/PHPixie/Project/blob/master/bundles/app/src/Project/App/Console.php
  2. https://github.com/PHPixie/Project/blob/master/bundles/app/src/Project/App/Console/Greet.php
  3. Register the Console class in your Builder, like here: https://github.com/PHPixie/Project/blob/master/bundles/app/src/Project/App/Builder.php

Running commands

Now try running the console script:

This will give you the list of available commands and their descriptions, e.g.:

You can get extended information about a command by using the help command:

Default commands

framework:installWebAssets Its purpose is creating symlinks from bundle directories to the /web/bundles folder, e.g. /web/bundles/app -> /bundles/app/web. The idea behind it is that we can have bundles that are installable and updatable via composer that provide their own web assets. The --copy flag will copy the directories instead of symlinking them. This is usefull if you want to deploy the files to some CDN network afterwards.

framework:generateBundle This command generates and registers a new bundle within your project.

Adding your own commands

There is a sample app:greet command provided in the skeleton project. They are added in the same was as HTTP Processors, using the \Project\App\Console class. To add a new command you have to add it's name to the array returned by the commandNames method, and create a build<command_name>Command method.

You can configure your command to add a description and define options and arguments. Let's look at the default Greet command:

Arguments and options

Let's say we want to define a command that dumps some tables from the database, a typical call might look like this:

Here myDatabase is the name of the database, followed by the names of the tables we want to dump. These are the arguments of our command. The user, skip-missing and f are options. Note that for arguments the order in which they are specified matters, but for the options it does not, also short one letter options can be referenced with a single - instead of two.

Let's look at defining options:

When defining arguments you have to keep in mind that they should be defined in the same order in which they should be specified. In out case this means we have to define a database argument before the tables one:

If we were to run the help command now, we would see the following:

When the command is executed the run method of the command receives the passed options and arguments, which can be accessed in the same way as when working with HTTP requests:

Input and Output

The easiest way to return output from the command is by returning a string. But some commands take a while to process and you may want to provide users with intermediate status. There are some additional methods you can use:

To further control input and out you can use the CLI context, in fact the above methods are just shortcuts to CLI context calls:

The exit code matters for if you want to check externally if the command was successful or not, e.g. in Bash if you do something like:


All versions of console with dependencies

PHP Build Version
Package Version
Requires phpixie/slice Version ~3.0
phpixie/cli Version ~3.1
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 phpixie/console contains the following files

Loading the files please wait ....