1: <?php
2: /**
3: * PHP OpenCloud library.
4: *
5: * @copyright 2013 Rackspace Hosting, Inc. See LICENSE for information.
6: * @license https://www.apache.org/licenses/LICENSE-2.0
7: * @author Jamie Hannaford <jamie.hannaford@rackspace.com>
8: */
9:
10: namespace OpenCloud\Common\Service;
11:
12: use OpenCloud\Common\Exceptions\InvalidArgumentError;
13:
14: /**
15: * This object represents the service catalog returned by the Rackspace API. It contains all the services available
16: * to the end-user, including specific information for each service.
17: */
18: class Catalog
19: {
20: /**
21: * @var array Service items
22: */
23: private $items = array();
24:
25: /**
26: * Produces a Catalog from a mixed input.
27: *
28: * @param $config
29: * @return Catalog
30: * @throws \OpenCloud\Common\Exceptions\InvalidArgumentError
31: */
32: public static function factory($config)
33: {
34: if (is_array($config)) {
35: $catalog = new self();
36: foreach ($config as $item) {
37: $catalog->items[] = CatalogItem::factory($item);
38: }
39: } elseif ($config instanceof Catalog) {
40: $catalog = $config;
41: } else {
42: throw new InvalidArgumentError(sprintf(
43: 'Argument for Catalog::factory must be either an array or an '
44: . 'instance of %s. You passed in: %s',
45: get_class(),
46: print_r($config, true)
47: ));
48: }
49:
50: return $catalog;
51: }
52:
53: /**
54: * @return array
55: */
56: public function getItems()
57: {
58: return $this->items;
59: }
60: }