/// /// This file is part of CRIMSON. /// /// CRIMSON is free software; you can redistribute it and/or modify it /// under the terms of the GNU General Public License as published by /// the Free Software Foundation; either version 3 of the License, or (at /// your option) any later version. /// /// CRIMSON is distributed in the hope that it will be useful, but /// WITHOUT ANY WARRANTY; without even the implied warranty of /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /// GNU General Public License for more details. /// /// You should have received a copy of the GNU General Public License /// along with CRIMSON. If not, see . abstract class Model extends Base { private function flatten_array($arr): array { $fn = fn($e) => is_array($e) ? $e : [$e]; return array_merge(...array_map($fn, $arr)); } protected function get_data(): ?array { /* return barebones base data */ $data = array(); $data['css'] = array(); $data['js'] = array(); $style = CONFIG['style']; $js = CONFIG['js']; $app = NULL; try { // get the class object of the child class, i.e. Blog_model $cls = new ReflectionClass(get_class($this)); // the name of the route is the name of the file without .php $path = $cls->getFileName(); $app = pathinfo($path, PATHINFO_FILENAME); // sanity check assert(is_string($app)); } catch (Exception $_e) { $app = CONTEXT['app']; } $data['css'] = $this->flatten_array([ $style[''] ?? [], $style[$app] ?? [], ]); $data['js'] = $this->flatten_array([ $js[''] ?? [], $js[$app] ?? [], ]); return $data; } }