set controller entity prop at init, not at _construct, because we need post_type registered

This commit is contained in:
Jacson Passold 2018-01-19 20:43:51 -02:00
parent 86d45910d4
commit 8c740ee5f7
6 changed files with 53 additions and 16 deletions

View File

@ -19,10 +19,17 @@ class TAINACAN_REST_Collections_Controller extends WP_REST_Controller {
public function __construct(){
$this->namespace = 'tainacan/v2';
$this->rest_base = 'collections';
$this->collections_repository = new Repositories\Collections();
$this->collection = new Entities\Collection();
add_action('rest_api_init', array($this, 'register_routes'));
add_action('init', array(&$this, 'init_objects'), 11);
}
/**
* Initialize objects after post_type register
*/
public function init_objects() {
$this->collections_repository = new Repositories\Collections();
$this->collection = new Entities\Collection();
}
/**

View File

@ -20,16 +20,22 @@ class TAINACAN_REST_Filters_Controller extends WP_REST_Controller {
$this->namespace = '/tainacan/v2';
$this->rest_base = 'filters';
add_action('rest_api_init', array($this, 'register_routes'));
add_action('init', array(&$this, 'init_objects'), 11);
}
/**
* Initialize objects after post_type register
*/
public function init_objects() {
$this->collection = new Entities\Collection();
$this->collection_repository = new Repositories\Collections();
$this->metadata = new Entities\Metadata();
$this->metadata_repository = new Repositories\Metadatas();
$this->filter = new Entities\Filter();
$this->filter_repository = new Repositories\Filters();
add_action('rest_api_init', array($this, 'register_routes'));
}
public function register_routes() {

View File

@ -21,12 +21,19 @@ class TAINACAN_REST_Items_Controller extends WP_REST_Controller {
public function __construct() {
$this->namespace = 'tainacan/v2';
$this->rest_base = 'items';
add_action('rest_api_init', array($this, 'register_routes'));
add_action('init', array(&$this, 'init_objects'), 11);
}
/**
* Initialize objects after post_type register
*/
public function init_objects() {
$this->items_repository = new Repositories\Items();
$this->item = new Entities\Item();
$this->item_metadata = new Repositories\Item_Metadata();
$this->collections_repository = new Repositories\Collections();
add_action('rest_api_init', array($this, 'register_routes'));
}
/**

View File

@ -14,16 +14,21 @@ class TAINACAN_REST_Metadata_Controller extends WP_REST_Controller {
$this->namespace = 'tainacan/v2';
$this->rest_base = 'metadata';
add_action('rest_api_init', array($this, 'register_routes'));
add_action('init', array(&$this, 'init_objects'), 11);
}
/**
* Initialize objects after post_type register
*/
public function init_objects() {
$this->metadata = new Entities\Metadata();
$this->metadata_repository = new Repositories\Metadatas();
$this->item_metadata_repository = new Repositories\Item_Metadata();
$this->item_repository = new Repositories\Items();
$this->collection_repository = new Repositories\Collections();
add_action('rest_api_init', array($this, 'register_routes'));
}
/**
* If POST on metadata/collection/<collection_id>, then
* a metadata will be created in matched collection and all your item will receive this metadata

View File

@ -3,7 +3,7 @@
use Tainacan\Entities;
use Tainacan\Repositories;
class TAINACAN_REST_Taxonomies_Controller extends WP_REST_Controller {
class TAINACAN_REST_Taxonomies_Controller extends \WP_REST_Controller {
private $taxonomy;
private $taxonomy_repository;
@ -14,10 +14,16 @@ class TAINACAN_REST_Taxonomies_Controller extends WP_REST_Controller {
$this->namespace = 'tainacan/v2';
$this->rest_base = 'taxonomies';
add_action('rest_api_init', array($this, 'register_routes'));
add_action('init', array(&$this, 'init_objects'), 11);
}
/**
* Initialize objects after post_type register
*/
public function init_objects() {
$this->taxonomy = new Entities\Taxonomy();
$this->taxonomy_repository = new Repositories\Taxonomies();
add_action('rest_api_init', array($this, 'register_routes'));
}
public function register_routes() {

View File

@ -16,12 +16,18 @@ class TAINACAN_REST_Terms_Controller extends WP_REST_Controller {
$this->namespace = 'tainacan/v2';
$this->rest_base = 'terms';
add_action('rest_api_init', array($this, 'register_routes'));
add_action('init', array(&$this, 'init_objects'), 11);
}
/**
* Initialize objects after post_type register
*/
public function init_objects() {
$this->term = new Entities\Term();
$this->terms_repository = new Repositories\Terms();
$this->taxonomy = new Entities\Taxonomy();
$this->taxonomy_repository = new Repositories\Taxonomies();
add_action('rest_api_init', array($this, 'register_routes'));
}
public function register_routes() {