Advertisement
Guest User

example.php

a guest
Sep 29th, 2014
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1. <?php
  2.  
  3. class exampleExternalAPI
  4. {
  5.        public function echoString($string){
  6.            echo $string;
  7.        }
  8. }
  9.  
  10. class api {
  11.     public $APIs;
  12.  
  13.     public function __construct($setAPI = null){
  14.         if (isset($setAPI)){
  15.             return $this->setAPI($setAPI);
  16.         }
  17.     }
  18.  
  19. public function setAPIs($setAPIs)
  20. {
  21.     $this->APIs = new stdClass; // clears a previous call to this method
  22.     if (!is_array($setAPIs)) { // if not an array
  23.         $setAPIs = array($setAPIs); // make array
  24.     }
  25.     foreach ($setAPIs as $setAPIType) {
  26.         if (class_exists($setAPIType)) {
  27.             $this->APIs->$setAPIType = new $setAPIType;
  28.         }
  29.     }
  30.     return $this->APIs;
  31. }
  32.  
  33.     public function getListOfAPIs($update = false){
  34.         if ($update){
  35.             $this->updateListOfAPIs();
  36.         }
  37.         return  $this->listOfAPIs;
  38.     }
  39. }
  40.  
  41. $api = new api();
  42. $api->setAPIs('exampleExternalAPI');
  43. $api->APIs->exampleExternalAPI->echoString('string');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement