Archive for the Category ◊ Symfony ◊

Author:
Thursday, March 24th, 2011

In symfony framework, we can generate WSDL files easily by using ckwebservice plugin.
There are different releases available in this plugin. We need to choose the release which suits for our symfony version.
To install this plugin type the following command

php symfony plugin:install ckWebServicePlugin

To use this plugin, we need to make changes in our application’s configuration files also.

1. In app.yml
all:
enable_soap_parameter: off
soap:
# enable the `ckSoapParameterFilter`
enable_soap_parameter: on
ck_web_service_plugin:
# the location of your wsdl file, relative to your project's `web/` folder
wsdl: %SF_WEB_DIR%/Billing.wsdl
# the class which will be registered as handler for webservice requests
handler: BillingHandler
soap_options:
encoding: utf-8
soap_version: <?php echoln(SOAP_1_2) ?>
classmap:
# mapping of wsdl types to PHP types
DoubleArray: ckGenericArray

Note : Billing.wsdl and BillingHandler is our WSDL and Handler names respectively.

2. In factories.yml
# your environment for webservice mode
soap:
controller:
class: ckWebServiceController

3. In filters.yml (only Symfony 1.3 or later versions)

rendering: ~
security:  ~
# insert your own filters here
cache:     ~
common:    ~
execution: ~
soap_parameter:
class: ckSoapParameterFilter
param:
# `app_enable_soap_parameter` has to be set to `on` so the filter is only enabled in soap mode
condition: %APP_ENABLE_SOAP_PARAMETER%

In symfony 1.2 or less versions filters.yml should look like this:

rendering: ~
security:  ~
# insert your own filters here
soap_parameter:
class: ckSoapParameterFilter
param:
# `app_enable_soap_parameter` has to be set to `on` so the filter is only enabled in soap mode
condition: %APP_ENABLE_SOAP_PARAMETER%
cache:     ~
common:    ~
execution: ~

Now we are ready to use this plugin. Once our action file is ready we can generate WSDL file by using ‘webservice:generate-wsdl’ command. Syntax of this command is

php symfony webservice:generate-wsdl [--environment=soap] [--debug] [--handler] app_name webservice_name  webservice_base_url

  • [--environment=soap] – (Optional) This sets the environment to webservice mode. Default value is ‘soap’
  • [--debug]  – (Optional) This enables the debug mode. Default is ‘FALSE’
  • [--handler] – (Optional) This generates custom SOAP handler by extending ckSoapHandler. Default is ‘FALSE’
  • app_name – Name of the application
  • webservice_name – Name of the webservice
  • webservice_base_url – URL under which webservice is accessable

For example :
php symfony webservice:generate-wsdl frontend Billing http://localhost:8080/

The above command will generate Billling.wsdl and BillingHandler.php in ‘web/’ folder
To view the generated WSDL file : http://localhost:8080/Billing.wsdl

Author:
Thursday, January 20th, 2011
analyze your source code according to the following quality axes :
Respect of coding rules violations
Density of documented API
Density of duplicated Code
Level of code coverage by Unit Tests
Density of potential bugs
Complexity distribution

Sonar analyzes your source code according to the following quality axes :

Respect of coding rules violations

Density of documented API

Density of duplicated Code

Level of code coverage by Unit Tests

Density of potential bugs

Complexity distribution

Sonar drives many tools including among others :

  • Static analysis : Checkstyle, PMD/CPD, Findbugs, JavaNCSS.
  • Dynamic analysis for unit tests : Cobertura, Clover, Surefire.

Sonar Requirements

Sonar runs on any operating system that supports Java and Maven. Those two pieces of software need to be installed first:

Sonar requires a relational database for storage of measures data. Sonar supports :

  • It is recommended to create an UTF-8 database named ‘sonar’ accessed by specific user ‘sonar’. Here is an example with MySQL:

mysql> CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;

mysql> grant all privileges on sonar.\* to ‘sonar’@'localhost’ identified by ‘\[your password\]‘;

mysql> flush privileges;

Sonar Installations

  • Download and Unzip the distribution
  • Execute on windows

bin\windows-x86-32\StartSonar.bat

  • If you do not use the default embedded database, edit conf/sonar.properties to configure the database access. Templates are available for every supported database. Just uncomment them and comment the first four lines dedicated to derby.

* sonar.jdbc.url : the URL of the database

* sonar.jdbc.driver : the class of the driver

* sonar.jdbc.user : the username (default is ‘sonar’)

* sonar.jdbc.password : the password (default is ‘sonar’)

Example for MySQL :

#sonar.jdbc.url: jdbc:derby://localhost:1527/sonar;create=true

#sonar.jdbc.driver: org.apache.derby.jdbc.ClientDriver

#sonar.jdbc.defaultTransactionIsolation: 1

