Textpattern | PHP Cross Reference | Content Management Systems |
Description: Adapting providable base class. <code> class MyProvidableAdaptee extends \Textpattern\Adaptable\Providable { public function getDefaultAdaptableProvider() { return new MyAdapterDriver(); } } </code>
1 <?php 2 3 /* 4 * Textpattern Content Management System 5 * https://textpattern.com/ 6 * 7 * Copyright (C) 2020 The Textpattern Development Team 8 * 9 * This file is part of Textpattern. 10 * 11 * Textpattern is free software; you can redistribute it and/or 12 * modify it under the terms of the GNU General Public License 13 * as published by the Free Software Foundation, version 2. 14 * 15 * Textpattern is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with Textpattern. If not, see <https://www.gnu.org/licenses/>. 22 */ 23 24 /** 25 * Adapting providable base class. 26 * 27 * <code> 28 * class MyProvidableAdaptee extends \Textpattern\Adaptable\Providable 29 * { 30 * public function getDefaultAdaptableProvider() 31 * { 32 * return new MyAdapterDriver(); 33 * } 34 * } 35 * </code> 36 * 37 * @since 4.6.0 38 * @package Adaptable 39 */ 40 41 namespace Textpattern\Adaptable; 42 43 abstract class Providable implements ProvidableInterface 44 { 45 /** 46 * Stores an instance of the current provider. 47 * 48 * @var \Textpattern\Adaptable\Adapter 49 */ 50 51 private $adapter; 52 53 /** 54 * Whether it's the first run. 55 * 56 * @var bool 57 */ 58 59 private $firstRun = true; 60 61 /** 62 * {@inheritdoc} 63 */ 64 65 public function setAdapter(\Textpattern\Adaptable\Adapter $adapter) 66 { 67 $this->adapter = $adapter; 68 69 return $this; 70 } 71 72 /** 73 * {@inheritdoc} 74 */ 75 76 public function getAdapter() 77 { 78 if (!$this->adapter) { 79 $this->adapter = $this->getDefaultAdapter(); 80 } 81 82 if ($this->firstRun) { 83 $this->firstRun = false; 84 $this->adapter->providable = $this; 85 } 86 87 return $this->adapter; 88 } 89 90 /** 91 * Redirects method calls to the adapter. 92 * 93 * @param string $name The method 94 * @param array $args The arguments 95 * @return mixed 96 */ 97 98 public function __call($name, array $args) 99 { 100 return call_user_func_array(array($this->getAdapter(), $name), $args); 101 } 102 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
title