timeline
1 month ago
implementor.php
1 month ago
index.html
1 month ago
manager.php
1 month ago
search.php
1 month ago
timeline.php
1 month ago
manager.php
97 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package VikAppointments |
| 4 | * @subpackage core |
| 5 | * @author E4J s.r.l. |
| 6 | * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved. |
| 7 | * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 | * @link https://vikwp.com |
| 9 | */ |
| 10 | |
| 11 | // No direct access |
| 12 | defined('ABSPATH') or die('No script kiddies please!'); |
| 13 | |
| 14 | /** |
| 15 | * Class responsible to dispatch the availability search handler. |
| 16 | * |
| 17 | * @since 1.7 |
| 18 | */ |
| 19 | final class VAPAvailabilityManager |
| 20 | { |
| 21 | /** |
| 22 | * The name of the search handler. |
| 23 | * |
| 24 | * @var string |
| 25 | */ |
| 26 | public static $manager = null; |
| 27 | |
| 28 | /** |
| 29 | * Creates a new instance of the availability search handler. |
| 30 | * |
| 31 | * @param integer $id_ser The service ID. |
| 32 | * @param integer $id_emp The employee ID (optional). |
| 33 | * @param array $options An array of options. |
| 34 | * |
| 35 | * @return VAPAvailabilitySearch |
| 36 | */ |
| 37 | public static function getInstance($id_ser, $id_emp = null, array $options = array()) |
| 38 | { |
| 39 | if (is_null(static::$manager)) |
| 40 | { |
| 41 | /** |
| 42 | * This hook can be used to safely change the class instance |
| 43 | * responsible of handling the whole availability system. |
| 44 | * In addition to returning the new class name, plugins must |
| 45 | * include all the needed resources. The returned object must |
| 46 | * also inherit VAPAvailabilitySearch class. |
| 47 | * |
| 48 | * The hook will be called only once per page session. |
| 49 | * |
| 50 | * @return string The class name. |
| 51 | * |
| 52 | * @since 1.7 |
| 53 | */ |
| 54 | static::$manager = VAPFactory::getEventDispatcher()->triggerOnce('onCreateAvailabilitySearch'); |
| 55 | |
| 56 | if (!static::$manager) |
| 57 | { |
| 58 | // plugin didn't specify a custom implementor, use default one |
| 59 | VAPLoader::import('libraries.availability.implementor'); |
| 60 | static::$manager = 'VAPAvailabilityImplementor'; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | // copy in a local variable |
| 65 | $classname = static::$manager; |
| 66 | |
| 67 | // make sure the object is loaded and exists |
| 68 | if (!class_exists($classname)) |
| 69 | { |
| 70 | // class not found, throw an exception |
| 71 | throw new Exception(sprintf('Availability search [%s] not found', $classname), 404); |
| 72 | } |
| 73 | |
| 74 | // create new instance |
| 75 | $handler = new $classname($id_ser, $id_emp, $options); |
| 76 | |
| 77 | // make sure the object is a valid instance |
| 78 | if (!$handler instanceof VAPAvailabilitySearch) |
| 79 | { |
| 80 | // Not a valid instance, unexpected behavior might occur... |
| 81 | // Prevent them by throwing an exception. |
| 82 | throw new Exception(sprintf('The class [%s] is not a valid instance', $classname), 500); |
| 83 | } |
| 84 | |
| 85 | return $handler; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Class constructor. |
| 90 | * Declared with protected visibility to avoid its instantiation. |
| 91 | */ |
| 92 | protected function __construct() |
| 93 | { |
| 94 | // cannot be publicly instantiated |
| 95 | } |
| 96 | } |
| 97 |