File tree

367 files changed

+24178
-9825
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searcx below for content that may be hidden.

367 files changed

+24178
-9825
lines changed
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<?php
2+
/**
3+
* Copyright 2017 Google Inc. All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
namespace Google\AdsApi\AdManager\Util\v201908;
19+
20+
use DateTime;
21+
use DateTimeZone;
22+
use Google\AdsApi\AdManager\v201908\Date;
23+
use Google\AdsApi\AdManager\v201908\DateTime as AdManagerDateTime;
24+
25+
/**
26+
* Static utility methods for working with Ad Manager `DateTime` objects.
27+
*/
28+
final class AdManagerDateTimes
29+
{
30+
31+
private function __construct()
32+
{
33+
}
34+
35+
/**
36+
* Creates a Ad Manager date time from a PHP date time.
37+
*
38+
* @param DateTime $dateTime
39+
* @return AdManagerDateTime
40+
*/
41+
public static function fromDateTime(DateTime $dateTime)
42+
{
43+
$date = new Date();
44+
$date->setYear(intval($dateTime->format('Y')));
45+
$date->setMonth(intval($dateTime->format('m')));
46+
$date->setDay(intval($dateTime->format('d')));
47+
48+
$result = new AdManagerDateTime();
49+
$result->setDate($date);
50+
$result->setHour(intval($dateTime->format('H')));
51+
$result->setMinute(intval($dateTime->format('i')));
52+
$result->setSecond(intval($dateTime->format('s')));
53+
$result->setTimeZoneId($dateTime->format('e'));
54+
55+
return $result;
56+
}
57+
58+
/**
59+
* Creates a Ad Manager date time from a date time string in ISO 8601
60+
* format.
61+
*
62+
* @param string $dateTime
63+
* @return AdManagerDateTime
64+
*/
65+
public static function fromDateTimeString($dateTime)
66+
{
67+
return self::fromDateTime(
68+
DateTime::createFromFormat(DateTime::ATOM, $dateTime)
69+
);
70+
}
71+
72+
/**
73+
* Converts a Ad Manager date time to a PHP date time.
74+
*
75+
* @param AdManagerDateTime $adManagerDateTime
76+
* @return DateTime
77+
*/
78+
public static function toDateTime(AdManagerDateTime $adManagerDateTime)
79+
{
80+
$dateTimeString = sprintf(
81+
'%sT%02d:%02d:%02d',
82+
AdManagerDates::toDateString($adManagerDateTime->getDate()),
83+
$adManagerDateTime->getHour(),
84+
$adManagerDateTime->getMinute(),
85+
$adManagerDateTime->getSecond()
86+
);
87+
88+
return new DateTime(
89+
$dateTimeString,
90+
new DateTimeZone($adManagerDateTime->getTimeZoneID())
91+
);
92+
}
93+
94+
/**
95+
* Returns an ISO 8601 string representation of the specified Ad Manager
96+
* date time.
97+
*
98+
* Optionally, you may specify the timezone you want to view the date time
99+
* in. By default the time zone from the Ad Manager date time is used.
100+
* For example, if the Ad Manager date time holds `11/29/2016 21:05:30
101+
* in GMT`, the result from this method with Europe/Paris as the new time
102+
* zone, would be `11/29/2016 22:05:30 in CET`. This is useful for
103+
* displaying Ad Manager date times in your network's time zone.
104+
* For example:
105+
*
106+
* ```
107+
* $timeZoneId = $networkService->getCurrentNetwork()->getTimeZone();
108+
* $dateTimeString = AdManagerDateTimes::toDateTimeString(
109+
* $adManagerDateTime,
110+
* $timeZoneId
111+
* );
112+
* ```
113+
*
114+
* @param AdManagerDateTime $adManagerDateTime
115+
* @param null|string $timeZoneId optional
116+
* @return string
117+
*/
118+
public static function toDateTimeString(
119+
AdManagerDateTime $adManagerDateTime,
120+
$timeZoneId = null
121+
) {
122+
$dateTime = self::toDateTime($adManagerDateTime);
123+
if ($timeZoneId !== null) {
124+
$dateTime->setTimezone(new DateTimeZone($timeZoneId));
125+
}
126+
127+
return $dateTime->format(DateTime::ATOM);
128+
}
129+
}
130+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
/**
3+
* Copyright 2017 Google Inc. All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
namespace Google\AdsApi\AdManager\Util\v201908;
19+
20+
use Google\AdsApi\AdManager\v201908\Date;
21+
22+
/**
23+
* Static utility methods for working with Ad Manager `Date` objects.
24+
*/
25+
final class AdManagerDates
26+
{
27+
28+
private function __construct()
29+
{
30+
}
31+
32+
/**
33+
* Returns string representation of the specified Ad Manager date in
34+
* `yyyy-MM-dd` format.
35+
*
36+
* @param Date $adManagerDate
37+
* @return string
38+
*/
39+
public static function toDateString(Date $adManagerDate)
40+
{
41+
return sprintf(
42+
'%d-%02d-%02d',
43+
$adManagerDate->getYear(),
44+
$adManagerDate->getMonth(),
45+
$adManagerDate->getDay()
46+
);
47+
}
48+
}
49+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
/**
3+
* Copyright 2017 Google Inc. All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
namespace Google\AdsApi\AdManager\Util\v201908;
19+
20+
use InvalidArgumentException;
21+
22+
/**
23+
* A utility class for processing and handling CSV files.
24+
*/
25+
class CsvFiles
26+
{
27+
28+
/**
29+
* This class is meant to be used statically.
30+
*/
31+
private function __construct()
32+
{
33+
}
34+
35+
/**
36+
* Writes the CSV data to a file located at `$fileName`.
37+
*
38+
* @param array $csvData the CSV data including the header
39+
* @param string $fileName the file to write the CSV data to
40+
* @throws InvalidArgumentException if `$csvData` is null or
41+
* `$fileName` is null
42+
*/
43+
public static function writeCsv(array $csvData, $fileName)
44+
{
45+
if (is_null($fileName)) {
46+
throw new InvalidArgumentException('File name is null.');
47+
}
48+
49+
$handle = null;
50+
51+
try {
52+
$handle = fopen($fileName, 'w');
53+
self::writeCsvToStream($csvData, $handle);
54+
} finally {
55+
if (isset($handle)) {
56+
fclose($handle);
57+
}
58+
}
59+
}
60+
61+
/**
62+
* Writes the CSV data to a stream handle.
63+
*
64+
* @param array $csvData the CSV data including the header
65+
* @param resource $handle the stream handle to write the CSV data to
66+
* @throws InvalidArgumentException if `$csvData` is null or
67+
* `$fileName` is null
68+
*/
69+
public static function writeCsvToStream(array $csvData, $handle)
70+
{
71+
if (is_null($handle)) {
72+
throw new InvalidArgumentException('File handle is null.');
73+
}
74+
75+
foreach ($csvData as $line) {
76+
fputcsv($handle, $line);
77+
}
78+
}
79+
}
80+

0 commit comments

Comments
 (0)