From f66ed5c3f142cb5bff0cd430078e553deec7c0b5 Mon Sep 17 00:00:00 2001 From: Jacson Passold Date: Wed, 15 Nov 2017 16:50:11 -0200 Subject: [PATCH] convert code to namespaces basis --- src/class-tainacan.php | 48 ++++++++++++------- src/classes/class-tainacan-entity.php | 3 +- src/classes/class-tainacan-repository.php | 3 +- .../entities/class-tainacan-collection.php | 13 +++-- .../entities/class-tainacan-filter.php | 19 ++++---- .../class-tainacan-item-metadata-entity.php | 15 +++--- src/classes/entities/class-tainacan-item.php | 19 ++++---- src/classes/entities/class-tainacan-log.php | 15 +++--- .../entities/class-tainacan-metadata.php | 15 +++--- .../entities/class-tainacan-taxonomy.php | 13 +++-- src/classes/entities/class-tainacan-term.php | 11 +++-- .../class-tainacan-checkbox-field-type.php | 5 +- .../class-tainacan-date-field-type.php | 5 +- .../field-types/class-tainacan-field-type.php | 5 +- .../class-tainacan-numeric-field-type.php | 5 +- .../class-tainacan-radio-field-type.php | 5 +- ...class-tainacan-relationship-field-type.php | 5 +- .../class-tainacan-selectbox-field-type.php | 5 +- .../class-tainacan-text-field-type.php | 5 +- .../class-tainacan-textarea-field-type.php | 5 +- .../class-tainacan-filter-type.php | 5 +- .../class-tainacan-list-filter-type.php | 4 +- .../class-tainacan-range-filter-type.php | 5 +- .../class-tainacan-collections.php | 15 +++--- .../repositories/class-tainacan-filters.php | 17 ++++--- .../class-tainacan-item-metadata.php | 19 ++++---- .../repositories/class-tainacan-items.php | 17 ++++--- .../repositories/class-tainacan-logs.php | 12 +++-- .../repositories/class-tainacan-metadatas.php | 19 ++++---- .../class-tainacan-taxonomies.php | 15 +++--- .../repositories/class-tainacan-terms.php | 9 ++-- ...ss-tainacan-entity-collection-relation.php | 8 ++-- ...s-tainacan-entity-collections-relation.php | 4 +- tests/test-collections.php | 13 +++-- tests/test-filters.php | 21 ++++---- tests/test-item-metadata.php | 31 ++++++------ tests/test-items.php | 25 +++++----- tests/test-logs.php | 7 ++- tests/test-metadata.php | 15 +++--- tests/test-taxonomies.php | 6 +-- 40 files changed, 300 insertions(+), 186 deletions(-) diff --git a/src/class-tainacan.php b/src/class-tainacan.php index 1554f4867..0f2bd2871 100644 --- a/src/class-tainacan.php +++ b/src/class-tainacan.php @@ -29,40 +29,54 @@ require_once(VENDOR_DIR . 'autoload.php'); spl_autoload_register('tainacan_autoload'); function tainacan_autoload($class_name){ - foreach(DIRS as $dir){ - $file = $dir . 'class-'. strtolower(str_replace('_', '-' , $class_name)) . '.php'; - if(file_exists($file)){ - require_once($file); - } - // else if($class_name == 'Respect\Validation\Validator'){ - // requiere_once(VENDOR_DIR . 'autoload.php'); - // } - } + $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); + } + // else if($class_name == 'Respect\Validation\Validator'){ + // requiere_once(VENDOR_DIR . 'autoload.php'); + // } + } + } + 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); + //var_dump($dir); + $file = $dir . 'class-tainacan-'. strtolower(str_replace('_', '-' , $class_name)) . '.php'; + //var_dump($file); + if(file_exists($file)) { + require_once($file); + } + } } global $Tainacan_Collections; -$Tainacan_Collections = new Tainacan_Collections(); +$Tainacan_Collections = new \Tainacan\Repositories\Collections(); global $Tainacan_Item_Metadata; -$Tainacan_Item_Metadata = new Tainacan_Item_Metadata(); +$Tainacan_Item_Metadata = new \Tainacan\Repositories\Item_Metadata(); global $Tainacan_Metadatas; -$Tainacan_Metadatas = new Tainacan_Metadatas(); +$Tainacan_Metadatas = new \Tainacan\Repositories\Metadatas(); global $Tainacan_Filters; -$Tainacan_Filters = new Tainacan_Filters(); +$Tainacan_Filters = new \Tainacan\Repositories\Filters(); global $Tainacan_Taxonomies; -$Tainacan_Taxonomies = new Tainacan_Taxonomies(); +$Tainacan_Taxonomies = new \Tainacan\Repositories\Taxonomies(); global $Tainacan_Items; -$Tainacan_Items = new Tainacan_Items(); +$Tainacan_Items = new \Tainacan\Repositories\Items(); global $Tainacan_Terms; -$Tainacan_Terms = new Tainacan_Terms(); +$Tainacan_Terms = new \Tainacan\Repositories\Terms(); global $Tainacan_Logs; -$Tainacan_Logs = new Tainacan_Logs(); +$Tainacan_Logs = new \Tainacan\Repositories\Logs(); /** * diff --git a/src/classes/class-tainacan-entity.php b/src/classes/class-tainacan-entity.php index 03c5924f4..3a964cd0c 100644 --- a/src/classes/class-tainacan-entity.php +++ b/src/classes/class-tainacan-entity.php @@ -1,7 +1,8 @@ 0) { $post = get_post($which); - if ($post instanceof WP_Post) { + if ($post instanceof \WP_Post) { $this->WP_Post = get_post($which); } - } elseif ($which instanceof WP_Post) { + } elseif ($which instanceof \WP_Post) { $this->WP_Post = $which; } else { - $this->WP_Post = new StdClass(); + $this->WP_Post = new \StdClass(); } } @@ -97,7 +100,7 @@ class Tainacan_Collection extends Tainacan_Entity { // metadata function get_metadata() { - $Tainacan_Metadatas = new Tainacan_Metadatas(); + $Tainacan_Metadatas = new \Tainacan\Repositories\Metadatas(); return $Tainacan_Metadatas->get_metadata_by_collection($this); } diff --git a/src/classes/entities/class-tainacan-filter.php b/src/classes/entities/class-tainacan-filter.php index cf59cb582..187b58a7f 100644 --- a/src/classes/entities/class-tainacan-filter.php +++ b/src/classes/entities/class-tainacan-filter.php @@ -1,11 +1,14 @@ 0) { $post = get_post( $which ); - if ( $post instanceof WP_Post) { + if ( $post instanceof \WP_Post) { $this->WP_Post = get_post( $which ); } - } elseif ( $which instanceof WP_Post ) { + } elseif ( $which instanceof \WP_Post ) { $this->WP_Post = $which; } else { - $this->WP_Post = new StdClass(); + $this->WP_Post = new \StdClass(); } } @@ -45,7 +48,7 @@ class Tainacan_Filter extends Tainacan_Entity { function get_metadata() { $id = $this->get_mapped_property('metadata'); - return new Tainacan_Metadata( $id ); + return new \Tainacan\Entities\Metadata( $id ); } function get_filter_type_object(){ @@ -77,12 +80,12 @@ class Tainacan_Filter extends Tainacan_Entity { * @param Tainacan_Metadata / int $value */ function set_metadata( $value ){ - $id = ( $value instanceof Tainacan_Metadata ) ? $value->get_id() : $value; + $id = ( $value instanceof \Tainacan\Entities\Metadata ) ? $value->get_id() : $value; return $this->set_mapped_property('metadata', $id); } - function set_filter_type_object( Tainacan_Filter_Type $value ){ + function set_filter_type_object( \Tainacan\Filter_Types\Filter_Type $value ){ // TODO: validate primitive type with filter //if filter matches the metadata type //if( in_array( $type->get_primitive_type(), $value->get_supported_types() ) ){ diff --git a/src/classes/entities/class-tainacan-item-metadata-entity.php b/src/classes/entities/class-tainacan-item-metadata-entity.php index b73497a0e..db47ad2f8 100644 --- a/src/classes/entities/class-tainacan-item-metadata-entity.php +++ b/src/classes/entities/class-tainacan-item-metadata-entity.php @@ -1,11 +1,14 @@ repository = 'Tainacan_Item_Metadata'; @@ -13,7 +16,7 @@ class Tainacan_Item_Metadata_Entity extends Tainacan_Entity { $this->set_metadata($metadata); } - function set_item(Tainacan_Item $item) { + function set_item(Item $item) { $this->item = $item; } @@ -21,7 +24,7 @@ class Tainacan_Item_Metadata_Entity extends Tainacan_Entity { $this->value = $value; } - function set_metadata(Tainacan_Metadata $metadata) { + function set_metadata(Metadata $metadata) { $this->metadata = $metadata; } @@ -37,7 +40,7 @@ class Tainacan_Item_Metadata_Entity extends Tainacan_Entity { if (isset($this->value)) return $this->value; - $Tainacan_Item_Metadata = new Tainacan_Item_Metadata(); + $Tainacan_Item_Metadata = new Item_Metadata_Entity(); return $Tainacan_Item_Metadata->get_item_metadata_value($this); } @@ -102,7 +105,7 @@ class Tainacan_Item_Metadata_Entity extends Tainacan_Entity { } else { if ($this->is_collection_key()) { - $Tainacan_Items = new Tainacan_Items(); + $Tainacan_Items = new \Tainacan\Repositories\Items(); $test = $Tainacan_Items->query([ 'collections' => $item->get_collection(), diff --git a/src/classes/entities/class-tainacan-item.php b/src/classes/entities/class-tainacan-item.php index 036c8e989..3c49adf8f 100644 --- a/src/classes/entities/class-tainacan-item.php +++ b/src/classes/entities/class-tainacan-item.php @@ -1,11 +1,14 @@ 0) { $post = get_post($which); - if ($post instanceof WP_Post) { + if ($post instanceof \WP_Post) { $this->WP_Post = get_post($which); } - } elseif ($which instanceof WP_Post) { + } elseif ($which instanceof \WP_Post) { $this->WP_Post = $which; } else { - $this->WP_Post = new StdClass(); + $this->WP_Post = new \StdClass(); } } @@ -67,16 +70,16 @@ class Tainacan_Item extends Tainacan_Entity { $metaList = $collection->get_metadata(); foreach ($metaList as $meta) { - $return[$meta->get_id()] = new Tainacan_Item_Metadata_Entity($this, $meta); + $return[$meta->get_id()] = new Item_Metadata_Entity($this, $meta); } } return $return; } - function add_metadata(Tainacan_Metadata $new_metadata, $value) { + function add_metadata(Metadata $new_metadata, $value) { //TODO Multiple metadata must receive an array as value - $item_metadata = new Tainacan_Item_Metadata_Entity($this, $new_metadata); + $item_metadata = new Item_Metadata_Entity($this, $new_metadata); $item_metadata->set_value($value); $current_meta = $this->get_metadata(); $current_meta[$new_metadata->get_id()] = $item_metadata; diff --git a/src/classes/entities/class-tainacan-log.php b/src/classes/entities/class-tainacan-log.php index 19e7886b9..c22f5d278 100644 --- a/src/classes/entities/class-tainacan-log.php +++ b/src/classes/entities/class-tainacan-log.php @@ -1,13 +1,12 @@ 0) { $post = get_post($which); - if ($post instanceof WP_Post) { + if ($post instanceof \WP_Post) { $this->WP_Post = get_post($which); } - } elseif ($which instanceof WP_Post) { + } elseif ($which instanceof \WP_Post) { $this->WP_Post = $which; } else { - $this->WP_Post = new StdClass(); + $this->WP_Post = new \StdClass(); } } diff --git a/src/classes/entities/class-tainacan-metadata.php b/src/classes/entities/class-tainacan-metadata.php index 6e229748f..5e3a25f8d 100644 --- a/src/classes/entities/class-tainacan-metadata.php +++ b/src/classes/entities/class-tainacan-metadata.php @@ -1,11 +1,14 @@ 0) { $post = get_post( $which ); - if ( $post instanceof WP_Post) { + if ( $post instanceof \WP_Post) { $this->WP_Post = get_post( $which ); } - } elseif ( $which instanceof WP_Post ) { + } elseif ( $which instanceof \WP_Post ) { $this->WP_Post = $which; } else { - $this->WP_Post = new StdClass(); + $this->WP_Post = new \StdClass(); } } @@ -128,7 +131,7 @@ class Tainacan_Metadata extends Tainacan_Entity { return $this->set_mapped_property('default_property', $value); } - function set_field_type_object(Tainacan_Field_Type $value){ + function set_field_type_object(\Tainacan\Field_Types\Field_Type $value){ $this->set_field_type( get_class( $value ) ); return $this->set_mapped_property('field_type_object', serialize($value) ) ; } diff --git a/src/classes/entities/class-tainacan-taxonomy.php b/src/classes/entities/class-tainacan-taxonomy.php index 06c027782..bafca6d2b 100644 --- a/src/classes/entities/class-tainacan-taxonomy.php +++ b/src/classes/entities/class-tainacan-taxonomy.php @@ -1,11 +1,14 @@ 0) { $post = get_post( $which ); - if ( $post instanceof WP_Post) { + if ( $post instanceof \WP_Post) { $this->WP_Post = get_post( $which ); } - } elseif ( $which instanceof WP_Post ) { + } elseif ( $which instanceof \WP_Post ) { $this->WP_Post = $which; } else { - $this->WP_Post = new StdClass(); + $this->WP_Post = new \StdClass(); } } diff --git a/src/classes/entities/class-tainacan-term.php b/src/classes/entities/class-tainacan-term.php index 576ba4e57..cc86b401d 100644 --- a/src/classes/entities/class-tainacan-term.php +++ b/src/classes/entities/class-tainacan-term.php @@ -1,9 +1,12 @@ 0) { $post = get_term_by('id', $which, $taxonomy); - if ( $post instanceof WP_Term) { + if ( $post instanceof \WP_Term) { $this->WP_Term = get_term_by('id', $which, $taxonomy); } - } elseif ( $which instanceof WP_Term ) { + } elseif ( $which instanceof \WP_Term ) { $this->WP_Term = $which; } else { - $this->WP_Term = new StdClass(); + $this->WP_Term = new \StdClass(); } } diff --git a/src/classes/field-types/class-tainacan-checkbox-field-type.php b/src/classes/field-types/class-tainacan-checkbox-field-type.php index c2c89f257..3c5baa65c 100644 --- a/src/classes/field-types/class-tainacan-checkbox-field-type.php +++ b/src/classes/field-types/class-tainacan-checkbox-field-type.php @@ -1,4 +1,7 @@ primitive_type = 'date'; diff --git a/src/classes/field-types/class-tainacan-date-field-type.php b/src/classes/field-types/class-tainacan-date-field-type.php index a8110346d..f9d3d7018 100644 --- a/src/classes/field-types/class-tainacan-date-field-type.php +++ b/src/classes/field-types/class-tainacan-date-field-type.php @@ -1,4 +1,7 @@ primitive_type = 'date'; diff --git a/src/classes/field-types/class-tainacan-field-type.php b/src/classes/field-types/class-tainacan-field-type.php index 023419c45..2d84c88b4 100644 --- a/src/classes/field-types/class-tainacan-field-type.php +++ b/src/classes/field-types/class-tainacan-field-type.php @@ -1,4 +1,7 @@ primitive_type = 'float'; diff --git a/src/classes/field-types/class-tainacan-radio-field-type.php b/src/classes/field-types/class-tainacan-radio-field-type.php index 2ce19e1aa..bb7a51215 100644 --- a/src/classes/field-types/class-tainacan-radio-field-type.php +++ b/src/classes/field-types/class-tainacan-radio-field-type.php @@ -1,4 +1,7 @@ primitive_type = ''; diff --git a/src/classes/field-types/class-tainacan-relationship-field-type.php b/src/classes/field-types/class-tainacan-relationship-field-type.php index 1b688f2cd..7d2651c0b 100644 --- a/src/classes/field-types/class-tainacan-relationship-field-type.php +++ b/src/classes/field-types/class-tainacan-relationship-field-type.php @@ -1,4 +1,7 @@ primitive_type = ''; diff --git a/src/classes/field-types/class-tainacan-selectbox-field-type.php b/src/classes/field-types/class-tainacan-selectbox-field-type.php index 7b716019a..5a120b22e 100644 --- a/src/classes/field-types/class-tainacan-selectbox-field-type.php +++ b/src/classes/field-types/class-tainacan-selectbox-field-type.php @@ -1,4 +1,7 @@ primitive_type = ''; diff --git a/src/classes/field-types/class-tainacan-text-field-type.php b/src/classes/field-types/class-tainacan-text-field-type.php index 8ea57ee7a..cf21206c4 100644 --- a/src/classes/field-types/class-tainacan-text-field-type.php +++ b/src/classes/field-types/class-tainacan-text-field-type.php @@ -1,4 +1,7 @@ primitive_type = 'string'; diff --git a/src/classes/field-types/class-tainacan-textarea-field-type.php b/src/classes/field-types/class-tainacan-textarea-field-type.php index 74ec1a037..d46c9b1bb 100644 --- a/src/classes/field-types/class-tainacan-textarea-field-type.php +++ b/src/classes/field-types/class-tainacan-textarea-field-type.php @@ -1,4 +1,7 @@ primitive_type = 'string'; diff --git a/src/classes/filter-types/class-tainacan-filter-type.php b/src/classes/filter-types/class-tainacan-filter-type.php index 016b9dcba..647ef6a4d 100644 --- a/src/classes/filter-types/class-tainacan-filter-type.php +++ b/src/classes/filter-types/class-tainacan-filter-type.php @@ -1,9 +1,12 @@ supported_types[] = 'string'; diff --git a/src/classes/filter-types/class-tainacan-range-filter-type.php b/src/classes/filter-types/class-tainacan-range-filter-type.php index 8ead1feec..74192ef1f 100644 --- a/src/classes/filter-types/class-tainacan-range-filter-type.php +++ b/src/classes/filter-types/class-tainacan-range-filter-type.php @@ -1,4 +1,7 @@ supported_types = ['float','date']; diff --git a/src/classes/repositories/class-tainacan-collections.php b/src/classes/repositories/class-tainacan-collections.php index cfcb44728..84e8fce27 100644 --- a/src/classes/repositories/class-tainacan-collections.php +++ b/src/classes/repositories/class-tainacan-collections.php @@ -1,11 +1,14 @@ validate()) @@ -135,7 +138,7 @@ class Tainacan_Collections { $collection->register_post_type(); // return a brand new object - return new Tainacan_Collection($collection->WP_Post); + return new \Tainacan\Entities\Collection($collection->WP_Post); } function get_collections($args = array()) { @@ -151,7 +154,7 @@ class Tainacan_Collections { $return = []; foreach ($posts as $post) { - $return[] = new Tainacan_Collection($post); + $return[] = new \Tainacan\Entities\Collection($post); } // TODO: Pegar coleções registradas via código @@ -160,7 +163,7 @@ class Tainacan_Collections { } function get_collection_by_id($id) { - return new Tainacan_Collection($id); + return new \Tainacan\Entities\Collection($id); } diff --git a/src/classes/repositories/class-tainacan-filters.php b/src/classes/repositories/class-tainacan-filters.php index f7b8cfdb2..07d4797e0 100644 --- a/src/classes/repositories/class-tainacan-filters.php +++ b/src/classes/repositories/class-tainacan-filters.php @@ -1,9 +1,12 @@ get_map(); foreach ($map as $prop => $mapped) { @@ -122,7 +125,7 @@ class Tainacan_Filters { } // return a brand new object - return new Tainacan_Filter($metadata->WP_Post); + return new \Tainacan\Entities\Filter($metadata->WP_Post); } @@ -145,17 +148,17 @@ class Tainacan_Filters { 'meta_value' => $collection_id ], $args); - $wp_query = new WP_Query($args); + $wp_query = new \WP_Query($args); return $wp_query; } /** * @param int $id - * @return Tainacan_Filter + * @return \Tainacan\Entities\Filter */ function get_filter_by_id($id) { - return new Tainacan_Filter($id); + return new \Tainacan\Entities\Filter($id); } /** diff --git a/src/classes/repositories/class-tainacan-item-metadata.php b/src/classes/repositories/class-tainacan-item-metadata.php index 4af3da5ae..b5efb59db 100644 --- a/src/classes/repositories/class-tainacan-item-metadata.php +++ b/src/classes/repositories/class-tainacan-item-metadata.php @@ -1,18 +1,19 @@ get_collection(); - if (!$collection instanceof Tainacan_Collection){ + if (!$collection instanceof \Tainacan\Entities\Collection){ return []; } @@ -22,7 +23,7 @@ class Tainacan_Item_Metadata { if (is_array($meta_list)) { foreach ($meta_list as $meta) { - $return = new Tainacan_Item_Metadata_Entity($item, $meta); + $return = new \Tainacan\Entities\Item_Metadata_Entity($item, $meta); } } @@ -30,7 +31,7 @@ class Tainacan_Item_Metadata { } - function insert(Tainacan_Item_Metadata_Entity $item_metadata) { + function insert(\Tainacan\Entities\Item_Metadata_Entity $item_metadata) { $unique = ! $item_metadata->is_multiple(); @@ -47,11 +48,11 @@ class Tainacan_Item_Metadata { } // return a brand new object - return new Tainacan_Item_Metadata_Entity($item_metadata->get_item(), $item_metadata->get_metadata()); + return new \Tainacan\Entities\Item_Metadata_Entity($item_metadata->get_item(), $item_metadata->get_metadata()); } - function get_item_metadata_value(Tainacan_Item_Metadata_Entity $item_metadata) { + function get_item_metadata_value(\Tainacan\Entities\Item_Metadata_Entity $item_metadata) { $unique = ! $item_metadata->is_multiple(); diff --git a/src/classes/repositories/class-tainacan-items.php b/src/classes/repositories/class-tainacan-items.php index 061b57e75..9745dba0a 100644 --- a/src/classes/repositories/class-tainacan-items.php +++ b/src/classes/repositories/class-tainacan-items.php @@ -1,9 +1,12 @@ get_map(); // get collection to determine post type @@ -107,7 +110,7 @@ class Tainacan_Items { } // return a brand new object - return new Tainacan_Item($item->WP_Post); + return new \Tainacan\Entities\Item($item->WP_Post); } // collections id or array of ids; collection object or array of objects @@ -123,7 +126,7 @@ class Tainacan_Items { $collections = $Tainacan_Collections->get_collection_by_id($collection); } - if ($collections instanceof Tainacan_Collection) { + if ($collections instanceof \Tainacan\Entities\Collection) { $cpt = $collections->get_db_identifier(); } elseif (is_array($collections)) { $cpt = []; @@ -132,7 +135,7 @@ class Tainacan_Items { if (is_numeric($collection)){ $collection = $Tainacan_Collections->get_collection_by_id($collection); } - if ($collection instanceof Tainacan_Collection){ + if ($collection instanceof \Tainacan\Entities\Collection){ $cpt[] = $collection->get_db_identifier(); } } @@ -156,7 +159,7 @@ class Tainacan_Items { $return = []; foreach ($posts as $post) { - $return[] = new Tainacan_Item($post); + $return[] = new \Tainacan\Entities\Item($post); } return $return; @@ -211,6 +214,6 @@ class Tainacan_Items { } function get_item_by_id($id) { - return new Tainacan_Item($id); + return new \Tainacan\Entities\Item($id); } } \ No newline at end of file diff --git a/src/classes/repositories/class-tainacan-logs.php b/src/classes/repositories/class-tainacan-logs.php index e1fb0f59c..6d338c9b1 100644 --- a/src/classes/repositories/class-tainacan-logs.php +++ b/src/classes/repositories/class-tainacan-logs.php @@ -1,11 +1,13 @@ get_map(); foreach ($map as $prop => $mapped) { @@ -118,7 +120,7 @@ class Tainacan_Logs extends Tainacan_Repository { }*/ // return a brand new object - return new Tainacan_Log($log->WP_Post); + return new \Tainacan\Entities\Log($log->WP_Post); } function get_logs($args = array()) { @@ -134,7 +136,7 @@ class Tainacan_Logs extends Tainacan_Repository { $return = []; foreach ($posts as $post) { - $return[] = new Tainacan_Log($post); + $return[] = new \Tainacan\Entities\Log($post); } // TODO: Pegar coleções registradas via código @@ -143,7 +145,7 @@ class Tainacan_Logs extends Tainacan_Repository { } function get_log_by_id($id) { - return new Tainacan_Log($id); + return new \Tainacan\Entities\Log($id); } diff --git a/src/classes/repositories/class-tainacan-metadatas.php b/src/classes/repositories/class-tainacan-metadatas.php index 1b78cace2..a28e5feff 100644 --- a/src/classes/repositories/class-tainacan-metadatas.php +++ b/src/classes/repositories/class-tainacan-metadatas.php @@ -1,12 +1,15 @@ get_map(); foreach ($map as $prop => $mapped) { @@ -158,7 +161,7 @@ class Tainacan_Metadatas { } // return a brand new object - return new Tainacan_Metadata($metadata->WP_Post); + return new \Tainacan\Entities\Metadata($metadata->WP_Post); } /** @@ -185,7 +188,7 @@ class Tainacan_Metadatas { $return = []; foreach ($posts as $post) { - $return[] = new Tainacan_Metadata($post); + $return[] = new \Tainacan\Entities\Metadata($post); } return $return; @@ -193,9 +196,9 @@ class Tainacan_Metadatas { /** * @param int $id - * @return Tainacan_Metadata + * @return \Tainacan\Entities\Metadata */ function get_metadata_by_id($id) { - return new Tainacan_Metadata($id); + return new \Tainacan\Entities\Metadata($id); } } \ No newline at end of file diff --git a/src/classes/repositories/class-tainacan-taxonomies.php b/src/classes/repositories/class-tainacan-taxonomies.php index cb0a26139..a6eacd541 100644 --- a/src/classes/repositories/class-tainacan-taxonomies.php +++ b/src/classes/repositories/class-tainacan-taxonomies.php @@ -1,4 +1,7 @@ get_map(); foreach ($map as $prop => $mapped) { @@ -144,7 +147,7 @@ class Tainacan_Taxonomies { $taxonomy->register_taxonomy(); // return a brand new object - return new Tainacan_Taxonomy($taxonomy->WP_Post); + return new\Tainacan\Entities\Taxonomy($taxonomy->WP_Post); } function registerTainacanTaxonomy( $taxonomy_name ){ @@ -173,6 +176,6 @@ class Tainacan_Taxonomies { } function get_taxonomy_by_id($id) { - return new Tainacan_Taxonomy($id); + return new \Tainacan\Entities\Taxonomy($id); } } \ No newline at end of file diff --git a/src/classes/repositories/class-tainacan-terms.php b/src/classes/repositories/class-tainacan-terms.php index 808abd267..3cb8b72cf 100644 --- a/src/classes/repositories/class-tainacan-terms.php +++ b/src/classes/repositories/class-tainacan-terms.php @@ -1,4 +1,7 @@ get_map(); foreach ($map as $prop => $mapped) { @@ -69,7 +72,7 @@ class Tainacan_Terms { function get_term_by($field,$value,$taxonomy){ $wp_term = get_term_by($field,$value,$taxonomy); - $tainacan_term = new Tainacan_Term( $wp_term ); + $tainacan_term = new \Tainacan\Entities\Term( $wp_term ); $tainacan_term->set_user( get_term_meta($tainacan_term->get_id() , 'user', true ) ); return $tainacan_term; diff --git a/src/classes/traits/class-tainacan-entity-collection-relation.php b/src/classes/traits/class-tainacan-entity-collection-relation.php index 4768f80bc..bda597b3a 100644 --- a/src/classes/traits/class-tainacan-entity-collection-relation.php +++ b/src/classes/traits/class-tainacan-entity-collection-relation.php @@ -1,15 +1,17 @@ get_mapped_property('collection_id'); } function get_collection() { - if (isset($this->collection) && $this->collection instanceof Tainacan_Collection) + if (isset($this->collection) && $this->collection instanceof \Tainacan\Entities\Collection) return $this->collection; if (is_numeric($this->get_collection_id())) { @@ -27,7 +29,7 @@ trait Tainacan_Entity_Collection_Relation { return $this->set_mapped_property('collection_id', $value); } - function set_collection(Tainacan_Collection $collection) { + function set_collection(\Tainacan\Entities\Collection $collection) { $this->collection = $collection; $this->set_collection_id($collection->get_id()); } diff --git a/src/classes/traits/class-tainacan-entity-collections-relation.php b/src/classes/traits/class-tainacan-entity-collections-relation.php index d15eb73af..e890e7c05 100644 --- a/src/classes/traits/class-tainacan-entity-collections-relation.php +++ b/src/classes/traits/class-tainacan-entity-collections-relation.php @@ -1,8 +1,10 @@ get_mapped_property('collections_ids'); diff --git a/tests/test-collections.php b/tests/test-collections.php index 2d6b95210..8ebcd82ae 100644 --- a/tests/test-collections.php +++ b/tests/test-collections.php @@ -1,4 +1,7 @@ set_name('teste'); $x->set_description('adasdasdsa'); @@ -39,7 +42,7 @@ class Test_Collections extends WP_UnitTestCase { function test_item() { - $x = new Tainacan_Collection(); + $x = new \Tainacan\Entities\Collection(); $x->set_name('teste'); $x->set_description('adasdasdsa'); @@ -52,7 +55,7 @@ class Test_Collections extends WP_UnitTestCase { - $i = new Tainacan_Item(); + $i = new \Tainacan\Entities\Item(); $i->set_title('item teste'); $i->set_description('adasdasdsa'); @@ -71,7 +74,7 @@ class Test_Collections extends WP_UnitTestCase { function test_validation() { - $x = new Tainacan_Collection(); + $x = new \Tainacan\Entities\Collection(); $x->set_name('teste'); $x->set_description('adasdasdsa'); diff --git a/tests/test-filters.php b/tests/test-filters.php index 2e8077952..8d5a3ee00 100644 --- a/tests/test-filters.php +++ b/tests/test-filters.php @@ -1,4 +1,7 @@ set_name('teste'); $collection = $Tainacan_Collections->insert($collection); @@ -36,12 +39,12 @@ class Test_Filters extends WP_UnitTestCase { function test_add_with_metadata_and_type(){ global $Tainacan_Collections, $Tainacan_Filters,$Tainacan_Metadatas; - $collection = new Tainacan_Collection(); - $metadata = new Tainacan_Metadata(); - $filter = new Tainacan_Filter(); - $type = new Tainacan_Text_Field_Type(); - $filter_list_type = new Tainacan_List_Filter_Type(); - $filter_range_type = new Tainacan_Range_Filter_Type(); + $collection = new \Tainacan\Entities\Collection(); + $metadata = new \Tainacan\Entities\Metadata(); + $filter = new \Tainacan\Entities\Filter(); + $type = new \Tainacan\Field_Types\Text_Field_Type(); + $filter_list_type = new \Tainacan\Filter_Types\List_Filter_Type(); + $filter_range_type = new \Tainacan\Filter_Types\Range_Filter_Type(); $collection->set_name('teste'); $collection = $Tainacan_Collections->insert($collection); diff --git a/tests/test-item-metadata.php b/tests/test-item-metadata.php index 7d9b1e0f9..bec45b253 100644 --- a/tests/test-item-metadata.php +++ b/tests/test-item-metadata.php @@ -1,4 +1,7 @@ set_name('teste'); $collection = $Tainacan_Collections->insert($collection); @@ -33,7 +36,7 @@ class Test_Item_Metadata extends WP_UnitTestCase { $test = $Tainacan_Metadatas->get_metadata_by_id($metadata->get_id()); - $i = new Tainacan_Item(); + $i = new \Tainacan\Entities\Item(); $i->set_title('item teste'); $i->set_description('adasdasdsa'); @@ -44,7 +47,7 @@ class Test_Item_Metadata extends WP_UnitTestCase { $item = $Tainacan_Items->get_item_by_id($item->get_id()); - $item_metadata = new Tainacan_Item_Metadata_Entity($item, $metadata); + $item_metadata = new \Tainacan\Entities\Item_Metadata_Entity($item, $metadata); $item_metadata->set_value('teste_value'); @@ -62,8 +65,8 @@ class Test_Item_Metadata extends WP_UnitTestCase { function teste_required(){ global $Tainacan_Collections, $Tainacan_Metadatas, $Tainacan_Item_Metadata; - $collection = new Tainacan_Collection(); - $metadata = new Tainacan_Metadata(); + $collection = new \Tainacan\Entities\Collection(); + $metadata = new \Tainacan\Entities\Metadata(); $collection->set_name('teste'); $collection = $Tainacan_Collections->insert($collection); @@ -79,7 +82,7 @@ class Test_Item_Metadata extends WP_UnitTestCase { $test = $Tainacan_Metadatas->get_metadata_by_id($metadata->get_id()); - $i = new Tainacan_Item(); + $i = new \Tainacan\Entities\Item(); $i->set_title('item teste'); $i->set_description('adasdasdsa'); @@ -90,7 +93,7 @@ class Test_Item_Metadata extends WP_UnitTestCase { $item = $Tainacan_Items->get_item_by_id($item->get_id()); - $item_metadata = new Tainacan_Item_Metadata_Entity($item, $metadata); + $item_metadata = new \Tainacan\Entities\Item_Metadata_Entity($item, $metadata); // false because its required $this->assertFalse($item_metadata->validate()); @@ -107,8 +110,8 @@ class Test_Item_Metadata extends WP_UnitTestCase { function teste_collection_key(){ global $Tainacan_Collections, $Tainacan_Metadatas, $Tainacan_Item_Metadata; - $collection = new Tainacan_Collection(); - $metadata = new Tainacan_Metadata(); + $collection = new \Tainacan\Entities\Collection(); + $metadata = new \Tainacan\Entities\Metadata(); $collection->set_name('teste'); $collection = $Tainacan_Collections->insert($collection); @@ -124,7 +127,7 @@ class Test_Item_Metadata extends WP_UnitTestCase { $test = $Tainacan_Metadatas->get_metadata_by_id($metadata->get_id()); - $i = new Tainacan_Item(); + $i = new \Tainacan\Entities\Item(); $i->set_title('item teste'); $i->set_description('adasdasdsa'); @@ -139,12 +142,12 @@ class Test_Item_Metadata extends WP_UnitTestCase { $value = 'teste_val'; - $item_metadata = new Tainacan_Item_Metadata_Entity($item, $metadata); + $item_metadata = new \Tainacan\Entities\Item_Metadata_Entity($item, $metadata); $item_metadata->set_value($value); $this->assertTrue($item_metadata->validate()); $item_metadata = $Tainacan_Item_Metadata->insert($item_metadata); - $n_item_metadata = new Tainacan_Item_Metadata_Entity($item, $metadata); + $n_item_metadata = new \Tainacan\Entities\Item_Metadata_Entity($item, $metadata); $n_item_metadata->set_value($value); $this->assertFalse($n_item_metadata->validate()); } diff --git a/tests/test-items.php b/tests/test-items.php index f4e613f48..02168876e 100644 --- a/tests/test-items.php +++ b/tests/test-items.php @@ -1,4 +1,7 @@ set_name('teste'); $collection = $Tainacan_Collections->insert($collection); $collection2->set_name('teste2'); $collection2 = $Tainacan_Collections->insert($collection2); - $metadata = new Tainacan_Metadata(); - $metadata2 = new Tainacan_Metadata(); - $metadata3 = new Tainacan_Metadata(); + $metadata = new \Tainacan\Entities\Metadata(); + $metadata2 = new \Tainacan\Entities\Metadata(); + $metadata3 = new \Tainacan\Entities\Metadata(); $metadata->set_name('metadado'); $metadata->set_collection( $collection ); @@ -37,7 +40,7 @@ class Test_Items extends WP_UnitTestCase { $metadata3 = $Tainacan_Metadatas->insert($metadata3); global $Tainacan_Items; - $i = new Tainacan_Item(); + $i = new \Tainacan\Entities\Item(); $i->set_title('orange'); $i->set_collection($collection); $i->add_metadata($metadata, 'value_1'); @@ -47,17 +50,17 @@ class Test_Items extends WP_UnitTestCase { $meta_test = $item->get_metadata(); $this->assertTrue( isset($meta_test[$metadata->get_id()]) ); - $this->assertTrue( $meta_test[$metadata->get_id()] instanceof Tainacan_Item_Metadata_Entity ); + $this->assertTrue( $meta_test[$metadata->get_id()] instanceof \Tainacan\Entities\Item_Metadata_Entity ); $this->assertEquals( $meta_test[$metadata->get_id()]->get_value(), 'value_1'); - $i = new Tainacan_Item(); + $i = new \Tainacan\Entities\Item(); $i->set_title('apple'); $i->set_collection($collection2); $i->add_metadata($metadata2, 'value_2'); $i->add_metadata($metadata3, 'value_2'); $item = $Tainacan_Items->insert($i); - $i = new Tainacan_Item(); + $i = new \Tainacan\Entities\Item(); $i->set_title('lemon'); $i->set_collection($collection2); $i->add_metadata($metadata2, 'value_2'); @@ -65,7 +68,7 @@ class Test_Items extends WP_UnitTestCase { $i->add_metadata($metadata3, 'value_3'); $item = $Tainacan_Items->insert($i); - $i = new Tainacan_Item(); + $i = new \Tainacan\Entities\Item(); $i->set_title('pinapple'); $i->set_collection($collection2); $i->add_metadata($metadata2, 'value_3'); diff --git a/tests/test-logs.php b/tests/test-logs.php index 101882272..01f58f7f8 100644 --- a/tests/test-logs.php +++ b/tests/test-logs.php @@ -1,4 +1,7 @@ set_title('blame someone'); diff --git a/tests/test-metadata.php b/tests/test-metadata.php index 1fa43a05b..602fc43c3 100644 --- a/tests/test-metadata.php +++ b/tests/test-metadata.php @@ -1,4 +1,7 @@ set_name('teste'); $collection = $Tainacan_Collections->insert($collection); @@ -44,9 +47,9 @@ class Test_Metadata extends WP_UnitTestCase { function teste_add_type(){ global $Tainacan_Collections, $Tainacan_Metadatas; - $collection = new Tainacan_Collection(); - $metadata = new Tainacan_Metadata(); - $type = new Tainacan_Text_Field_Type(); + $collection = new \Tainacan\Entities\Collection(); + $metadata = new \Tainacan\Entities\Metadata(); + $type = new \Tainacan\Field_Types\Text_Field_Type(); $collection->set_name('teste'); $collection = $Tainacan_Collections->insert($collection); diff --git a/tests/test-taxonomies.php b/tests/test-taxonomies.php index 6ea064c39..0fedf7015 100644 --- a/tests/test-taxonomies.php +++ b/tests/test-taxonomies.php @@ -17,7 +17,7 @@ class Test_Taxonomies extends WP_UnitTestCase { function test_add() { global $Tainacan_Taxonomies; - $taxonomy = new Tainacan_Taxonomy(); + $taxonomy = new \Tainacan\Entities\Taxonomy(); //setando os valores na classe do tainacan $taxonomy->set_name('genero'); @@ -38,8 +38,8 @@ class Test_Taxonomies extends WP_UnitTestCase { function test_add_term_taxonomy(){ global $Tainacan_Taxonomies, $Tainacan_Terms; - $taxonomy = new Tainacan_Taxonomy(); - $term = new Tainacan_Term(); + $taxonomy = new \Tainacan\Entities\Taxonomy(); + $term = new \Tainacan\Entities\Term(); //setando os valores na classe de taxonomia $taxonomy->set_name('genero');