This commit is contained in:
weryques 2017-11-24 17:06:37 -02:00
parent bcc6637a35
commit 9b309a1964
3 changed files with 87 additions and 73 deletions

View File

@ -0,0 +1,10 @@
<?php
const ENDPOINTS_DIR = __DIR__ . '/endpoints/';
require_once(ENDPOINTS_DIR . 'class-tainacan-rest-collections-controller.php');
$rest_collections_controller = new TAINACAN_REST_Collections_Controller();
// Add here other endpoints imports
?>

View File

@ -0,0 +1,73 @@
<?php
const ENTITIES_DIR = __DIR__ . '/entities/';
const FIELD_TYPES_DIR = __DIR__ . '/field-types/';
const FILTER_TYPES_DIR = __DIR__ . '/filter-types/';
const REPOSITORIES_DIR = __DIR__ . '/repositories/';
const TRAITS_DIR = __DIR__ . '/traits/';
const CLASSES_DIR = __DIR__;
const VENDOR_DIR = __DIR__ . '/../vendor/';
const DIRS = [
CLASSES_DIR,
ENTITIES_DIR,
FIELD_TYPES_DIR,
FILTER_TYPES_DIR,
REPOSITORIES_DIR,
TRAITS_DIR,
];
require_once(VENDOR_DIR . 'autoload.php');
spl_autoload_register('tainacan_autoload');
function tainacan_autoload($class_name){
$class_path = explode('\\', $class_name);
$class_name = end($class_path);
if(count($class_path) == 1 ) {
foreach(DIRS as $dir) {
$file = $dir . 'class-'. strtolower(str_replace('_', '-' , $class_name)) . '.php';
if(file_exists($file)) {
require_once($file);
}
}
}
elseif ($class_path[0] == 'Tainacan') {
$dir = strtolower(CLASSES_DIR.implode(DIRECTORY_SEPARATOR, array_slice($class_path, 1, count($class_path) -2) )).'/';
$dir = str_replace('_', '-', $dir);
$file = $dir . 'class-tainacan-'. strtolower(str_replace('_', '-' , $class_name)) . '.php';
if(file_exists($file)) {
require_once($file);
}
}
}
global $Tainacan_Collections;
$Tainacan_Collections = new \Tainacan\Repositories\Collections();
global $Tainacan_Item_Metadata;
$Tainacan_Item_Metadata = new \Tainacan\Repositories\Item_Metadata();
global $Tainacan_Metadatas;
$Tainacan_Metadatas = new \Tainacan\Repositories\Metadatas();
global $Tainacan_Filters;
$Tainacan_Filters = new \Tainacan\Repositories\Filters();
global $Tainacan_Taxonomies;
$Tainacan_Taxonomies = new \Tainacan\Repositories\Taxonomies();
global $Tainacan_Items;
$Tainacan_Items = new \Tainacan\Repositories\Items();
global $Tainacan_Terms;
$Tainacan_Terms = new \Tainacan\Repositories\Terms();
global $Tainacan_Logs;
$Tainacan_Logs = new \Tainacan\Repositories\Logs();
?>

View File

@ -10,80 +10,11 @@
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
const ENTITIES_DIR = __DIR__ . '/classes/entities/';
const FIELD_TYPES_DIR = __DIR__ . '/classes/field-types/';
const FILTER_TYPES_DIR = __DIR__ . '/classes/filter-types/';
const REPOSITORIES_DIR = __DIR__ . '/classes/repositories/';
const TRAITS_DIR = __DIR__ . '/classes/traits/';
const CLASSES_DIR = __DIR__ . '/classes/';
const VENDOR_DIR = __DIR__ . '/vendor/';
const ENDPOINTS_DIR = __DIR__ . '/api/endpoints/';
const API_DIR = __DIR__ . '/api/';
const CLASSES_DIR = __DIR__ . '/classes/';
const DIRS = [
CLASSES_DIR,
ENTITIES_DIR,
FIELD_TYPES_DIR,
FILTER_TYPES_DIR,
REPOSITORIES_DIR,
TRAITS_DIR,
];
require_once(VENDOR_DIR . 'autoload.php');
spl_autoload_register('tainacan_autoload');
function tainacan_autoload($class_name){
$class_path = explode('\\', $class_name);
$class_name = end($class_path);
if(count($class_path) == 1 ) {
foreach(DIRS as $dir) {
$file = $dir . 'class-'. strtolower(str_replace('_', '-' , $class_name)) . '.php';
if(file_exists($file)) {
require_once($file);
}
}
}
elseif ($class_path[0] == 'Tainacan') {
$dir = strtolower(CLASSES_DIR.implode(DIRECTORY_SEPARATOR, array_slice($class_path, 1, count($class_path) -2) )).'/';
$dir = str_replace('_', '-', $dir);
$file = $dir . 'class-tainacan-'. strtolower(str_replace('_', '-' , $class_name)) . '.php';
if(file_exists($file)) {
require_once($file);
}
}
}
global $Tainacan_Collections;
$Tainacan_Collections = new \Tainacan\Repositories\Collections();
global $Tainacan_Item_Metadata;
$Tainacan_Item_Metadata = new \Tainacan\Repositories\Item_Metadata();
global $Tainacan_Metadatas;
$Tainacan_Metadatas = new \Tainacan\Repositories\Metadatas();
global $Tainacan_Filters;
$Tainacan_Filters = new \Tainacan\Repositories\Filters();
global $Tainacan_Taxonomies;
$Tainacan_Taxonomies = new \Tainacan\Repositories\Taxonomies();
global $Tainacan_Items;
$Tainacan_Items = new \Tainacan\Repositories\Items();
global $Tainacan_Terms;
$Tainacan_Terms = new \Tainacan\Repositories\Terms();
global $Tainacan_Logs;
$Tainacan_Logs = new \Tainacan\Repositories\Logs();
require_once(ENDPOINTS_DIR . 'class-tainacan-rest-collections-controller.php');
$rest_collections_controller = new TAINACAN_REST_Collections_Controller();
require_once(CLASSES_DIR . 'tainacan-creator.php');
require_once(API_DIR . 'tainacan-rest-creator.php');
/**
*