DataSift\Storyplayer\DeviceLib::getDeviceAdapter PHP Method

getDeviceAdapter() public static method

public static getDeviceAdapter ( DataSift\Stone\ObjectLib\BaseObject $deviceDetails )
$deviceDetails DataSift\Stone\ObjectLib\BaseObject
    public static function getDeviceAdapter($deviceDetails)
    {
        // which namespace do our device adapters live in?
        $namespace = 'DataSift\\Storyplayer\\DeviceLib\\';
        // where do we want to get the device from?
        $adapterClass = $namespace . $deviceDetails->adapter . 'Adapter';
        // do we have the adapter?
        if (!class_exists($adapterClass)) {
            throw new E4xx_NoSuchDeviceAdapter($deviceDetails->adapter);
        }
        // create the adapter
        $deviceAdapter = new $adapterClass();
        // is this an adapter we're happy with?
        if (!$deviceAdapter instanceof \DataSift\Storyplayer\DeviceLib\DeviceAdapter) {
            throw new E5xx_BadDeviceAdapter($adapterClass);
        }
        // initialise the adapter
        $deviceAdapter->init($deviceDetails);
        // all done
        return $deviceAdapter;
    }

Usage Example

Esempio n. 1
0
 /**
  * @return void
  */
 public function startDevice()
 {
     // what are we doing?
     $log = $this->startAction('start the test device');
     // what sort of browser are we starting?
     $deviceDetails = $this->getDeviceDetails();
     // get the adapter
     $adapter = DeviceLib::getDeviceAdapter($deviceDetails);
     // initialise the adapter
     $adapter->init($deviceDetails);
     // start the browser
     $adapter->start($this);
     // remember the adapter
     $this->setDeviceAdapter($adapter);
     // do we have a deviceSetup() phase?
     if (isset($this->story) && $this->story->hasDeviceSetup()) {
         // get the callbacks to call
         $callbacks = $this->story->getDeviceSetup();
         // make the call
         //
         // we do not need to wrap these in a TRY/CATCH block,
         // as we are already running inside one of the story's
         // phases
         foreach ($callbacks as $callback) {
             call_user_func($callback, $this);
         }
     }
     // all done
     $log->endAction();
 }