Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 614287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:05:45+00:00 2026-05-13T18:05:45+00:00

Basically I have a class that sends a SOAP request for room information receives

  • 0

Basically I have a class that sends a SOAP request for room information receives a response, it can only handle one room at a time.. eg:

class roomParser {
    private $numRooms;
    private $adults;
    private $dailyPrice;

    public function parse(){}
    public function send(){}

};

$room = new roomParser( $arrival, $departue );
$return = $room->parse();

if ( $return ) { }

Now I have the dilemma of basically supporting multiple rooms, and for each room I have to separately keep information of the dailyPrice, # of adults, so I have to sessionize each rooms information since its a multiple step form..

Should I just create multiple instances of my object, or somehow modify my class so it supports any # of rooms in a rooms array, and in the rooms array it contains properties for each room?

Edit #1: After taking advice I tried implementing the Command pattern:

<?php

interface Parseable {

    public function parse( $arr, $dept );
}

class Room implements Parseable {

    protected $_adults;
    protected $_kids;
    protected $_startDate;
    protected $_endDate;
    protected $_hotelCode;
    protected $_sessionNs;
    protected $_minRate;
    protected $_maxRate;
    protected $_groupCode;
    protected $_rateCode;
    protected $_promoCode;
    protected $_confCode;
    protected $_currency = 'USD';
    protected $_soapAction;
    protected $_soapHeaders;
    protected $_soapServer;
    protected $_responseXml;
    protected $_requestXml;

    public function __construct( $startdate,$enddate,$rooms=1,$adults=2,$kids=0 ) {
        $this->setNamespace(SESSION_NAME);
        $this->verifyDates( $startdate, $enddate );

        $this->_rooms= $rooms;
        $this->_adults= $adults;
        $this->_kids= $kids;

        $this->setSoapAction();
        $this->setRates();
    }

    public function parse( $arr, $dept ) {
        $this->_price = $arr * $dept * rand();
        return $this;
    }

    public function setNamespace( $namespace ) {
        $this->_sessionNs = $namespace;
    }

    private function verifyDates( $startdate, $enddate ) {}

    public function setSoapAction( $str= 'CheckAvailability' ) {
        $this->_soapAction = $str;
    }

    public function setRates( $rates='' ) { }

    private function getSoapHeader() {
        return '<?xml version="1.0" encoding="utf-8"?>
            <soap:Header>
            </soap:Header>';
    }

    private function getSoapFooter() {
        return '</soap:Envelope>';
    }

    private function getSource() {
        return '<POS>
            <Source><RequestorId ID="" ID_Context="" /></Source>
            </POS>';
    }

    function requestXml() {
        $this->_requestXml  = $this->getSoapHeader();
        $this->_requestXml .='<soap:Body></soap:Body>';
        return $this->_requestXml;
    }

    private function setSoapHeaders ($contentLength) {
        $this->_soapHeaders = array('POST /url HTTP/1.1',
            'Host: '.SOAP_HOST,
            'Content-Type: text/xml; charset=utf-8',
            'Content-Length: '.$contentLength);
    }
}

class RoomParser extends SplObjectStorage {

    public function attach( Parseable $obj ) {
        parent::attach( $obj );
    }

    public function parseRooms( $arr, $dept ) {
        for ( $this->rewind(); $this->valid(); $this->next() ) {
            $ret = $this->current()->parse( $arr, $dept );
            echo $ret->getPrice(), PHP_EOL;
        }
    }
}

$arrive = '12/28/2010';
$depart = '01/02/2011';
$rooms = new RoomParser( $arrive, $depart);
$rooms->attach( new Room( '12/28/2010', '01/02/2011') );
$rooms->attach( new Room( '12/29/2010', '01/04/2011') );
echo $rooms->count(), ' Rooms', PHP_EOL;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:05:45+00:00Added an answer on May 13, 2026 at 6:05 pm

    Given from the information in the question, I’d probably use a Command Pattern

    All Rooms should implement a parse() command

    interface Parseable
    {
        public function parse($arr, $dept);
    }
    

    A room instance could look like this

    class Room implements Parseable
    {
        protected $_price;
        protected $_adults;
        public function parse($arr, $dept) {
             // nonsense calculation, exchange with your parse logic
            $this->_price = $arr * $dept * rand();
            return $this;
        }
        public function getPrice()
        {
            return $this->_price;
        }
    }
    

    To go through them, I’d add them to an Invoker that stores all rooms and knows how to invoke their parse() method and also knows what to do with the return from parse(), if necessary

    class RoomParser extends SplObjectStorage
    {
        // makes sure we only have objects implementing parse() in store      
        public function attach(Parseable $obj)
        {
            parent::attach($obj);
        }
    
        // invoking all parse() methods in Rooms
        public function parseRooms($arr, $dept)
        {
            for($this->rewind(); $this->valid(); $this->next()) {
                $ret = $this->current()->parse($arr, $dept);
                // do something with $ret
                echo $ret->getPrice(), PHP_EOL;
            }
        }
        // other methods
    }
    

    And then you could use it like this:

    $parser = new RoomParser;
    $parser->attach(new Room);
    $parser->attach(new Room);
    $parser->attach(new Room);
    $parser->attach(new Room);
    echo $parser->count(), ' Rooms', PHP_EOL;
    
    $parser->parseRooms(1,2);
    

    Note that the Invoker extends SplObjectStorage, so it implements Countable, Iterator, Traversable, Serializable and ArrayAccess.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.