Home > SOA Tips > The Web Services Advisor > SCA and SDO for PHP
SOA Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

THE WEB SERVICES ADVISOR

SCA and SDO for PHP


Daniel Rubio
02.06.2007
Rating: -5.00- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


Led by the Open Service Oriented Architecture collaboration group ( OSOA ), Service Component Architecture (SCA) and Service Data Objects (SDO) have become the newest approaches for enabling service-oriented architectures. Initially conceived to operate in the most widely used programming environments for the enterprise -- Java and C++ -- both SCA and SDO have grown to accommodate additional platforms, in the following article we will explore how the popular scripting language PHP has embraced these same SOA techniques.

Lets start by taking a look at what SDO can offer you. In a typical PHP application, data will more than likely come from a relational database, but what happens if this same application later requires accessing information not only from this source, but also from a flat file or Web service? Well, it will be a long process at best or a convoluted task at worst, the reason being is that each data source comes with its own set of quirks for retrieving appropriately.

In this sense, SDO for PHP achieves the touted transparency inherent to SOA when dealing with application data sources. Instead of working with each type of data source individually, SDO offers a unified manner in which to access data objects. The way this process is achieved is through Data Access Service's (DAS), a level of indirection built into the SDO architecture. Take a look at the following listing which illustrates an SDO query in PHP:

Listing 1.1 SDO query in PHP

<?php
  $providers = $company->shippingByGround;
  foreach ($providers as $name => $value) {
     echo "$name: $value\n";
  }
?>

Notice how this last query has the characteristic of being data source agnostic. That is to say, you can't tell were the underlying data is being extracted from, you simply make a search using PHP's SDO syntax and the intricate details are dealt with in the DAS, of which PHP currently supports both XML and relational database sources.

While SDO is focused on data, SCA's intent is on achieving this same transparency, but with more general purpose classes or components. In what would be another typical PHP scenario, accessing existing business logic from any PHP class forces a developer to wrap a design around a particular series of assumptions: Is the logic in another local PHP class? Or is it located across the network? Is it even written in PHP?

While each of the aforementioned scenarios is resolvable in its own right, each one requires different coding techniques.

Using SCA's approach, the location in which such logic is located -- across the network or locally -- should be a moot point, not to mention the implementing language -- PHP, Java or C++ -- would also be irrelevant. This last statement may lead you to ask "Hey, this sounds a lot like a run-of-the-mill Web service, what's the difference ?" Well take a look at listing 1.2 which contains a PHP SCA component.

Listing 1.2 SCA component in PHP

 
<?php

include "SCA/SCA.php";

/**
 * Calculate a shipment price for a given customer using a specific provider
 *
 * @service
 */
class ShipmentQuote {

    /**
     * The customer discount fee service to use.
     *
     * @reference
     * @binding.php ../DiscountFeeRate/DiscountFeeRate.php
     */
    public $discountFee;

    /**
     * The shipping service to use.
     *
     * @reference
     * @binding.wsdl ../Shipper/ShipperQuote.wsdl
     */
    public $shipper;

    /**
     * Get a quote for a given customer using a specific provider
     *
     * @param string $shipping The shipping company 
     * @param string $customer The customer requiring shipment, in order to obtain discount rate
     * @return float The quote for a given customer using a certain shipping provider. 
     */
    function getQuote($shippingCo, $customer)
    {
        $rateShip  = $this->shipper->getShippingPrice($shippingCo);
        $rate   = $this->discountFee->getDiscountRate($customer);
        return  $rate * $rateShip;
    }
}
?>

The most important declarations in the previous listing are those made in @ statements, since each one provides specific SCA behaviors. Topping things off is the @service tag, which is charged with exposing the class in question as a service. In this particular case, the last function by the name of getQuote will be the only operation exposed through the service, something which is achieved using the @param and @return annotations.

The actual execution or deployment of this last service -- which is delegated to a PHP SCA runtime -- will net us an access point capable of producing a WSDL contract, just like you would expect of any Web service. Besides the simplicity in deploying a service in this manner , the real advantage to SCA's model becomes more evident when you inspect the getQuote function code.

Notice the two statements $this-<shipper->getShippingPrice($shippingCo) and $this->discountFee->getDiscountRate($customer), which are based on the earlier references in the class. Each of these references are backed by other underlying services -- thanks to SCA's @reference and @binding annotations -- in the case of $discountFee this would a PHP class and in shipper's case this would be a standard WSDL backed service.

As you can realize, much of the power behind SCA's programming model is the ease with which you can create chained calling sequences of services without tainting the actual business logic, a conclusion you can also probably arrive at by simply removing all the SCA annotations we just described. If you do so, you will be left with plain business logic with no other type of dependencies, a characteristic which is highly beneficial to not only developing services for SOA, but also software in general.

Though PHP's simplicity and ample user community have made it a favorite for building Web applications, until recently, its usage in the enterprise was limited to a handful of scenarios, but with SCA and SDO now supported in PHP and the former technologies appearing on the radar of organizations trying to implement a SOA, honing your PHP skill set may prove to be wise choice, especially now that it will be able to participate on the same service-oriented playing field as the other major enterprise languages.

About the Author

Daniel Rubio is a software consultant with over 10 years of experience in enterprise software development, having recently founded Mashup Soft, a startup specializing in the use Web services for Mashups. He is a technology enthusiast in all areas related to software platforms and maintains a blog on these topics at http://webforefront.com.


Rate this Tip
To rate tips, you must be a member of SearchSOA.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
The Web Services Advisor
Erlang and concurrency in service-orientated architectures
Backup to the compute cloud
SPARQL shines as RDF's query language
Testing Web services: Unit testing and monitoring
Web services for Windows CE
Testing Web services and RIAs
The problem with IT project management
Web services with Open and Microsoft Office
REST with Axis, Struts, ColdFusion and WCF
Cross-site XMLHttpRequest: Boon or Pandora's Box

Emerging SOA standards
What OSGi means to SOA
SOA simplicity by committee?
Apache releases Java SCA
W3C publishes WS-Policy as recommendation
Does Microsoft get SOA?
CTO views SaaS as the ultimate in SOA
SOA 2007: Adoption steady, but tech squabbles exist
SOA development seen as three-way split
Java EE 6 team looks at SOA
Microsoft MIA in SOA standards – analyst

Service Component Architecture (SCA)
Oracle re-brands BEA WebLogic as its strategic server for SOA
Eclipse Ganymede: SOA project adds WS-Policy, SCA tools
Ganymede: Modeling tools target SOA, UML
What OSGi means to SOA
SCA and SDO standards
Eclipse Swordfish SOA runtime mixes SCA, JBI and OSGi
SOA seen as plus for C++
Oracle previews SOA tool
Swordfish may lure SMBs into SOA waters
Paul Fremantle on coding SOA and data integration

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
service-component architecture  (SearchSOA.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.

About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 2001 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts