dev-master
9999999-dev https://github.com/javijalis/JalisServiceGeneratorBundle.gitSymfony2 Bundle for create services by command line
MIT
The Requires
- php >=5.3.2
- symfony/framework-bundle >=2.0.0
service dependency injection symfony2 generator
Wallogit.com
2017 © Pedro Peláez
Symfony2 Bundle for create services by command line
This package contains a bundle to easily create basic services efficiently and without effort from command line., (*1)
The package add a new command line app/console generate:service that create all the config and code for a basic service:, (*2)
Installation depends on your version of Symfony:, (*3)
Composer is a project dependency manager for PHP. You have to list
your dependencies in a composer.json file:, (*4)
``` json { "require-dev": { "jalis/service-generator": "dev-master" } }, (*5)
To actually install Service Generator in your project, download the composer binary and run it: ``` bash wget http://getcomposer.org/composer.phar # or curl -O http://getcomposer.org/composer.phar php composer.phar install
bin/vendors.php methodIf you're using the bin/vendors.php method to manage your vendor libraries,
add the following entries to the deps in the root of your project file:, (*6)
[JalisServiceGeneratorBundle]
git=https://github.com/javijalis/JalisServiceGeneratorBundle.git
target=/bundles/Jalis/Bundle/ServiceGeneratorBundle
Next, update your vendors by running:, (*7)
``` bash $ ./bin/vendors, (*8)
Finally, add the following entries to your autoloader: ``` php <?php // app/autoload.php $loader->registerNamespaces(array( // ... 'Jalis' => __DIR__.'/../vendor/bundles', ));
Finally, enable the bundle in the kernel:, (*9)
``` php <?php // app/AppKernel.php, (*10)
public function registerBundles() { $bundles = array( // ... new Jalis\Bundle\ServiceGeneratorBundle\JalisServiceGeneratorBundle(), ); }, (*11)
## How to use: Execute the command: ``` php $ app/console generate:service
Follow the instructions:, (*12)
``` php Your service code must be written in Manager directory. This command helps you generate them easily., (*13)
Each service is hosted under a namespace (like Acme/Bundle/BlogBundle). (which must have Bundle as a suffix)., (*14)
Bundle namespace: myFolder/Bundle/myBundle, (*15)
Your service must have a name for call it, (*16)
Service Name: example, (*17)
Your service need EntityManager?, (*18)
Do you need entity Manager in your service [no]? yes, (*19)
After that, you only have to use the service where ever you want:
``` php
$my_service = $this->get('exampleManager');
The class for your code used in the service is in the folder BundleGiven/Manager/exampleManager.php ``` php <?php namespace BundleGiven\Manager;, (*20)
use Doctrine\ORM\EntityManager;, (*21)
class exampleManager
{
protected $em;, (*22)
public function __construct(EntityManager $em){
$this->em = $em;
}
public function getInfo() {
return "name: exampleManager";
}
//... your code
}
```, (*23)
Symfony2 Bundle for create services by command line
MIT
service dependency injection symfony2 generator