| 1 | <?php | ||
| 16 | abstract class AbstractAuthorizedApiController extends BaseController | ||
| 17 | { | ||
| 18 | /** | ||
| 19 | * Allow anonymous access to this controller. | ||
| 20 | * | ||
| 21 | * @var bool | ||
| 22 | */ | ||
| 23 | protected $allowAnonymous = true; | ||
| 24 | |||
| 25 | /** | ||
| 26 | * Initialize controller | ||
| 27 | */ | ||
| 28 | public function init() | ||
| 29 |     { | ||
| 30 | craft()->apiAuth->setCorsHeaders(); | ||
| 31 |         if (craft()->apiAuth->isOptionsRequest()) { | ||
| 32 | craft()->end(); | ||
| 33 | } | ||
| 34 | $this->authorizeApi(); | ||
| 35 | } | ||
| 36 | |||
| 37 | /** | ||
| 38 | * @return bool | ||
| 39 | */ | ||
| 40 | private function authorizeApi() | ||
| 54 | } | ||
| 55 | 
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: