Download the PHP package box-project/console without Composer

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

Build Status Latest Stable Version Latest Unstable Version Total Downloads

Console

composer require box-project/console

Console simplifies the process of building a command line application using the dependency injection design pattern. Input and output management is already handled for you. You simply need to create your commands and register each as a service.

Requirements

Suggested

Getting Started

You need to be familiar with some of the third-party libraries that are used by Console in order to be able to make sense of anything. These libraries come from Symfony, an open source web application framework. For your convenience, the documentation for the most relevant libraries are linked below.

Creating an Application

Before a new application can be created, a dependency injection container will be needed. While any instance of ContainerInterface may be used, we will be using an instance of ContainerBuilder (more detail on why later).

With the container, a new Application instance can now be created.

When an instance of ContainerBuilder is provided to Application, it will automatically set parameters and register services needed to run the console application. Application will not set parameters or register services that already exist. It is important to note that only instances of ContainerBuilder will cause Application to set the default parameters and register the default services.

Running an Application

Before we can begin process of running the console, the container must first be compiled. Compiling the container allows for some last minute processes to occur.

With the compiled container, the application is ready to run.

When the code in the examples above are run from a script in the command line, the following output will be shown. It may be important to note that the output may vary slightly depending on the age of the documentation and what libraries were installed in addition to Console.

Using the Container

Application is designed around the use of the container. All functionality that is provided by Console can be found as a parameter or service within the container. As a result, all changes to the console (adding commands, adding helpers, changing defaults, etc) must also occur through the container.

Loading Resources

In order to make changes to the container, the loaders provided by the DependencyInjection library must be used. More information about how to use the DI loaders can be found on Symfony's website. While you may use any compatible loader, Console will only officially support XML and YAML for file-based loading. PHP is also supported, but not in conjunction with the bundled commands or loaders.

Loading .dist Files

In addition to the standard loaders, Console provides its own loader for special cases. Many applications make use of files that end with .dist. This file extension is used to indicate that the file is part of the distribution. A user may then make a copy of the file, drop the .dist extension, and use their version of the file with their software.

The following example will support the loading of XML and YAML files, with or without the .dist file extension.

As the name implies, the ResourceCollection class manages a collection of Resource instances. Because of how the standard file loaders behave when determining support for files, ResourceSupport is used to map an unsupported file extension (e.g. .yml.dist) a supported one (e.g. .yml). The loader, ResourceCollectionLoader, will then iterate through the collection attempting load each resource until one is successfully loaded. If the first resource in the collection fails to load due to it not existing, the next will be attempted. This iteration will continue until the list is exhausted, or an error is found while processing an available resource.

In the example above, an exception is thrown if none of the resources in the collection exist. To optionally load a resource, without having an exception thrown, the loadOptional() method should be used.

Registering Commands

To register a command, you must tag its service with "box.console.command".

In PHP

In XML

In YAML

Registering Helpers

To register a command, you must tag its service with "box.console.helper".

In PHP

In XML

In YAML

Registering Event Listeners and Subscribers

The EventDispatcher library supports the registration of listeners, or a collection of listeners through what is known as a "subscriber". A listener is a single callable, while a subscriber is a class that returns a list of which methods must be called when specific events a dispatched.

Listeners

In PHP
In XML
In YAML

Subscribers

In PHP
In XML
In YAML

Registering Extensions

Extensions provide another way of setting parameters and setting service definitions for the container. However, in order make those extensions available to the container helper so that the bundled commands still work, registration must be done through the registerExtension() method.

This will create a tagged service definition in the container builder, in addition to register the extension with the container. This will allow the helper to re-register the same extension when a new container builder is created for the bundled commands.

The Defaults

As mentioned early in Getting Started, when a ContainerBuilder instance is passed to Application, a set of default parameters and services are set within the container. The following is a list of those parameters and services.

Parameters

Name (Default Value) Description
box.console.auto_exit
(true)
If true, exit() is called once a command finishes.
box.console.class
(Symfony\Component\Console\Application)
The class for the console application.
box.console.command.*.class
(Instances of Symfony\Component\Console\Command\Command)
The class for each default command.
box.console.event_dispatcher.class
(Symfony\Component\EventDispatcher\ContainerAwareDispatcher)
The class for the event dispatcher.
box.console.helper.*.class
(Instances of Symfony\Component\Console\Helper\Helper)
The class for each default helper.
box.console.helper.container.class
(Box\Component\Console\Helper\ContainerHelper)
The class a helper that provides access to the container.
box.console.helper_set.class
(Symfony\Component\Console\Helper\HelperSet)
The class for the helper set.
box.console.input.class
(Symfony\Component\Console\Input\ArgvInput)
The class for the default input manager.
box.console.name
(UNKNOWN)
The name of the console application.
box.console.output.class
(Symfony\Component\Console\Output\ConsoleOutput)
The class for the default output manager.
box.console.version
(UNKNOWN)
The version of the console application.

Services

Identifier (Class) Description
box.console
(%box.console.class%)
The console application which contains all commands.
box.console.helper.container
(%box.console.helper.container.class%)
A helper that provides access to the container.
box.console.command.*
(%box.console.command.*.class%)
A command.
box.console.helper.*
(%box.console.helper.*.class%)
A helper.
box.console.event_dispatcher
(%box.console.event_dispatcher.class%)
The event dispatcher.
box.console.helper_set
(%box.console.helper_set.class%)
The helper set which contains all helpers.
box.console.input
(%box.console.input.class%)
The input manager.
box.console.output
(%box.console.output.class%)
The output manager.

Commands

Command Description
config:current Displays the current configuration for an extension registered with the container.
config:list Displays the list of extensions registered with the container.
config:reference Displays the reference configuration for an extension registered with the container.
debug:container Displays the parameters and services in the container. This command is only available if symfony/framework-bundle is installed.

Helpers

Helper Description
container Provides access to the container.

Performance

The processing of building a container can potentially be time consuming and costly in terms of performance. Console provides a way to cache the results of the container building process so that subsequent uses of the application can be faster.

The ApplicationCache::bootstrap() method manages the process of creating, loading, and saving the container. When the application is first run using this method, the following files are created. It is important to note that the name of the generated files will vary depending on what you provided as the first argument to bootstrap().

File Description
example.php The cached container.
example.php.meta The cache metadata, used to determine if the cache needs to be refreshed.
example.xml The container configuration used for debugging.

By default, the name of the cached container class is ConsoleContainer and resides in the root namespace. Also by default, "debugging" is enabled. The debugging option will cause the cache to be refreshed if a resource is updated. By disabling debugging, the cache files must be manually deleted before any of the changes to the resources take effect.

License

This software is released under the MIT license.


All versions of console with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4
kherge/file Version ~1.3
herrera-io/object-storage Version ~1.0
symfony/config Version ~2.5
symfony/console Version ~2.5
symfony/dependency-injection Version ~2.5
symfony/yaml Version ~2.5
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 box-project/console contains the following files

Loading the files please wait ....