PEAR2_Services_NYTimesPEAR2_Services_NYTimes-0.1.0/php/PEAR2/Services/NYTimes/Main.php

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
<?php
/**
 * PEAR2\Services\NYTimes\Main
 *
 * PHP version 5
 *
 * @category  Services
 * @package   PEAR2_Services_NYTimes
 * @author    Till Klampaeckel <till@php.net>
 * @copyright 2011 Till Klampaeckel
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @version   SVN: $Id$
 * @link      https://github.com/pear2/Services_NYTimes
 */

/**
 * Main class for PEAR2_Services_NYTimes
 *
 * @category  Services
 * @package   PEAR2_Services_NYTimes
 * @author    Till Klampaeckel <till@php.net>
 * @copyright 2011 Till Klampaeckel
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @link      https://github.com/pear2/Services_NYTimes
 * @link      http://developer.nytimes.com/attribution
 */
namespace PEAR2\Services\NYTimes;
class Main
{
    /**
     * A class factory.
     *
     * @param string $api The name of the API to use.
     * @param string $key The API Key.
     *
     * @return PEAR2\Services\Base
     */
    public static function factory($api, $key)
    {
        static $supported = array('Newswire');
        $api = ucfirst(strtolower($api));

        if (!in_array($api, $supported)) {
            throw new \DomainException("Currently not supported: {$api}");
        }

        $className = "PEAR2\Services\NYTimes\\" . $api;

        return new $className($key);
    }
}
EOF