diff --git a/README.md b/README.md index 76973d1..48ab8a5 100644 --- a/README.md +++ b/README.md @@ -215,7 +215,7 @@ Prevents the direct setting of some class variables ]; Overrides the default tablename -default: strtolower(get_class()) +default: strtolower(self:class) ### database_config_name (string) diff --git a/lib/Skeleton/Object/Child.php b/lib/Skeleton/Object/Child.php index 75046f8..5cd163c 100644 --- a/lib/Skeleton/Object/Child.php +++ b/lib/Skeleton/Object/Child.php @@ -95,7 +95,7 @@ protected function trait_child_save() { * @return string $table */ public static function trait_get_child_database_table() { - if (property_exists(get_class(), 'class_configuration') and is_array(self::$class_configuration)) { + if (property_exists(self::class, 'class_configuration') and is_array(self::$class_configuration)) { if (array_key_exists('database_table', self::$class_configuration) and self::$class_configuration['database_table'] === null) { return null; } elseif (isset(self::$class_configuration['database_table'])) { @@ -103,7 +103,7 @@ public static function trait_get_child_database_table() { } } - return strtolower((new \ReflectionClass(get_class()))->getShortName()); + return strtolower((new \ReflectionClass(self::class))->getShortName()); } /** @@ -113,10 +113,10 @@ public static function trait_get_child_database_table() { * @return string $id */ public static function trait_get_parent_table_field_id() { - if (property_exists(get_class(), 'class_configuration') and isset(self::$class_configuration['parent_field_id'])) { + if (property_exists(self::class, 'class_configuration') and isset(self::$class_configuration['parent_field_id'])) { return self::$class_configuration['parent_field_id']; } else { - return strtolower((new \ReflectionClass(get_class()))->getParentClass()->getShortName() . '_id'); + return strtolower((new \ReflectionClass(self::class))->getParentClass()->getShortName() . '_id'); } } } diff --git a/lib/Skeleton/Object/Get.php b/lib/Skeleton/Object/Get.php index e6f28be..20e079b 100644 --- a/lib/Skeleton/Object/Get.php +++ b/lib/Skeleton/Object/Get.php @@ -114,7 +114,7 @@ public static function get_by_id($id) { * If in class_configuration a child_classname field is specified, * use this */ - if (property_exists(get_class(), 'class_configuration') && isset(self::$class_configuration['child_classname_field'])) { + if (property_exists(self::class, 'class_configuration') && isset(self::$class_configuration['child_classname_field'])) { $classname_field = self::$class_configuration['child_classname_field']; $table = self::trait_get_database_table(); $db = self::trait_get_database(); diff --git a/lib/Skeleton/Object/Model.php b/lib/Skeleton/Object/Model.php index a2d0856..ab11b2b 100644 --- a/lib/Skeleton/Object/Model.php +++ b/lib/Skeleton/Object/Model.php @@ -68,9 +68,9 @@ trait Model { * @param int $id */ public function __construct($id = null) { - if (property_exists(get_class(), 'class_configuration') && isset(self::$class_configuration['child_classname_field'])) { + if (property_exists(__CLASS__, 'class_configuration') && isset(self::$class_configuration['child_classname_field'])) { $classname_field = self::$class_configuration['child_classname_field']; - $this->details[$classname_field] = get_class($this); + $this->details[$classname_field] = __CLASS__; } if ($id !== null) { @@ -94,7 +94,7 @@ public function cast($classname) { throw new \Exception('Classname "' . $classname . '" doesn\'t exist'); } - if (get_class($this) == $classname) { + if (__CLASS__ == $classname) { return $this; } @@ -151,7 +151,7 @@ protected function get_details() { */ public function __set($key, $value) { // Check if the key we want to set exists in the disallow_set variable - if (property_exists(get_class(), 'class_configuration') && isset(self::$class_configuration['disallow_set'])) { + if (property_exists(__CLASS__, 'class_configuration') && isset(self::$class_configuration['disallow_set'])) { if (is_array(self::$class_configuration['disallow_set'])) { if (in_array($key, self::$class_configuration['disallow_set'])) { throw new \Exception('Can not set ' . $key . ' directly'); @@ -441,7 +441,7 @@ public static function get_object_fields() { * @return Database $database */ protected static function trait_get_database() { - if (property_exists(get_class(), 'class_configuration') && isset(self::$class_configuration['database_config_name'])) { + if (property_exists(self::class, 'class_configuration') && isset(self::$class_configuration['database_config_name'])) { $db = Database::get(self::$class_configuration['database_config_name']); } else { $db = Database::get(); @@ -456,10 +456,10 @@ protected static function trait_get_database() { * @return string $table */ public static function trait_get_database_table() { - if (property_exists(get_class(), 'class_configuration') && isset(self::$class_configuration['database_table'])) { + if (property_exists(self::class, 'class_configuration') && isset(self::$class_configuration['database_table'])) { return self::$class_configuration['database_table']; } else { - return strtolower((new \ReflectionClass(get_class()))->getShortName()); + return strtolower((new \ReflectionClass(self::class))->getShortName()); } } @@ -470,7 +470,7 @@ public static function trait_get_database_table() { * @return string $id */ protected static function trait_get_table_field_id() { - if (property_exists(get_class(), 'class_configuration') && isset(self::$class_configuration['table_field_id'])) { + if (property_exists(self::class, 'class_configuration') && isset(self::$class_configuration['table_field_id'])) { return self::$class_configuration['table_field_id']; } else { return 'id'; @@ -484,7 +484,7 @@ protected static function trait_get_table_field_id() { * @return string $created */ private static function trait_get_table_field_created() { - if (property_exists(get_class(), 'class_configuration') && isset(self::$class_configuration['table_field_created'])) { + if (property_exists(self::class, 'class_configuration') && isset(self::$class_configuration['table_field_created'])) { return self::$class_configuration['table_field_created']; } else { return 'created'; @@ -498,7 +498,7 @@ private static function trait_get_table_field_created() { * @return string $updated */ private static function trait_get_table_field_updated() { - if (property_exists(get_class(), 'class_configuration') && isset(self::$class_configuration['table_field_updated'])) { + if (property_exists(self::class, 'class_configuration') && isset(self::$class_configuration['table_field_updated'])) { return self::$class_configuration['table_field_updated']; } else { return 'updated'; @@ -512,7 +512,7 @@ private static function trait_get_table_field_updated() { * @return string $archived */ private static function trait_get_table_field_archived() { - if (property_exists(get_class(), 'class_configuration') && isset(self::$class_configuration['table_field_archived'])) { + if (property_exists(self::class, 'class_configuration') && isset(self::$class_configuration['table_field_archived'])) { return self::$class_configuration['table_field_archived']; } else { return 'archived'; diff --git a/lib/Skeleton/Object/Number.php b/lib/Skeleton/Object/Number.php index 6cae0d6..8945ab0 100644 --- a/lib/Skeleton/Object/Number.php +++ b/lib/Skeleton/Object/Number.php @@ -22,7 +22,7 @@ protected function generate_number() { /** * We need to know the fields that divide the numbers groups of unique numbers */ - if (property_exists(get_class(), 'class_configuration') AND isset(self::$class_configuration['number_dividers'])) { + if (property_exists(__CLASS__, 'class_configuration') AND isset(self::$class_configuration['number_dividers'])) { $number_dividers = self::$class_configuration['number_dividers']; } @@ -36,7 +36,7 @@ protected function generate_number() { /** * Which field do we need to store the number */ - if (property_exists(get_class(), 'class_configuration') AND isset(self::$class_configuration['number_field'])) { + if (property_exists(__CLASS__, 'class_configuration') AND isset(self::$class_configuration['number_field'])) { $number_field = self::$class_configuration['number_field']; } @@ -63,7 +63,7 @@ protected function generate_number() { $conditions = []; foreach ($number_dividers as $number_divider) { if (empty($this->$number_divider)) { - throw new \Exception('Cannot create number for ' . get_class() . '. Number divider ' . $number_divider . ' is empty'); + throw new \Exception('Cannot create number for ' . __CLASS__ . '. Number divider ' . $number_divider . ' is empty'); } $conditions[$number_divider] = $this->$number_divider; } diff --git a/lib/Skeleton/Object/Slug.php b/lib/Skeleton/Object/Slug.php index 15484d4..90e4909 100644 --- a/lib/Skeleton/Object/Slug.php +++ b/lib/Skeleton/Object/Slug.php @@ -20,7 +20,7 @@ trait Slug { private function trait_slug_get_base(): string { $sluggable_field = 'name'; - if (property_exists(get_class(), 'class_configuration') AND isset(self::$class_configuration['sluggable'])) { + if (property_exists(__CLASS__, 'class_configuration') AND isset(self::$class_configuration['sluggable'])) { $sluggable_field = self::$class_configuration['sluggable']; }