PHP
  Home arrow PHP arrow Page 3 - Building a Complete Web Searching Class with Yahoo Web Services and PHP 5
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PHP

Building a Complete Web Searching Class with Yahoo Web Services and PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 3
    2008-02-20


    Table of Contents:
  • Building a Complete Web Searching Class with Yahoo Web Services and PHP 5
  • Defining an image searching class in PHP 5
  • Using Inheritance to work with different Yahoo! Web Services
  • Consuming specific Yahoo! Web Search Services

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Building a Complete Web Searching Class with Yahoo Web Services and PHP 5 - Using Inheritance to work with different Yahoo! Web Services
    ( Page 3 of 4 )

    Since the web service classes that you learned before are very similar to each other, it's preferable to take a more efficient approach and build a base class that encapsulates as much common functionality as possible. Next, derive some subclasses that implement (or eventually) override some of the parent's method in order to use a specific Yahoo! Web Service.

    Of course, to do so I have to appeal to Inheritance, but first let me show you the signature of this base web searching class. It is as follows:


    // define abstract 'SearchService' class


    abstract class SearchService{

    protected $requestPath;

    protected $query;

    protected $numResults;

    protected $output;

    public function __construct(){

    $this->query='madonna';

    $this->numResults=10;

    $this->output='';

    }

    // set search query

    public function setQuery($query){

    if(!$query){

    throw new Exception('Invalid search query!');

    }

    $this->query=urlencode($query);

    }

    // set number of search results

    public function setNumResults($numResults){

    if(!$numResults||!is_int($numResults)||$numResults>50){

    throw new Exception('Invalid number of results!');

    }

    $this->numResults=$numResults;

    }

    // define a generic method to perform web search and get search results

    public function getSearchResults(){}

    }


    As you can see, in this case I simply defined the previous "SearchService" class abstract, since I don't want it to be instantiated later on. However, this class also defines one generic "getSearchResults()" method (aside from the corresponding constructor, of course), which needs to be implemented in a concrete way by all the subclasses derived from this parent to use a specific Yahoo! Web Search Service.

    Defining the previous classes this way permits us to build some child classes, which will be responsible for consuming a concrete Yahoo! Web service. Undoubtedly, this is a clear example of how useful Inheritance can be in a real-world situation.

    All in all, at this point I'm pretty sure that you understand how the prior "SearchService" class was built, so it's an appropriate moment to learn how the respective subclasses will be derived from this parent.

    Indeed, this process will be quite interesting, so to learn more, please click on the link below and read the following section.



     
     
    >>> More PHP Articles          >>> More By Alejandro Gervasio
     

       

    PHP ARTICLES

    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek