Skip to content

Commit 0d476dd

Browse files
committed
Forward all available listeners
When a child class is requested via Api::api or Api::childClass, all available listeners are sent to that child, not just `oauth` and `basicauth`.
1 parent e509d8d commit 0d476dd

File tree

3 files changed

+54
-6
lines changed

3 files changed

+54
-6
lines changed

lib/Bitbucket/API/Api.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,8 @@ protected function childFactory($name)
299299
$class = '\\Bitbucket\\API\\'.$name;
300300
$child = new $class($this->client);
301301

302-
if ($this->getClient()->isListener('basicauth')) {
303-
$child->getClient()->addListener($this->getClient()->getListener('basicauth'));
304-
}
305-
306-
if ($this->getClient()->isListener('oauth')) {
307-
$child->getClient()->addListener($this->getClient()->getListener('oauth'));
302+
if ($this->getClient()->hasListeners()) {
303+
$child->getClient()->setListeners($this->getClient()->getListeners());
308304
}
309305

310306
return $child;

lib/Bitbucket/API/Http/ClientInterface.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,25 @@ public function delListener($name);
149149
*/
150150
public function getListener($name);
151151

152+
/**
153+
* @access public
154+
* @return array
155+
*/
156+
public function getListeners();
157+
158+
/**
159+
* @access public
160+
* @return bool
161+
*/
162+
public function hasListeners();
163+
164+
/**
165+
* @access public
166+
* @param array $listeners
167+
* @return $this
168+
*/
169+
public function setListeners(array $listeners);
170+
152171
/**
153172
* Check if a listener exists
154173
*

lib/Bitbucket/API/Http/Listener.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,39 @@ public function isListener($name)
7676
return ($this->searchListener($name) instanceof ListenerInterface);
7777
}
7878

79+
/**
80+
* @access public
81+
* @return array
82+
*/
83+
public function getListeners()
84+
{
85+
return $this->listeners;
86+
}
87+
88+
/**
89+
* @access public
90+
* @return bool
91+
*/
92+
public function hasListeners()
93+
{
94+
return (count($this->listeners) > 0);
95+
}
96+
97+
/**
98+
* @access public
99+
* @param array $listeners
100+
* @return $this;
101+
*/
102+
public function setListeners(array $listeners)
103+
{
104+
foreach ($listeners as $prio => $listener) {
105+
$listener = array_values($listener);
106+
$this->addListener($listener[0], $prio);
107+
}
108+
109+
return $this;
110+
}
111+
79112
/**
80113
* @access protected
81114
* @param string $name Listener name

0 commit comments

Comments
 (0)