Behavior.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * @package Kohana/ORM
  4. * @author Koseven Team
  5. * @copyright (c) 2016-2018 Koseven Team
  6. * @license https://koseven.ga/LICENSE.md
  7. */
  8. class Kohana_ORM_Behavior {
  9. /**
  10. * Database query builder
  11. * @var Database_Query_Builder_Select
  12. */
  13. protected $_config;
  14. /**
  15. * Creates and returns a new ORM behavior.
  16. *
  17. * @chainable
  18. * @param string $type Type name
  19. * @param mixed $id Parameter for find()
  20. * @return ORM
  21. */
  22. public static function factory($behavior, $config = NULL)
  23. {
  24. if ( ! is_string($behavior) AND is_array($config))
  25. {
  26. if ( ! is_callable($config))
  27. throw new Kohana_Exception('Behavior cannot be created: function does not exists');
  28. // This is either a callback as an array or a lambda
  29. return new ORM_Behavior_LocalBehavior($config);
  30. }
  31. // Set class name
  32. $behavior_name = 'ORM_Behavior_'.ucfirst($behavior);
  33. return new $behavior_name($config);
  34. }
  35. protected function __construct($config)
  36. {
  37. $this->_config = $config;
  38. }
  39. public function on_construct($model, $id) { return TRUE; }
  40. public function on_create($model) { }
  41. public function on_update($model) { }
  42. }