PHP
  Home arrow PHP arrow Page 3 - Building a Complete Web Searching Clas...
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
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? 
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: 5 stars5 stars5 stars5 stars5 stars / 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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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

    Dell PowerEdge Servers

    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


       · Over the course of this last episode of the series, you’ll learn how to build some...
     

       

    PHP ARTICLES

    - Setting Up a Web-based Image Hosting Service
    - Comparing Files and Databases with PHP Bench...
    - Setting Up a Web-Based Image Gallery
    - Using Timers to Benchmark PHP Applications
    - Benchmarking Applications with PHP
    - Setting Up a Web-Based File Manager: PHPfile...
    - Developing a Modular Class For a PHP File Up...
    - Setting Up a Web-Based File Manager: bfExplo...
    - Defining a Custom Function for File Uploader...
    - Parsing Child Nodes with the DOM XML extensi...
    - Creating an Error Handling Module for a PHP ...
    - Accessing Attributes and Cloning Nodes with ...
    - Retrieving Information on Selected Files wit...
    - Handling HTML Strings and Files with the DOM...
    - Building File Uploaders with PHP 5

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway