ssa/ssa-bundle

This package is abandoned and no longer maintained. No replacement package was suggested.
There is no license information available for the latest version (v1.0.1) of this package.

ssa bundle for use ssa framework into Symfony

Installs: 34

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:symfony-bundle

v1.0.1 2014-09-06 19:11 UTC

This package is not auto-updated.

Last update: 2022-08-01 16:47:07 UTC


README

Ssa is a framework for access to your php service in your javascript code. This project is the ssa integration on symfony 2. Ssa project

Installation

Ssa bundle installation is very simple, you need just to add composer dependency.

composer.json

"require": {
  "ssa/ssa-bundle" : "dev-master",
}

If composer say "ssa/core" not found add this line in your composer file : composer.json

"require": {
  "ssa/core" : "dev-master",
}

Add the bundle in your kernel :

new Ssa\SsaBundle\SsaBundle()

Add the ssa routing in your routing.yml

routing.yml

_ssa:
    resource: "@SsaBundle/Resources/config/routing.yml"

After you can register your services into config.yml

config.yml

ssa :
    services :
        # serviceName is the ssa service name
        # service : is the symfony serivce
        serviceName : {service : 'ssa.test.service'}
        # or you can just export any methods of this service
        serviceName2 : {service : 'ssa.test.service', methods : ['methodToImport']}
        # if your service is not a symfony service you can use the class attribute
        serviceName3 : {class : '\Path\To\Your\Class', methods : ['methodToImport']}      

And you can Simply import the javascript service with assetic, like this :

file.html.twig

{% javascripts 
    'ssa:serviceName'
    'ssa:serviceName1'
    'ssa:serviceName2'
%}
<script type="text/javascript" src="{{asset_url }}"></script>
{% endjavascripts  %}
    

you can now simply call your php service into your javascript file :

serviceName1
    .methodToImport('param1', {objectProp : 'ObjectValue', objectProp2 : 'ObjectValue2'})
    .done(function(data){
        console.log(data);
    });

Support

Ssa allow to call php service into javascript code. Ssa in symfony add a parameter resolver. It can convert json oject into your doctrine entity. Example : Entity

Product :
  - id
  - name
  - price
  

Database

Id | Name | Price

1 | Foo | 10.0

ProductService.php

class ProductService {
    private $em;
    
    public function __construct(EntityManagerInterface $em) {
        $this->em = $em;
    }
    
    public function getProduct(Product $p) {
        return $p;
    }

    public function updateProduct(Product $p) {
        $this->em->persist($p);
        $this->em->flush();
        return $p;
    }
}

Javascript call :

productService.getProduct({id : 1}).done(function(data){
  // data.id = 1
  // data.name = "Foo"
  // data.price = 10.0
});

productService.updateProduct({name : 'Bar', price : 15}).done(function(data){
  // data.id = AutoGenerated value
  // data.name = 'Bar'
  // data.price = 15
});

productService.updateProduct({id : 1, price : 11.5}).done(function(data){
  // data.id = 1
  // data.name = 'Foo'
  // data.price = 11.5
});

customization

You can customize the framework with you own classes or change parameters.

Parameters

You can change any parameters on config.yml

config.yml

ssa :
    configuration :
        # the debug configuration, default is the symfony configuration
        debug : true | false
        # the cache configuration, by default there are no cache, the cachemode is not mandatory with symfony
        cacheMode : file | apc | memcache
        # the cache directory if cacheMode is file. default it's the kernel.cache_dir
        cacheDirectory : 
        # the host for memcache cacheMode
        memcacheHost :
        # the port for memcache cacheMode
        memcachePort :
        # path to ssa js file, if you have your own ssa js implementation. Path begin in web directory
        ssaJsFile :

You can add your own resolver, if you want use specific resolver for your own class : Ssa documentation

config.yml

ssa :
    parameterResolver :
        primitive :
            - YourFirstPrimitiveResolver
            - YoutSecondPrimitiveResolver
        object :
            - YourFirstObjectResolver
            - YourSecondObjectResolver

Implementation

You can change ssa implementation, add ssa parameters resolver, change route generator.

Route manager

Routes are use for generate url to call php services, by default the ssa_run_service route is used. You have two way for change route generation. The first is to change the route name used :

service.yml

parameters :
    ssa.runner.route : 'your_own_ssa_route_name'

Or you can completly change the class use for generate route, your class must implements ssa\converter\UrlFactory interface, your constructor must have two parameters Symfony\Component\Routing\RouterInterface $router and $routeName. For change the class used you must change the ssa.urlFactory.class parameter :

service.yml

parameters :
    ssa.runner.route : Your\Own\UrlFactory
Parameter resolver

If you want use your own parameter resolver, you can set the class used. the parameter resolver is used for convert get or post parameter in php object. Your parameter resolver need to extends ssa\runner\resolver\impl\DefaultParameterResolver or implements ssa\runner\resolver\ParameterResolver. Your must change the parameter ssa.parameterResolver.class for use your own parameterResolver.

service.yml

parameters :
    ssa.parameterResolver.class : Your\own\resolver