MyRuntimeHelper - lddefensor/SimpleAI GitHub Wiki

Namespace and Path

  • namespace: Ulap\Helpers
  • path: LIB . DS . 'Helpers' . DS . 'MyRuntimeHelper.php' The MyRuntimeHelper Class is a helper class that allows instantiation of classes given a Path and ClassName given that the class is within App namespace.

Constructor

  • accepts two string parameters, path and className.
  • If file given by path does not exist, a MyRuntimeException with code 1002 will be thrown.
  • If the class given by className does not exists even on inclusion of file, that contains the supposed class, a MyRuntimeException with code 1001 will be thrown.
  • If no exception is thrown, the className is assigned to the class's className property.

instantiateClass

  • parameters: array $args (defaults to null)
  • instantiates the class given by className and assigns it to instance property of class

Exceptions thrown

  • if class is not instantiable - MyRuntimeException ErrorCode: 1004
  • if arguments passed is insufficient - MyRuntimeException ErrorCode: 1003

hasMethod

  • parameters: string method
  • checks if the given instance contains a method with the name given in method, returns true or false

invokeMethod

  • parameters: string $method

  • parameters: array $args (defaults to null)

  • invokes the instance's method

Exceptions thrown

  • if the number of args is less than required number of arguments - MyRuntimeException, ErrorCode: 1008
  • if method does not exists - MyRuntimeException, ErrorCode: 1007