Skimia\Foundation
  • Namespace
  • Class
  • Tree
  • Todo
  • Download

Namespaces

  • None
  • PHP
  • Skimia
    • Foundation
      • Annotations
      • Exceptions
        • Fail
      • Providers
        • Traits
      • Support
        • Traits
      • Testing
        • Traits

Classes

  • Skimia\Foundation\Annotations\BaseServiceProvider
  • Skimia\Foundation\Annotations\Scanner
  • Skimia\Foundation\FoundationServiceProvider
  • Skimia\Foundation\Testing\CommandOutput

Interfaces

  • Skimia\Foundation\Testing\TestablePromptCommandInterface

Traits

  • Skimia\Foundation\Providers\Traits\CommandLoaderTrait
  • Skimia\Foundation\Support\Traits\NamespaceClassFinderTrait
  • Skimia\Foundation\Testing\Traits\CommandTrait
  • Skimia\Foundation\Testing\Traits\TestableCommandTrait

Exceptions

  • Exception
  • LogicException
  • Skimia\Foundation\Exceptions\Fail\InvalidSuperclassUsedForTraitException
  • Skimia\Foundation\Exceptions\Fail\IsNotASubclassOfException

Functions

  • ensure_trait_used_in_subclass_of_or_fail
  • is_subclass_of_or_fail
 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         //TODO: Implement Message
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      * @param $trait mixed The trait name (use get_class(self)).
24      * @param $object mixed A class name or an object instance. No error is generated if the class does not exist.
25      * @param $class_name string The required parent class name
26      * @param bool|true $allow_string
27      * @throws LogicException if the trait is used in class not extends the required
28      * @return bool
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 
Skimia\Foundation API documentation generated by ApiGen