forked from joomla-framework/github-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractPackage.php
More file actions
68 lines (60 loc) · 1.54 KB
/
AbstractPackage.php
File metadata and controls
68 lines (60 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/**
* Part of the Joomla Framework Github Package
*
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\Github;
use Joomla\Http\Http as BaseHttp;
use Joomla\Registry\Registry;
/**
* GitHub API package class for the Joomla Framework.
*
* @since 1.0
*/
abstract class AbstractPackage extends AbstractGithubObject
{
/**
* Constructor.
*
* @param Registry $options GitHub options object.
* @param BaseHttp $client The HTTP client object.
*
* @since 1.0
*/
public function __construct(Registry $options = null, BaseHttp $client = null)
{
parent::__construct($options, $client);
$this->package = \get_class($this);
$this->package = substr($this->package, strrpos($this->package, '\\') + 1);
}
/**
* Magic method to lazily create API objects
*
* @param string $name Name of property to retrieve
*
* @since 1.0
* @throws \InvalidArgumentException
*
* @return AbstractPackage GitHub API package object.
*/
public function __get($name)
{
$class = '\\Joomla\\Github\\Package\\' . $this->package . '\\' . ucfirst($name);
if (class_exists($class) == false)
{
throw new \InvalidArgumentException(
sprintf(
'Argument %1$s produced an invalid class name: %2$s in package %3$s',
$name, $class, $this->package
)
);
}
if (isset($this->$name) == false)
{
$this->$name = new $class($this->options, $this->client);
}
return $this->$name;
}
}