Permalink
Browse files

create ResourceInfoboxDefinition class

  • Loading branch information...
1 parent ee5f6ac commit 4dcd22edf3e430767e1ecbcd708f06f711e0af83 @benatkin committed Sep 21, 2011
Showing with 27 additions and 8 deletions.
  1. +27 −8 resource-infobox.php
View
@@ -26,13 +26,15 @@
*/
class ResourceInfobox {
- function __construct( $url ) {
+ function __construct( $url, $plugin ) {
$this->url = $url;
+ $this->plugin = $plugin;
}
- function fetch_rules() {
+ function fetch_resource_definition() {
$description_file = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'descriptions.json';
- $this->rules = json_decode(file_get_contents($description_file))->github->repository;
+ $this->resource_definition = json_decode(file_get_contents($description_file))->github->repository;
+ $this->resource_definition = $this->plugin->resource_definition_collection->find($this->url);
}
function variable_matched($matches) {
@@ -67,8 +69,8 @@ function replace_url_params($url) {
}
function find_resource() {
- $this->params = $this->extract_url_params($this->rules->url, $this->url);
- $this->api_url = $this->replace_url_params($this->rules->api_url);
+ $this->params = $this->extract_url_params($this->resource_definition->url, $this->url);
+ $this->api_url = $this->replace_url_params($this->resource_definition->api_url);
}
function fetch_data() {
@@ -140,7 +142,7 @@ function render_field( $field ) {
function render() {
$fields_html = '';
- foreach ($this->rules->fields as $field) {
+ foreach ($this->resource_definition->fields as $field) {
$fields_html .= $this->render_field($field);
}
@@ -150,8 +152,25 @@ function render() {
}
}
+class ResourceInfoboxDefinition {
+ function __construct() {
+ }
+}
+
+class ResourceInfoboxDefinitionCollection {
+ function __construct() {
+ $description_file = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'descriptions.json';
+ $this->data = json_decode(file_get_contents($description_file));
+ }
+
+ function find($url) {
+ return $this->data->github->repository;
+ }
+}
+
class ResourceInfoboxPlugin {
function __construct() {
+ $this->resource_definition_collection = new ResourceInfoboxDefinitionCollection();
}
function setup() {
@@ -167,8 +186,8 @@ function shortcode($atts) {
$url = $atts['url'];
- $infobox = new ResourceInfobox($url);
- $infobox->fetch_rules();
+ $infobox = new ResourceInfobox($url, $this);
+ $infobox->fetch_resource_definition();
$infobox->find_resource();
$infobox->fetch_data();
$html = $infobox->render();

0 comments on commit 4dcd22e

Please sign in to comment.