Controller.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * Lithium: the most rad php framework
  4. *
  5. * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
  6. * @license http://opensource.org/licenses/bsd-license.php The BSD License
  7. */
  8. namespace lithium\console\command\create;
  9. use lithium\util\Inflector;
  10. /**
  11. * Generate a Controller class in the `--library` namespace
  12. *
  13. * `li3 create controller Posts`
  14. * `li3 create --library=li3_plugin controller Posts`
  15. *
  16. */
  17. class Controller extends \lithium\console\command\Create {
  18. /**
  19. * Get the fully-qualified model class that is used by the controller.
  20. *
  21. * @param string $request
  22. * @return string
  23. */
  24. protected function _use($request) {
  25. $request->params['command'] = 'model';
  26. return $this->_namespace($request) . '\\' . $this->_model($request);
  27. }
  28. /**
  29. * Get the controller class name.
  30. *
  31. * @param string $request
  32. * @return string
  33. */
  34. protected function _class($request) {
  35. return $this->_name($request) . 'Controller';
  36. }
  37. /**
  38. * Returns the name of the controller class, minus `'Controller'`.
  39. *
  40. * @param string $request
  41. * @return string
  42. */
  43. protected function _name($request) {
  44. return Inflector::camelize(Inflector::pluralize($request->action));
  45. }
  46. /**
  47. * Get the plural variable used for data in controller methods.
  48. *
  49. * @param string $request
  50. * @return string
  51. */
  52. protected function _plural($request) {
  53. return Inflector::pluralize(Inflector::camelize($request->action, false));
  54. }
  55. /**
  56. * Get the model class used in controller methods.
  57. *
  58. * @param string $request
  59. * @return string
  60. */
  61. protected function _model($request) {
  62. return Inflector::camelize(Inflector::pluralize($request->action));
  63. }
  64. /**
  65. * Get the singular variable to use for data in controller methods.
  66. *
  67. * @param string $request
  68. * @return string
  69. */
  70. protected function _singular($request) {
  71. return Inflector::singularize(Inflector::camelize($request->action, false));
  72. }
  73. }
  74. ?>