Db.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. *
  4. * Cube Framework $Id$ XPoN8KX6bC4qpM5es9her1f+yUppk0Sg3JNKaS+2zGQ=
  5. *
  6. * @link http://codecu.be/framework
  7. * @copyright Copyright (c) 2014 CodeCube SRL
  8. * @license http://codecu.be/framework/license Commercial License
  9. *
  10. * @version 1.0
  11. */
  12. /**
  13. * creates a db adapter resource
  14. */
  15. namespace Cube\Application\Resource;
  16. use Cube\Db as DbObject,
  17. Cube\Db\Adapter\AbstractAdapter;
  18. class Db extends AbstractResource
  19. {
  20. /**
  21. *
  22. * @var \Cube\Db\Adapter\AbstractAdapter
  23. */
  24. protected $_adapter;
  25. /**
  26. *
  27. * initialize translate object
  28. *
  29. * @throws \InvalidArgumentException
  30. * @return \Cube\Translate
  31. */
  32. public function init()
  33. {
  34. if (!($this->_adapter instanceof AbstractAdapter)) {
  35. if (!isset($this->_options['db']['adapter'])) {
  36. throw new \InvalidArgumentException("A database adapter is required for creating a Db resource.");
  37. }
  38. $this->_adapter = DbObject::factory($this->_options['db']['adapter'], $this->_options['db']);
  39. }
  40. return $this->_adapter;
  41. }
  42. }