Area.php
79 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * ====================================================================== |
| 5 | * LICENSE: This file is subject to the terms and conditions defined in * |
| 6 | * file 'license.txt', which is part of this source code package. * |
| 7 | * ====================================================================== |
| 8 | */ |
| 9 | |
| 10 | /** |
| 11 | * AAM core API Area class |
| 12 | * |
| 13 | * This class defines what area AAM is operating on. Can be backend, frontend, rest |
| 14 | * etc. |
| 15 | * |
| 16 | * @package AAM |
| 17 | * @author Vasyl Martyniuk <vasyl@vasyltech.com> |
| 18 | */ |
| 19 | final class AAM_Core_Api_Area { |
| 20 | |
| 21 | /** |
| 22 | * |
| 23 | */ |
| 24 | const BACKEND = "backend"; |
| 25 | |
| 26 | /** |
| 27 | * |
| 28 | */ |
| 29 | const FRONTEND = "frontend"; |
| 30 | |
| 31 | /** |
| 32 | * |
| 33 | */ |
| 34 | const API = "api"; |
| 35 | |
| 36 | /** |
| 37 | * Get operating area |
| 38 | * |
| 39 | * @return string |
| 40 | * |
| 41 | * @access public |
| 42 | * @static |
| 43 | */ |
| 44 | public static function get() { |
| 45 | if (defined('REST_REQUEST') && REST_REQUEST) { |
| 46 | $area = self::API; |
| 47 | } elseif (is_admin()) { |
| 48 | $area = self::BACKEND; |
| 49 | } else { |
| 50 | $area = self::FRONTEND; |
| 51 | } |
| 52 | |
| 53 | return $area; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * |
| 58 | * @return type |
| 59 | */ |
| 60 | public static function isBackend() { |
| 61 | return self::get() === self::BACKEND; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * |
| 66 | * @return type |
| 67 | */ |
| 68 | public static function isFrontend() { |
| 69 | return self::get() === self::FRONTEND; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * |
| 74 | * @return type |
| 75 | */ |
| 76 | public static function isAPI() { |
| 77 | return self::get() === self::API; |
| 78 | } |
| 79 | } |