Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit503bc71

Browse files
committed
Merge branch '0.6.x'
2 parents678ffe5 +d623be8 commit503bc71

File tree

65 files changed

+668
-958
lines changed

Some content is hidden

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

65 files changed

+668
-958
lines changed

‎CHANGELOG.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
###0.6.0
2+
3+
####Breaking changes
4+
5+
1. Eradicated`Client*Operator` operators completely, use context instead to pass client's username.
6+
2. Every method that was expecting`array $context` will now expect`Context $context`, if you want e.g. to make a request for client with username`"foo"` you can now do it via`$operator->requestMethod(... params, Context::forClient("foo"))`.
7+
8+
...
9+
110
###0.2.0
211

312
####Breaking changes

‎composer.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"phpunit/phpunit":"^4.7",
1313
"guzzlehttp/guzzle":"^6",
1414
"doctrine/cache":"^1",
15-
"dsl/cache-control":"0.1.0"
15+
"dsl/cache-control":"0.1.0",
16+
"psr/log":"^1"
1617
},
1718
"license":"Apache License 2.0",
1819
"autoload": {

‎src/Client.php‎

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,10 @@ public function __construct(RequestFactory $requestFactory, HttpMiddlewareStackP
3232
*
3333
* @param string $path
3434
* @param array|null $query
35-
* @param array|null $context Arbitrary context-table
36-
*
35+
* @param Context $context
3736
* @return mixed
38-
* @throws MyTargetException
3937
*/
40-
publicfunctionget($path,array$query =null,array$context =null)
38+
publicfunctionget($path,array$query =null,Context$context)
4139
{
4240
$request =$this->requestFactory->create('GET',$path,$query);
4341

@@ -52,12 +50,10 @@ public function get($path, array $query = null, array $context = null)
5250
* @param string $path
5351
* @param array|null $query
5452
* @param array|null $body
55-
* @param array|null $context
56-
*
53+
* @param Context $context
5754
* @return mixed
58-
* @throws MyTargetException
5955
*/
60-
publicfunctionpost($path,array$query =null,$body =null,array$context =null)
56+
publicfunctionpost($path,array$query =null,$body =null,Context$context)
6157
{
6258
$request =$this->requestFactory->create('POST',$path,$query);
6359

@@ -76,12 +72,12 @@ public function post($path, array $query = null, $body = null, array $context =
7672
*
7773
* @param string $path
7874
* @param array|null $query
79-
* @paramarray|null $context
75+
* @paramContext $context
8076
*
8177
* @return mixed
8278
* @throws MyTargetException
8379
*/
84-
publicfunctiondelete($path,array$query =null,array$context =null)
80+
publicfunctiondelete($path,array$query =null,Context$context)
8581
{
8682
$request =$this->requestFactory->create("DELETE",$path,$query);
8783

@@ -94,12 +90,12 @@ public function delete($path, array $query = null, array $context = null)
9490
* @param string $path
9591
* @param array $body
9692
* @param array|null $query
97-
* @paramarray|null $context
93+
* @paramContext $context
9894
*
9995
* @return mixed
10096
* @throws MyTargetException
10197
*/
102-
publicfunctionpostMultipart($path,array$body,array$query =null,array$context =null)
98+
publicfunctionpostMultipart($path,array$body,array$query =null,Context$context)
10399
{
104100
$request =$this->requestFactory->create("POST",$path,$query);
105101
$request =$request->withBody(newpsr\MultipartStream($body));

‎src/Context.php‎

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<?php
2+
3+
namespaceDsl\MyTarget;
4+
5+
class Context
6+
{
7+
/**
8+
* @var string|null
9+
*/
10+
private$username;
11+
12+
/**
13+
* @var string
14+
*/
15+
private$limitBy;
16+
17+
/**
18+
* @var array|null
19+
*/
20+
private$parameters;
21+
22+
/**
23+
* @param string|null $username
24+
* @param string|null $limitBy
25+
* @param array|null $parameters
26+
*/
27+
publicfunction__construct($username =null,$limitBy =null,array$parameters =null)
28+
{
29+
$this->username =$username;
30+
$this->limitBy =$limitBy;
31+
$this->parameters =$parameters;
32+
}
33+
34+
/**
35+
* @param string $username
36+
* @param array|null $parameters
37+
* @return static
38+
*/
39+
publicstaticfunctionforClient($username,array$parameters =null)
40+
{
41+
returnnewstatic($username,null,$parameters);
42+
}
43+
44+
/**
45+
* @param array|null $parameters
46+
* @return static
47+
*/
48+
publicstaticfunctionparams(array$parameters =null)
49+
{
50+
returnnewstatic(null,null,$parameters);
51+
}
52+
53+
/**
54+
* @param Context|null $ctx
55+
* @param string $limitBy
56+
* @return static
57+
*/
58+
publicstaticfunctionwithLimitBy(Context$ctx =null,$limitBy)
59+
{
60+
if ($ctx) {
61+
$ctx->limitBy =$limitBy;
62+
}else {
63+
$ctx =newstatic(null,$limitBy);
64+
}
65+
66+
return$ctx;
67+
}
68+
69+
/**
70+
* @return bool
71+
*/
72+
publicfunctionhasUsername()
73+
{
74+
return$this->username !==null;
75+
}
76+
77+
/**
78+
* @return null|string
79+
*/
80+
publicfunctiongetUsername()
81+
{
82+
return$this->username;
83+
}
84+
85+
/**
86+
* @return null|string
87+
*/
88+
publicfunctiongetLimitBy()
89+
{
90+
return$this->limitBy;
91+
}
92+
93+
/**
94+
* @param string $key
95+
* @param mixed $value
96+
* @return $this
97+
*/
98+
publicfunctionaddParameter($key,$value)
99+
{
100+
$this->parameters[$key] =$value;
101+
102+
return$this;
103+
}
104+
105+
/**
106+
* @param string $key
107+
* @return bool
108+
*/
109+
publicfunctionhasParameter($key)
110+
{
111+
returnisset($this->parameters[$key]);
112+
}
113+
114+
/**
115+
* @param string $key
116+
* @return mixed
117+
*/
118+
publicfunctiongetParameter($key)
119+
{
120+
returnisset($this->parameters[$key]) ?$this->parameters[$key] :null;
121+
}
122+
123+
/**
124+
* @return array|null
125+
*/
126+
publicfunctiongetParameters()
127+
{
128+
return$this->parameters;
129+
}
130+
}

‎src/Domain/V1/Targeting/RemarketingTargeting.php‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ class RemarketingTargeting
1818
*/
1919
private$name;
2020

21+
/**
22+
* @param int $id
23+
* @return RemarketingTargeting
24+
*/
25+
publicstaticfunctionwithId($id)
26+
{
27+
returnnewRemarketingTargeting($id,null);
28+
}
29+
2130
/**
2231
* @param int $id
2332
* @param string $name

‎src/Limiting/DoctrineCacheRateLimitProvider.php‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespaceDsl\MyTarget\Limiting;
44

55
useDoctrine\Common\Cache\Cache;
6+
useDsl\MyTarget\Context;
67
usePsr\Http\Message\RequestInterface;
78
usePsr\Http\Message\ResponseInterface;
89

@@ -33,16 +34,15 @@ class DoctrineCacheRateLimitProvider implements RateLimitProvider
3334
*
3435
* @param Cache $cache
3536
* @param LimitExtractor|null $limitExtractor
36-
* @param callable|null $hashFunction callable(string $limitBy, RequestInterface,array $context)
37+
* @param callable|null $hashFunction callable(string $limitBy, RequestInterface,Context $context)
3738
*/
3839
publicfunction__construct(Cache$cache,LimitExtractor$limitExtractor =null,callable$hashFunction =null)
3940
{
4041
$this->cache =$cache;
4142
$this->limitExtractor =$limitExtractor ?:newHeaderLimitExtractor();
4243

43-
$this->hashFunction =$hashFunction ?:function($limitBy,RequestInterface$request,array$context) {
44-
$username =isset($context["username"]) ?$context["username"] :"";
45-
returnsprintf("%s#%s",$limitBy,$username);
44+
$this->hashFunction =$hashFunction ?:function($limitBy,RequestInterface$request,Context$context) {
45+
returnsprintf("%s#%s",$limitBy,$context->getUsername());
4646
};
4747

4848
$this->momentGenerator =function () {
@@ -61,9 +61,9 @@ public function setMomentGenerator(callable $generator)
6161
/**
6262
* @inheritdoc
6363
*/
64-
publicfunctionrateLimitTimeout($limitBy,RequestInterface$request,array$context =null)
64+
publicfunctionrateLimitTimeout($limitBy,RequestInterface$request,Context$context)
6565
{
66-
$id =call_user_func($this->hashFunction,$limitBy,$request,$context ?: []);
66+
$id =call_user_func($this->hashFunction,$limitBy,$request,$context);
6767
$limitsArray =$this->cache->fetch($id);
6868

6969
if ( !is_array($limitsArray) || !$limitsArray) {
@@ -101,11 +101,11 @@ public function rateLimitTimeout($limitBy, RequestInterface $request, array $con
101101
/**
102102
* @inheritdoc
103103
*/
104-
publicfunctionrefreshLimits(RequestInterface$request,ResponseInterface$response,$limitBy,array$context =null)
104+
publicfunctionrefreshLimits(RequestInterface$request,ResponseInterface$response,$limitBy,Context$context)
105105
{
106106
$limits =$this->limitExtractor->extractLimits($response,call_user_func($this->momentGenerator));
107107

108-
$id =call_user_func($this->hashFunction,$limitBy,$request,$context ?: []);
108+
$id =call_user_func($this->hashFunction,$limitBy,$request,$context);
109109

110110
$this->cache->save($id,$limits->toArray());
111111
}

‎src/Limiting/LimitingMiddleware.php‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
usePsr\Http\Message\RequestInterface;
99
useDsl\MyTarget\Exception\DecodingException;
1010
useDsl\MyTargetasf;
11+
useDsl\MyTarget\Context;
1112

1213
class LimitingMiddlewareimplements HttpMiddleware
1314
{
@@ -26,13 +27,13 @@ public function __construct(RateLimitProvider $rateLimitProvider)
2627
/**
2728
* @inheritdoc
2829
*/
29-
publicfunctionrequest(RequestInterface$request,HttpMiddlewareStack$stack,array$context =null)
30+
publicfunctionrequest(RequestInterface$request,HttpMiddlewareStack$stack,Context$context)
3031
{
31-
if ( !is_array($context) || !isset($context["limit-by"])) {
32+
if ( !$context->getLimitBy()) {
3233
return$stack->request($request,$context);
3334
}
3435

35-
$limitBy =$context["limit-by"];
36+
$limitBy =$context->getLimitBy();
3637

3738
$timeout =$this->rateLimitProvider->rateLimitTimeout($limitBy,$request,$context);
3839

@@ -45,9 +46,6 @@ public function request(RequestInterface $request, HttpMiddlewareStack $stack, a
4546
$this->rateLimitProvider->refreshLimits($request,$response,$limitBy,$context);
4647

4748
if ($response->getStatusCode() ===self::HTTP_STATUS_LIMIT_REACHED) {
48-
if (strpos((string)$response->getBody(),'banners limit') !==false) {
49-
thrownewEx\BannerLimitException('Banners limit exceeded');
50-
}
5149
try {
5250
$decoded =f\json_decode((string)$response->getBody());
5351
}catch (DecodingException$e) { }

‎src/Limiting/RateLimitProvider.php‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespaceDsl\MyTarget\Limiting;
44

5+
useDsl\MyTarget\Context;
56
usePsr\Http\Message\RequestInterface;
67
usePsr\Http\Message\ResponseInterface;
78

@@ -13,19 +14,19 @@ interface RateLimitProvider
1314
*
1415
* @param string $limitBy
1516
* @param RequestInterface $request
16-
* @paramarray|null $context
17+
* @paramContext $context
1718
*
1819
* @return int|bool
1920
*/
20-
publicfunctionrateLimitTimeout($limitBy,RequestInterface$request,array$context =null);
21+
publicfunctionrateLimitTimeout($limitBy,RequestInterface$request,Context$context);
2122

2223
/**
2324
* Will look into the response headers and try to find X-RateLimit-* headers and save them somewhere
2425
*
2526
* @param RequestInterface $request
2627
* @param ResponseInterface $response
2728
* @param string $limitBy
28-
* @paramarray|null $context
29+
* @paramContext $context
2930
*/
30-
publicfunctionrefreshLimits(RequestInterface$request,ResponseInterface$response,$limitBy,array$context =null);
31+
publicfunctionrefreshLimits(RequestInterface$request,ResponseInterface$response,$limitBy,Context$context);
3132
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp