1 <?php
2
3 use Skimia\Foundation\Exceptions\Fail\IsNotASubclassOfException;
4 use Skimia\Foundation\Exceptions\Fail\InvalidSuperclassUsedForTraitException;
5
6 if (! function_exists('is_subclass_of_or_fail')) {
7 function is_subclass_of_or_fail($object, $class_name, $allow_string = true)
8 {
9
10 if (! is_subclass_of($object, $class_name, $allow_string)) {
11 throw new IsNotASubclassOfException(
12 is_object($object) ? get_class($object) : $object,
13 $class_name);
14 }
15
16 return true;
17 }
18 }
19
20 if (! function_exists('ensure_trait_used_in_subclass_of_or_fail')) {
21
22 23 24 25 26 27 28 29
30 function ensure_trait_used_in_subclass_of_or_fail($trait, $object, $class_name, $allow_string = true)
31 {
32 if (! is_subclass_of($object, $class_name, $allow_string)) {
33 throw new InvalidSuperclassUsedForTraitException(
34 is_object($trait) ? get_class($trait) : $trait,
35 is_object($class_name) ? get_class($class_name) : $class_name
36 );
37 }
38
39 return true;
40 }
41 }
42