#sonar.jdbc.validationQuery: values(1)

sonar.jdbc.url: jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8

sonar.jdbc.driver: com.mysql.jdbc.Driver

sonar.jdbc.validationQuery: select 1

Install and Configure Sonar plugin on Hudson

Click on Manage Hudson – Manage Plugins. Click now on the Available tab, you should see the Hudson Sonar Plugin. Check this plugin and click on the Install button at the far right hand corner.

Restart Hudson and you should be able to see the plugin in the Installed tab as shown below:

Image 1

Next, configure the Sonar plugin from within Manage Hudson -> Configure System. I am using the default database, and so didn’t make any changes here. However, if you are using a different database server, you need to provide the database URL, username, password and so on as shown below.

sonar_2

more…

Author:
Tuesday, February 23rd, 2010

Steps for setting up error reporting in Symfony

You can set up the Error Reporting Level, in myapp/config/settings.yml

prod:

.settings:

error_reporting:  257

dev:

.settings:

error_reporting:  4095

4095 is a shortcut for E_ALL | E_STRICT

257 stands for E_ERROR | E_USER_ERROR (the default value for every new environment)

Symfony can log a lot of custom events. You can find all the symfony logs under the myproject/log/ directory

There are eight levels of symfony log messages: emerg, alert, crit, err, warning, notice, info, and debug. You can configure the maximum level to be logged in each environment in the logging.yml

Default Logging Configuration, in myapp/config/logging.yml

prod:
  enabled: off
  level:   err
  rotate:  on
  purge:   off
 dev:
 test:
 #all:
#  enabled:  on
#  level:    debug
#  rotate:   off
#  period:   7
#  history:  10
#  purge:    on

You can manually add a message in the symfony log file from your code by using one of the techniques described below

// From an action
$this->logMessage($message, $level);
// From a template
<?php use_helper('Debug') ?>
<?php log_message($message, $level) ?>

For clearing the log use the below command.

symfony log-purge
Category: PHP, Symfony | Tags: , ,  | One Comment
Author:
Friday, January 29th, 2010

While working on symfony framework we faced some issues and in this blog I am going to discuss about the issues and fixes for that issues.

Problem 1 :

symfony 1.2 propel-build-model Bus error

(Crashes PHP CLI when we try to execute

symfony propel-build-model or

symfony propel-build-all

)
Solution :

Execute €˜symfony propel-build-model’ ends with ‘Bus error’

I found this is caused by one field type in db with default value:

I have a column called €˜created_at’of type: timestamp with default value ‘CURRENT_TIMESTAMP’, this is on MYSQL level.

Execute €˜propel-build-schema’ at symfony command line

you will get

created_at: { type: TIMESTAMP, required: true, defaultValue: CURRENT_TIMESTAMP } then, run ‘propel-build-model’, you would get ‘Bus error’

propel generator might not know ‘CURRENT_TIMESTAMP’. After removing this from scheme.yml, you can run that script smoothly.

Problem 2 :

When we tried to host the symfony project which we developed to Linux server, it displayed blank page.

Solution :

It’s because of the case sensitivity of filenames.

Ex: we have a file Test.php, in windows if we include test.php it will work but in Linux it will fail because of case sensitivity.

Author:
Monday, December 14th, 2009

What’s Symfony?
Symfony is a web application MVC framework for PHP projects. It aims to speed up the creation and maintenance of web applications, and to replace the repetitive coding tasks.

Why use an MVC framework?

  • Avoid €œreinventing the wheel€
  • Use proven, tested code
  • Speed up application development
  • Easy to maintain
  • Code cleanliness
  • Structured the code

Why Symfony?

  • Supports complex web applications
  • Idea adopted from existing framework (Mojavi, Prado, rails, Django)
  • Clean MVC Seperation
  • Configurability, Flexibility
  • Write less code
  • Support Unit testing and functional testing

Database Support

  • Mysql, PostgreSQL, Oracle
  • Object Role Modeling (ORM)
  • Propel as default
  • It doesn’t require extrenal ORM

The Symfony supports most of the databases and the beauty of framework is that we can change the database at any stage of development. Since the database is different layer it won’t affect the other layer of the code.

Speed & Performance

  • Cache configuration
  • Caching on page, function , query
  • Disable / enable plugins, databases, modules

Other Features

  • Easy to Manage Template
  • SEO Friendly link/ url
  • Friendly logging
  • Assessment on loading time

Plugins and helper

  • Ajax enabled plugins
  • jQuery, dojo, extjs, yui
  • Create your own plugin and reuse
  • Autocomplete
  • Drag and drop
Famous Applications
Yahoo! answer
Yahoo! bookmark
delcious
Daily Motion
etc…

Famous Applications using Symfony Framework

Yahoo! answer

Yahoo! bookmark

delcious

Daily Motion

etc…