Пример #1
0
 public function testHas()
 {
     $api = $this->createApi('en');
     $apiCollection = new ApiCollection();
     $this->assertFalse($apiCollection->has('en'));
     $apiCollection->add('en', $api);
     $this->assertTrue($apiCollection->has('en'));
 }
Пример #2
0
 public function testApi()
 {
     $enApi = $this->createApi();
     $ruApi = $this->createApi();
     $apiCollection = new ApiCollection();
     $apiCollection->add('en', $enApi);
     $apiCollection->add('ru', $ruApi);
     $project = new ProjectExample($apiCollection);
     $this->assertEquals($enApi, $project->api('en'));
     $this->assertEquals($ruApi, $project->api('ru'));
 }
Пример #3
0
 /**
  * @param string|null $language
  * 
  * @return Mediawiki\Api\Api
  */
 public function api($language = null)
 {
     if ($language === null and $this->defaultLanguage === null) {
         throw new LogicException('Please, specify language of API or default language of project');
     }
     $language = $language === null ? $this->defaultLanguage : $language;
     return $this->api->get($language);
 }
Пример #4
0
 /**
  * @param  array  $apiUrls
  * @param  array  $apiUsernames
  * @param  Project|string $class
  * 
  * @return Project
  */
 public function createProject($apiUrls = [], $apiUsernames = [], $class = Project::class)
 {
     if (is_string($class)) {
         if (!class_exists($class)) {
             throw new InvalidArgumentException(sprintf('Class "%s" does not exists', $class));
         }
         $project = new $class();
     } else {
         $project = $class;
     }
     if (!$project instanceof Project) {
         throw new InvalidArgumentException(sprintf('Argument 1 passed to %s must be an instance of %s, %s given', __METHOD__, Project::class, is_object($project) ? get_class($project) : gettype($project)));
     }
     if (!is_array($apiUrls)) {
         throw new InvalidArgumentException(sprintf('%s expects parameter 2 to be array, %s given', __METHOD__, gettype($format)));
     }
     if (!is_array($apiUsernames)) {
         throw new InvalidArgumentException(sprintf('%s expects parameter 3 to be array, %s given', __METHOD__, gettype($format)));
     }
     if (!empty($apiUrls)) {
         foreach ($apiUrls as $language => $url) {
             $project->setApiUrl($language, $url);
         }
     }
     if (!empty($apiUsernames)) {
         foreach ($apiUsernames as $language => $username) {
             $project->setApiUsername($language, $username);
         }
     }
     $apiCollection = new ApiCollection();
     foreach ($project->getApiUrls() as $language => $url) {
         $api = new Api($url, $this->client, $this->storage);
         $apiCollection->add($language, $api);
     }
     $serviceManager = new ServiceManager($apiCollection);
     $project->setApiCollection($apiCollection);
     $project->setServiceManager($serviceManager);
     return $project;
 }