Example #1
0
 /**
  * Tracker constructor.
  * @param array|null $credentials
  */
 public function __construct(array $credentials = null)
 {
     // Singleton pattern to the base container we don't need
     // to instantiate the base container a lot of times
     $this->baseContainer = BaseContainer::getInstance();
     // Register the OauthStack extension by default
     $this->registerExtension(Extensions\OauthStack::class);
     /*
      * Execute useOauth by default
      * Due we decided to include OauthExtension by default
      * we should call its method
      */
     (new Extensions\OauthStack($credentials))->useOauth();
 }
 /**
  * Using the magic method __call we can look for the proper class
  * which contains the method called
  *
  * @param $method
  * @param $args
  * @return EndpointsTrait
  * @throws TwitterStreamingException
  */
 public function __call($method, $args)
 {
     try {
         // Get the extensions registered of the BaseContainer class
         $extensions = BaseContainer::getInstance()->getRegistry();
         if (is_array($extensions)) {
             foreach ($extensions as $extension) {
                 // Create a new instance of the extension and check if
                 // has the method and its public
                 $_class = new \ReflectionClass($extension);
                 if ($_class->hasMethod($method)) {
                     $reflection = new \ReflectionMethod($extension, $method);
                     if ($reflection && $reflection->isPublic()) {
                         return $this->call($reflection, $extension, $args);
                     }
                 }
             }
             throw new TwitterStreamingException(sprintf('Unable to find a class with the method `%s`', $method));
         }
     } catch (TwitterStreamingException $e) {
         exit($e->getMessage());
     }
 }