Coder Social home page Coder Social logo

consoleserviceprovider's Introduction

DEPRECATED

Unfortunately we decided to not maintain this project anymore (see why). If you want to mark another package as a replacement for this one please send an email to [email protected].

ConsoleServiceProvider

Provides a Symfony\Component\Console based console for Silex 2.x.

Installation

Add knplabs/console-service-provider to your composer.json and register the service provider:

composer require knplabs/console-service-provider
use Knp\Provider\ConsoleServiceProvider;

$app->register(new ConsoleServiceProvider());

You can now copy the console executable from the bin folder to whatever place you see fit, and tweak it to your needs.

You will need a way to fetch your silex application, the most common way is to return it from your bootstrap file:

use Knp\Provider\ConsoleServiceProvider;
use Silex\Application;

$app = new Application();

$app->register(new ConsoleServiceProvider());
$app->register(new SomeOtherServiceProvider());

return $app;

For the rest of this documentation, we will assume you do have a bin directory, so the console executable will be located at bin/console.

Usage

Use the console just like any Symfony\Component\Console based console:

$ bin/console my:command

or on Windows:

$ php bin/console my:command

Configuration parameters

Parameter Default Description
console.name (string) Silex console Name of your console application
console.version (string) UNKNOWN Version of your console application
console.project_directory (string) (auto-detected) Your project's directory path. The default value should work, assuming the provider is installed in vendor/knplabs/console-service-provider
console.class (string) Knp\Console\Application Class name of the console service
console.boot_in_constructor (bool) false Whether the console should boot Silex when loaded (set it to true if you depend on a bug that was fixed in 2.1)
console.command.ids (array) array() Console commands registered as services

Default commands

The service provider will register the following commands if the corresponding Symfony components are installed:

  • From symfony/twig-bridge, the lint:twig and debug:twig commands
  • From symfony/yaml, the lint:yaml command

Web-server-bundle support

The WebServerServiceProvider will register the commands provided by symfony/web-server-bundle.

$app = new Silex\Application();

$app->register(new Knp\Provider\ConsoleServiceProvider());
$app->register(new Knp\Provider\WebServerServiceProvider(), array(
    // Folder that contains your front controller/public files
    'web_server.document_root' => __DIR__.'/../public',
));

The server commands expect your front controller to be located in your document root and be called app_dev.php, app.php, index_dev.php or index.php.

For more information, please consult the Symfony documentation.

Recipes

consoleserviceprovider's People

Contributors

batwolf avatar crimsonlabs avatar flip111 avatar ovr avatar pedrotroller avatar rybakit avatar skalpa avatar tigr avatar ubermuda avatar weaverryan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

consoleserviceprovider's Issues

Lack call to terminate() method

The console application lacks the call to the terminate() method.

Something like ๐Ÿ‘

terminate(Request::createFromGlobals(), Response::create());

the terminate methode trogger the event dispather wich is used by many component like swift mailer (ie to spool mail queue).

calling add() function on a non object

the following is my console code, but when I try to run this code I'm getting the error that $application is non-object. I tried in many other ways but same issue, Tried to dump $application giving me a knp command object. Please tell me whats wrong with my code.

!/usr/bin/env php

add(new x()); $application->run();

Symfony 3 support?

AFAIK, there are no incompatible API changes related to ConsoleServiceProvider in symfony/console v. 3. So, maybe just change "~2.1" in composer.json to ">2.1"?

Add tag version

Is it possible to have a tagged version to avoid depending on dev-master in our composer.json file?

Thanks a lot

Support newer symfony/console releases

Right now this project only supports symfony/console 2.1.*. Would be nice to see it support 2.3.*@. I'll send it a pull request if I get time.

Cheers.

Tag minor version

Hi,

I use Symfony 3.4 and the pull request #40 solve a bug. I prefer do not have an @dev in the composer.json before send new version into production.

Can you release a new minor version? Please.

Thanks in advance and thanks for this good library.

ServiceProviderInterface

When using silex 2.0 and registering the ConsoleServiceProvider I get the following error: "Interface 'Silex\ServiceProviderInterface' not found in /vagrant/vendor/knplabs/console-service-provider/Knp/Provider/ConsoleServiceProvider.php on line 13"

Upon further investigation it seems the providers are using the Pimple/ServiceProviderInterface and the Silex/ServiceProviderInterface class does not exist.

Is there something I am missing or is this an update that needs to be done due to updates in the silex framework?

Maintainer

Good Day, I am interested in maintaining this product. Please assist?

Is there a way to force a command to autorun?

I have a script using the ConsoleServiceProvider and I want it to auto run a command when I run it.

$app->register(new ConsoleServiceProvider(),
                array('console.name'              => 'ScanJobs',
                      'console.version'           => '1.0.0',
                      'console.project_directory' => __DIR__.'/..'));
$application = $app['console'];
$x = new ScanJobsCommand();
$x->addGeocodeer(new Geocode());
$application->add($x);
$application->run();

When run is called, I want it to execute a specific command. Is there a way to do this? right now I call the script with a parameter and it works fine. I just want to eliminate the parameter.

=C=

The command defined in "Knp\Command\Twig\DebugCommand" cannot have an empty name. in /var/www/yourist/vendor/symfony/console/Application.php:450

PHP Fatal error:  Uncaught Symfony\Component\Console\Exception\LogicException: The command defined in "Knp\Command\Twig\DebugCommand" cannot have an empty name. in /var/www/yourist/vendor/symfony/console/Application.php:450
Stack trace:
#0 /var/www/yourist/vendor/knplabs/console-service-provider/Knp/Provider/ConsoleServiceProvider.php(49): Symfony\Component\Console\Application->add(Object(Knp\Command\Twig\DebugCommand))
#1 /var/www/yourist/vendor/pimple/pimple/src/Pimple/Container.php(118): Knp\Provider\ConsoleServiceProvider->Knp\Provider\{closure}(Object(Silex\Application))
#2 /var/www/yourist/app/bootstrap/bootstrap-cli.php(36): Pimple\Container->offsetGet('console')
#3 /var/www/yourist/bin/run(11): require('/var/www/youris...')
#4 {main}
  thrown in /var/www/yourist/vendor/symfony/console/Application.php on line 450

I have such an issue, when i run composer update

Console application boots Silex application

ConsoleServiceProvider must be registered last, because it boots silex application providers.

I want to use \Kurl\Silex\Provider\DoctrineMigrationsProvider for migrations. This provider require Console application, so i add it:

<?php
$app->register(new ConsoleServiceProvider(), array(
    'console.name'              => 'app',
    'console.version'           => '1.0.0',
    'console.project_directory' => __DIR__
));

// at this moment all previders registered in silex app are booted

$app->register(
    new \Kurl\Silex\Provider\DoctrineMigrationsProvider($app['console']),
    array(
        'migrations.directory'  => __DIR__ . '/../migrations',
        'migrations.name'       => 'app',
        'migrations.namespace'  => 'App\Migrations',
        'migrations.table_name' => 'migrations',
    )
);

// at this moment to late to register anything. Application already booted

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.