| 1 |
<?php |
| 2 |
namespace Depicter\DataSources; |
| 3 |
|
| 4 |
use Depicter\DataSources\Tags\Manager as TagsManager; |
| 5 |
|
| 6 |
/** |
| 7 |
* Chained api to access all data sources |
| 8 |
*/ |
| 9 |
class Manager { |
| 10 |
|
| 11 |
/** |
| 12 |
* Returns the instance of posts class |
| 13 |
* |
| 14 |
* @return Posts |
| 15 |
*/ |
| 16 |
public function posts(): Posts { |
| 17 |
return \Depicter::resolve('depicter.dataSources.posts'); |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* Returns the instance of products class |
| 22 |
* |
| 23 |
* @return Products |
| 24 |
*/ |
| 25 |
public function products(): Products { |
| 26 |
return \Depicter::resolve('depicter.dataSources.products'); |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Returns the instance of handpicked products class |
| 31 |
* |
| 32 |
* @return HandPickedProducts |
| 33 |
*/ |
| 34 |
public function handPickedProducts(): HandPickedProducts { |
| 35 |
return \Depicter::resolve('depicter.dataSources.handPickedProducts'); |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Returns the instance of tags Manager class |
| 40 |
* |
| 41 |
* @return TagsManager |
| 42 |
*/ |
| 43 |
public function tagsManager(): TagsManager { |
| 44 |
return \Depicter::resolve('depicter.dataSources.tags.manager'); |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Get DataSource instance by type |
| 49 |
* |
| 50 |
* @param string $type |
| 51 |
* |
| 52 |
* @return DataSourceInterface |
| 53 |
*/ |
| 54 |
public function getByType( string $type ){ |
| 55 |
$result = $this->posts(); |
| 56 |
|
| 57 |
switch ( $type ) { |
| 58 |
|
| 59 |
case 'wpPost': |
| 60 |
case 'wpPostHandpicked': |
| 61 |
case 'wpPage': |
| 62 |
case 'wpPageHandpicked': |
| 63 |
case 'wpCPT': |
| 64 |
$result = $this->posts(); |
| 65 |
break; |
| 66 |
|
| 67 |
case 'wooProduct': |
| 68 |
case 'wooProducts': |
| 69 |
$result = $this->products(); |
| 70 |
break; |
| 71 |
|
| 72 |
case 'wooHandpicked': |
| 73 |
$result = $this->handPickedProducts(); |
| 74 |
break; |
| 75 |
|
| 76 |
case 'catalogs': |
| 77 |
$result = \Depicter::resolve('depicter.dataSources.catalogs'); |
| 78 |
break; |
| 79 |
|
| 80 |
default: |
| 81 |
break; |
| 82 |
} |
| 83 |
|
| 84 |
return $result; |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* Get post type by DataSource type |
| 89 |
* |
| 90 |
* @param string $type |
| 91 |
* |
| 92 |
* @return string |
| 93 |
*/ |
| 94 |
public function getPostTypeByType( string $type ){ |
| 95 |
$result = ''; |
| 96 |
|
| 97 |
switch ( $type ) { |
| 98 |
|
| 99 |
case 'wpPost': |
| 100 |
case 'wpPostHandpicked': |
| 101 |
case 'wpCPT': |
| 102 |
$result = 'post'; |
| 103 |
break; |
| 104 |
|
| 105 |
case 'wpPage': |
| 106 |
case 'wpPageHandpicked': |
| 107 |
$result = 'page'; |
| 108 |
break; |
| 109 |
|
| 110 |
case 'wooProduct': |
| 111 |
case 'wooProducts': |
| 112 |
case 'wooHandpicked': |
| 113 |
$result = 'product'; |
| 114 |
break; |
| 115 |
|
| 116 |
default: |
| 117 |
break; |
| 118 |
} |
| 119 |
|
| 120 |
return $result; |
| 121 |
} |
| 122 |
|
| 123 |
} |
| 124 |
|