Created
October 17, 2011 10:43
-
-
Save mach3/1292371 to your computer and use it in GitHub Desktop.
Servces_Twitterを拡張して定義ファイルを追加で読み込めるようにする。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$foo = new MY_Services_twitter(); | |
$foo->addAPI( "/the/path/to/your/api.xml" ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once( "Services/Twitter.php" ); | |
class MY_Services_twitter extends Services_twitter { | |
public function __construct(){ | |
parent::__construct(); | |
} | |
public function addAPI( $xml ){ | |
if( !file_exists( $xml ) ){ | |
throw new Exception( "'{$xml}' is not found." ); | |
} | |
$xmlApi = simplexml_load_file( $xml ); | |
foreach ($xmlApi->category as $category) { | |
$catName = (string)$category['name']; | |
if( !is_array( $this->api[$catName] ) ){ | |
$this->api[$catName] = array(); | |
} | |
foreach ($category->endpoint as $endpoint) { | |
$this->api[$catName][(string)$endpoint['name']] = $endpoint; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment