PHP version 5 Copyright 2016, Google Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
See also: AdsUtility
 /**
  * Gets a singleton instance of AdsUtilityRegistry.
  *
  * @return AdsUtilityRegistry the ads utility registry
  */
 public static function getInstance()
 {
     if (AdsUtilityRegistry::$instance === null) {
         AdsUtilityRegistry::$instance = new AdsUtilityRegistry();
     }
     return AdsUtilityRegistry::$instance;
 }
 /**
  * @covers AdsUtilityRegistry::addUtility
  * @covers AdsUtilityRegistry::popAllUtilities
  */
 public function testAddAndPopRegisteredUtilities()
 {
     AdsUtilityRegistry::getInstance()->addUtility('BatchJobHelper');
     AdsUtilityRegistry::getInstance()->addUtility('ReportDownloader/file');
     AdsUtilityRegistry::getInstance()->addUtility('ReportDownloader/string');
     $expected = array('BatchJobHelper' => 'BatchJobHelper', 'ReportDownloader/file' => 'ReportDownloader/file', 'ReportDownloader/string' => 'ReportDownloader/string');
     // First time, get all registered ads utilities.
     $this->assertEquals($expected, AdsUtilityRegistry::getInstance()->popAllUtilities());
     // Second time and later, get an empty list.
     $this->assertEquals(array(), AdsUtilityRegistry::getInstance()->popAllUtilities());
     $this->assertEquals(array(), AdsUtilityRegistry::getInstance()->popAllUtilities());
 }
示例#3
0
 /**
  * Gets all the user agent parts that identify this client library plus user
  * agent parts from the ads utilities registry.
  * @return array An array of all the user agent parts that identify this
  *     client library where each user agent part has been joined by a '/'
  *     (forward slash).
  */
 private function GetAllClientLibraryUserAgentParts()
 {
     $clientLibUserAgentParts[] = implode('/', $this->GetClientLibraryNameAndVersion());
     foreach ($this->GetCommonClientLibraryUserAgentParts() as $userAgentPart) {
         $clientLibUserAgentParts[] = implode('/', $userAgentPart);
     }
     if ($this->getIsIncludeUtilitiesInUserAgent() === 'true') {
         $adsUtilities = AdsUtilityRegistry::getInstance()->popAllUtilities();
         sort($adsUtilities, SORT_STRING);
         $clientLibUserAgentParts = array_merge($clientLibUserAgentParts, $adsUtilities);
     }
     return $clientLibUserAgentParts;
 }
 /**
  * Create an instance of BatchJobUtils with the specified upload URL, total
  * uploaded content bytes, CurlUtils object, BatchJobUtilsDelegate object and
  * ads utility registry.
  *
  * @param string $uploadUrl the upload URL to which the operations will be
  *     uploaded
  * @param int|null $totalContentBytes the total content bytes uploaded so far,
  *     used in incremental batch job uploads
  * @param CurlUtils|null $curlUtils the CurlUtils object for uploading batch
  *     job operations and downloading the results of batch job processing
  * @param BatchJobUtilsDelegate|null $batchJobUtilsDelegate the batch job
  *     utils delegate that uploads batch job operations and downloads the
  *     results
  * @param AdsUtilityRegistry|null $adsUtilityRegistry the ads utility registry
  */
 public function __construct($uploadUrl, $totalContentBytes = null, CurlUtils $curlUtils = null, BatchJobUtilsDelegate $batchJobUtilsDelegate = null, AdsUtilityRegistry $adsUtilityRegistry = null)
 {
     $this->batchJobUtilsDelegate = $batchJobUtilsDelegate === null ? new BatchJobUtilsDelegate($uploadUrl, $totalContentBytes, $curlUtils) : $batchJobUtilsDelegate;
     $this->adsUtilityRegistry = $adsUtilityRegistry === null ? AdsUtilityRegistry::getInstance() : $adsUtilityRegistry;
 }
 /**
  * Tests if the user agent doesn't include any usages of ads utilities when
  * isIncludeUtilitiesInUserAgent is false.
  *
  * @covers AdsUser::setIncludeUtilitiesInUserAgent
  * @covers AdsUser::updateClientLibraryUserAgent
  * @covers AdWordsUser::__construct
  */
 public function testUpdateClientLibraryUserAgent_isIncludeUtilitiesInUserAgent_false()
 {
     $USER_AGENT = 'AdWordsApiPhpClient-test';
     $LIB_NAME = 'AwApi-PHP';
     $COMMON_NAME = 'Common-PHP';
     $VERSION_REGEX = '\\d{1,2}\\.\\d{1,2}\\.\\d{1,2}';
     $user = new AdWordsUser($this->authIniFilePath, 'devToken', $USER_AGENT, null, null, $this->mockOAuth2Credential);
     $user->setIncludeUtilitiesInUserAgent('false');
     AdsUtilityRegistry::getInstance()->addUtility('BatchJobHelper');
     $user->updateClientLibraryUserAgent($user->GetUserAgent());
     // Example: "AdWordsApiPhpClient-test (AwApi-PHP/9.0.0, Common-PHP/9.0.0,
     // PHP/5.4.8)"
     $expectedUserAgents = sprintf('/^%s \\(%s\\/%s, %s\\/%s, PHP\\/%s\\)$/', preg_quote($user->GetUserAgent()), preg_quote($LIB_NAME), $VERSION_REGEX, preg_quote($COMMON_NAME), $VERSION_REGEX, preg_quote(PHP_VERSION));
     $this->assertRegExp($expectedUserAgents, $user->GetClientLibraryUserAgent());
 }
 /**
  * Create an instance of ReportUtils with the specified ads utility registry.
  *
  * @param AdsUtilityRegistry $adsUtilityRegistry the ads utility registry
  */
 public function __construct(AdsUtilityRegistry $adsUtilityRegistry = null)
 {
     $this->adsUtilityRegistry = $adsUtilityRegistry === null ? AdsUtilityRegistry::getInstance() : $adsUtilityRegistry;
 }