Utils.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * @author Jenner <hypxm@qq.com>
  4. * @license https://opensource.org/licenses/MIT MIT
  5. * @datetime: 2015/11/11 17:50
  6. */
  7. namespace Jenner\SimpleFork;
  8. class Utils
  9. {
  10. /**
  11. * check if the sub class of Process has overwrite the run method
  12. *
  13. * @param $child_class
  14. */
  15. public static function checkOverwriteRunMethod($child_class)
  16. {
  17. $parent_class = '\\Jenner\\SimpleFork\\Process';
  18. if ($child_class == $parent_class) {
  19. $message = "you should extend the `{$parent_class}`" .
  20. ' and overwrite the run method';
  21. throw new \RuntimeException($message);
  22. }
  23. $child = new \ReflectionClass($child_class);
  24. if ($child->getParentClass() === false) {
  25. $message = "you should extend the `{$parent_class}`" .
  26. ' and overwrite the run method';
  27. throw new \RuntimeException($message);
  28. }
  29. $parent_methods = $child->getParentClass()->getMethods(\ReflectionMethod::IS_PUBLIC);
  30. foreach ($parent_methods as $parent_method) {
  31. if ($parent_method->getName() !== 'run') continue;
  32. $declaring_class = $child->getMethod($parent_method->getName())
  33. ->getDeclaringClass()
  34. ->getName();
  35. if ($declaring_class === $parent_class) {
  36. throw new \RuntimeException('you must overwrite the run method');
  37. }
  38. }
  39. }
  40. }