RequestHandlerComponent.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. <?php
  2. /**
  3. * Request object for handling alternative HTTP requests
  4. *
  5. * Alternative HTTP requests can come from wireless units like mobile phones, palmtop computers,
  6. * and the like. These units have no use for Ajax requests, and this Component can tell how Cake
  7. * should respond to the different needs of a handheld computer and a desktop machine.
  8. *
  9. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  10. * Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. *
  12. * Licensed under The MIT License
  13. * Redistributions of files must retain the above copyright notice.
  14. *
  15. * @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
  16. * @link http://cakephp.org CakePHP(tm) Project
  17. * @package Cake.Controller.Component
  18. * @since CakePHP(tm) v 0.10.4.1076
  19. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  20. */
  21. App::uses('Xml', 'Utility');
  22. /**
  23. * Request object for handling HTTP requests
  24. *
  25. * @package Cake.Controller.Component
  26. * @link http://book.cakephp.org/2.0/en/core-libraries/components/request-handling.html
  27. *
  28. */
  29. class RequestHandlerComponent extends Component {
  30. /**
  31. * The layout that will be switched to for Ajax requests
  32. *
  33. * @var string
  34. * @see RequestHandler::setAjax()
  35. */
  36. public $ajaxLayout = 'ajax';
  37. /**
  38. * Determines whether or not callbacks will be fired on this component
  39. *
  40. * @var boolean
  41. */
  42. public $enabled = true;
  43. /**
  44. * Holds the reference to Controller::$request
  45. *
  46. * @var CakeRequest
  47. */
  48. public $request;
  49. /**
  50. * Holds the reference to Controller::$response
  51. *
  52. * @var CakeResponse
  53. */
  54. public $response;
  55. /**
  56. * Contains the file extension parsed out by the Router
  57. *
  58. * @var string
  59. * @see Router::parseExtensions()
  60. */
  61. public $ext = null;
  62. /**
  63. * The template to use when rendering the given content type.
  64. *
  65. * @var string
  66. */
  67. protected $_renderType = null;
  68. /**
  69. * A mapping between extensions and deserializers for request bodies of that type.
  70. * By default only JSON and XML are mapped, use RequestHandlerComponent::addInputType()
  71. *
  72. * @var array
  73. */
  74. protected $_inputTypeMap = array(
  75. 'json' => array('json_decode', true)
  76. );
  77. /**
  78. * Constructor. Parses the accepted content types accepted by the client using HTTP_ACCEPT
  79. *
  80. * @param ComponentCollection $collection ComponentCollection object.
  81. * @param array $settings Array of settings.
  82. */
  83. public function __construct(ComponentCollection $collection, $settings = array()) {
  84. parent::__construct($collection, $settings);
  85. $this->addInputType('xml', array(array($this, 'convertXml')));
  86. $Controller = $collection->getController();
  87. $this->request = $Controller->request;
  88. $this->response = $Controller->response;
  89. }
  90. /**
  91. * Checks to see if a file extension has been parsed by the Router, or if the
  92. * HTTP_ACCEPT_TYPE has matches only one content type with the supported extensions.
  93. * If there is only one matching type between the supported content types & extensions,
  94. * and the requested mime-types, RequestHandler::$ext is set to that value.
  95. *
  96. * @param Controller $controller A reference to the controller
  97. * @param array $settings Array of settings to _set().
  98. * @return void
  99. * @see Router::parseExtensions()
  100. */
  101. public function initialize($controller, $settings = array()) {
  102. if (isset($this->request->params['ext'])) {
  103. $this->ext = $this->request->params['ext'];
  104. }
  105. if (empty($this->ext) || $this->ext == 'html') {
  106. $this->_setExtension();
  107. }
  108. $this->params = $controller->params;
  109. $this->_set($settings);
  110. }
  111. /**
  112. * Set the extension based on the accept headers.
  113. * Compares the accepted types and configured extensions.
  114. * If there is one common type, that is assigned as the ext/content type
  115. * for the response.
  116. *
  117. * If html is one of the preferred types, no content type will be set, this
  118. * is to avoid issues with browsers that prefer html and several other content types.
  119. *
  120. * @return void
  121. */
  122. protected function _setExtension() {
  123. $accept = $this->request->parseAccept();
  124. if (empty($accept)) {
  125. return;
  126. }
  127. $extensions = Router::extensions();
  128. $preferred = array_shift($accept);
  129. $preferredTypes = $this->response->mapType($preferred);
  130. $similarTypes = array_intersect($extensions, $preferredTypes);
  131. if (count($similarTypes) === 1 && !in_array('xhtml', $preferredTypes) && !in_array('html', $preferredTypes)) {
  132. $this->ext = array_shift($similarTypes);
  133. }
  134. }
  135. /**
  136. * The startup method of the RequestHandler enables several automatic behaviors
  137. * related to the detection of certain properties of the HTTP request, including:
  138. *
  139. * - Disabling layout rendering for Ajax requests (based on the HTTP_X_REQUESTED_WITH header)
  140. * - If Router::parseExtensions() is enabled, the layout and template type are
  141. * switched based on the parsed extension or Accept-Type header. For example, if `controller/action.xml`
  142. * is requested, the view path becomes `app/View/Controller/xml/action.ctp`. Also if
  143. * `controller/action` is requested with `Accept-Type: application/xml` in the headers
  144. * the view path will become `app/View/Controller/xml/action.ctp`.
  145. * - If a helper with the same name as the extension exists, it is added to the controller.
  146. * - If the extension is of a type that RequestHandler understands, it will set that
  147. * Content-type in the response header.
  148. * - If the XML data is POSTed, the data is parsed into an XML object, which is assigned
  149. * to the $data property of the controller, which can then be saved to a model object.
  150. *
  151. * @param Controller $controller A reference to the controller
  152. * @return void
  153. */
  154. public function startup($controller) {
  155. $controller->request->params['isAjax'] = $this->request->is('ajax');
  156. $isRecognized = (
  157. !in_array($this->ext, array('html', 'htm')) &&
  158. $this->response->getMimeType($this->ext)
  159. );
  160. if (!empty($this->ext) && $isRecognized) {
  161. $this->renderAs($controller, $this->ext);
  162. } elseif ($this->request->is('ajax')) {
  163. $this->renderAs($controller, 'ajax');
  164. } elseif (empty($this->ext) || in_array($this->ext, array('html', 'htm'))) {
  165. $this->respondAs('html', array('charset' => Configure::read('App.encoding')));
  166. }
  167. foreach ($this->_inputTypeMap as $type => $handler) {
  168. if ($this->requestedWith($type)) {
  169. $input = call_user_func_array(array($controller->request, 'input'), $handler);
  170. $controller->request->data = $input;
  171. }
  172. }
  173. }
  174. /**
  175. * Helper method to parse xml input data, due to lack of anonymous functions
  176. * this lives here.
  177. *
  178. * @param string $xml
  179. * @return array Xml array data
  180. */
  181. public function convertXml($xml) {
  182. try {
  183. $xml = Xml::build($xml);
  184. if (isset($xml->data)) {
  185. return Xml::toArray($xml->data);
  186. }
  187. return Xml::toArray($xml);
  188. } catch (XmlException $e) {
  189. return array();
  190. }
  191. }
  192. /**
  193. * Handles (fakes) redirects for Ajax requests using requestAction()
  194. *
  195. * @param Controller $controller A reference to the controller
  196. * @param string|array $url A string or array containing the redirect location
  197. * @param mixed $status HTTP Status for redirect
  198. * @param boolean $exit
  199. * @return void
  200. */
  201. public function beforeRedirect($controller, $url, $status = null, $exit = true) {
  202. if (!$this->request->is('ajax')) {
  203. return;
  204. }
  205. foreach ($_POST as $key => $val) {
  206. unset($_POST[$key]);
  207. }
  208. if (is_array($url)) {
  209. $url = Router::url($url + array('base' => false));
  210. }
  211. if (!empty($status)) {
  212. $statusCode = $this->response->httpCodes($status);
  213. $code = key($statusCode);
  214. $this->response->statusCode($code);
  215. }
  216. $this->response->body($this->requestAction($url, array('return', 'bare' => false)));
  217. $this->response->send();
  218. $this->_stop();
  219. }
  220. /**
  221. * Returns true if the current HTTP request is Ajax, false otherwise
  222. *
  223. * @return boolean True if call is Ajax
  224. * @deprecated use `$this->request->is('ajax')` instead.
  225. */
  226. public function isAjax() {
  227. return $this->request->is('ajax');
  228. }
  229. /**
  230. * Returns true if the current HTTP request is coming from a Flash-based client
  231. *
  232. * @return boolean True if call is from Flash
  233. * @deprecated use `$this->request->is('flash')` instead.
  234. */
  235. public function isFlash() {
  236. return $this->request->is('flash');
  237. }
  238. /**
  239. * Returns true if the current request is over HTTPS, false otherwise.
  240. *
  241. * @return boolean True if call is over HTTPS
  242. * @deprecated use `$this->request->is('ssl')` instead.
  243. */
  244. public function isSSL() {
  245. return $this->request->is('ssl');
  246. }
  247. /**
  248. * Returns true if the current call accepts an XML response, false otherwise
  249. *
  250. * @return boolean True if client accepts an XML response
  251. */
  252. public function isXml() {
  253. return $this->prefers('xml');
  254. }
  255. /**
  256. * Returns true if the current call accepts an RSS response, false otherwise
  257. *
  258. * @return boolean True if client accepts an RSS response
  259. */
  260. public function isRss() {
  261. return $this->prefers('rss');
  262. }
  263. /**
  264. * Returns true if the current call accepts an Atom response, false otherwise
  265. *
  266. * @return boolean True if client accepts an RSS response
  267. */
  268. public function isAtom() {
  269. return $this->prefers('atom');
  270. }
  271. /**
  272. * Returns true if user agent string matches a mobile web browser, or if the
  273. * client accepts WAP content.
  274. *
  275. * @return boolean True if user agent is a mobile web browser
  276. */
  277. public function isMobile() {
  278. return $this->request->is('mobile') || $this->accepts('wap');
  279. }
  280. /**
  281. * Returns true if the client accepts WAP content
  282. *
  283. * @return boolean
  284. */
  285. public function isWap() {
  286. return $this->prefers('wap');
  287. }
  288. /**
  289. * Returns true if the current call a POST request
  290. *
  291. * @return boolean True if call is a POST
  292. * @deprecated Use $this->request->is('post'); from your controller.
  293. */
  294. public function isPost() {
  295. return $this->request->is('post');
  296. }
  297. /**
  298. * Returns true if the current call a PUT request
  299. *
  300. * @return boolean True if call is a PUT
  301. * @deprecated Use $this->request->is('put'); from your controller.
  302. */
  303. public function isPut() {
  304. return $this->request->is('put');
  305. }
  306. /**
  307. * Returns true if the current call a GET request
  308. *
  309. * @return boolean True if call is a GET
  310. * @deprecated Use $this->request->is('get'); from your controller.
  311. */
  312. public function isGet() {
  313. return $this->request->is('get');
  314. }
  315. /**
  316. * Returns true if the current call a DELETE request
  317. *
  318. * @return boolean True if call is a DELETE
  319. * @deprecated Use $this->request->is('delete'); from your controller.
  320. */
  321. public function isDelete() {
  322. return $this->request->is('delete');
  323. }
  324. /**
  325. * Gets Prototype version if call is Ajax, otherwise empty string.
  326. * The Prototype library sets a special "Prototype version" HTTP header.
  327. *
  328. * @return string Prototype version of component making Ajax call
  329. */
  330. public function getAjaxVersion() {
  331. if (env('HTTP_X_PROTOTYPE_VERSION') != null) {
  332. return env('HTTP_X_PROTOTYPE_VERSION');
  333. }
  334. return false;
  335. }
  336. /**
  337. * Adds/sets the Content-type(s) for the given name. This method allows
  338. * content-types to be mapped to friendly aliases (or extensions), which allows
  339. * RequestHandler to automatically respond to requests of that type in the
  340. * startup method.
  341. *
  342. * @param string $name The name of the Content-type, i.e. "html", "xml", "css"
  343. * @param mixed $type The Content-type or array of Content-types assigned to the name,
  344. * i.e. "text/html", or "application/xml"
  345. * @return void
  346. * @deprecated use `$this->response->type()` instead.
  347. */
  348. public function setContent($name, $type = null) {
  349. $this->response->type(array($name => $type));
  350. }
  351. /**
  352. * Gets the server name from which this request was referred
  353. *
  354. * @return string Server address
  355. * @deprecated use $this->request->referer() from your controller instead
  356. */
  357. public function getReferer() {
  358. return $this->request->referer(false);
  359. }
  360. /**
  361. * Gets remote client IP
  362. *
  363. * @param boolean $safe
  364. * @return string Client IP address
  365. * @deprecated use $this->request->clientIp() from your, controller instead.
  366. */
  367. public function getClientIP($safe = true) {
  368. return $this->request->clientIp($safe);
  369. }
  370. /**
  371. * Determines which content types the client accepts. Acceptance is based on
  372. * the file extension parsed by the Router (if present), and by the HTTP_ACCEPT
  373. * header. Unlike CakeRequest::accepts() this method deals entirely with mapped content types.
  374. *
  375. * Usage:
  376. *
  377. * `$this->RequestHandler->accepts(array('xml', 'html', 'json'));`
  378. *
  379. * Returns true if the client accepts any of the supplied types.
  380. *
  381. * `$this->RequestHandler->accepts('xml');`
  382. *
  383. * Returns true if the client accepts xml.
  384. *
  385. * @param mixed $type Can be null (or no parameter), a string type name, or an
  386. * array of types
  387. * @return mixed If null or no parameter is passed, returns an array of content
  388. * types the client accepts. If a string is passed, returns true
  389. * if the client accepts it. If an array is passed, returns true
  390. * if the client accepts one or more elements in the array.
  391. * @see RequestHandlerComponent::setContent()
  392. */
  393. public function accepts($type = null) {
  394. $accepted = $this->request->accepts();
  395. if ($type == null) {
  396. return $this->mapType($accepted);
  397. } elseif (is_array($type)) {
  398. foreach ($type as $t) {
  399. $t = $this->mapAlias($t);
  400. if (in_array($t, $accepted)) {
  401. return true;
  402. }
  403. }
  404. return false;
  405. } elseif (is_string($type)) {
  406. $type = $this->mapAlias($type);
  407. return in_array($type, $accepted);
  408. }
  409. return false;
  410. }
  411. /**
  412. * Determines the content type of the data the client has sent (i.e. in a POST request)
  413. *
  414. * @param mixed $type Can be null (or no parameter), a string type name, or an array of types
  415. * @return mixed If a single type is supplied a boolean will be returned. If no type is provided
  416. * The mapped value of CONTENT_TYPE will be returned. If an array is supplied the first type
  417. * in the request content type will be returned.
  418. */
  419. public function requestedWith($type = null) {
  420. if (!$this->request->is('post') && !$this->request->is('put')) {
  421. return null;
  422. }
  423. list($contentType) = explode(';', env('CONTENT_TYPE'));
  424. if ($type == null) {
  425. return $this->mapType($contentType);
  426. } elseif (is_array($type)) {
  427. foreach ($type as $t) {
  428. if ($this->requestedWith($t)) {
  429. return $t;
  430. }
  431. }
  432. return false;
  433. } elseif (is_string($type)) {
  434. return ($type == $this->mapType($contentType));
  435. }
  436. }
  437. /**
  438. * Determines which content-types the client prefers. If no parameters are given,
  439. * the single content-type that the client most likely prefers is returned. If $type is
  440. * an array, the first item in the array that the client accepts is returned.
  441. * Preference is determined primarily by the file extension parsed by the Router
  442. * if provided, and secondarily by the list of content-types provided in
  443. * HTTP_ACCEPT.
  444. *
  445. * @param mixed $type An optional array of 'friendly' content-type names, i.e.
  446. * 'html', 'xml', 'js', etc.
  447. * @return mixed If $type is null or not provided, the first content-type in the
  448. * list, based on preference, is returned. If a single type is provided
  449. * a boolean will be returnend if that type is preferred.
  450. * If an array of types are provided then the first preferred type is returned.
  451. * If no type is provided the first preferred type is returned.
  452. * @see RequestHandlerComponent::setContent()
  453. */
  454. public function prefers($type = null) {
  455. $acceptRaw = $this->request->parseAccept();
  456. if (empty($acceptRaw)) {
  457. return $this->ext;
  458. }
  459. $accepts = array_shift($acceptRaw);
  460. $accepts = $this->mapType($accepts);
  461. if ($type == null) {
  462. if (empty($this->ext) && !empty($accepts)) {
  463. return $accepts[0];
  464. }
  465. return $this->ext;
  466. }
  467. $types = (array)$type;
  468. if (count($types) === 1) {
  469. if (!empty($this->ext)) {
  470. return in_array($this->ext, $types);
  471. }
  472. return in_array($types[0], $accepts);
  473. }
  474. $intersect = array_values(array_intersect($accepts, $types));
  475. if (empty($intersect)) {
  476. return false;
  477. }
  478. return $intersect[0];
  479. }
  480. /**
  481. * Sets the layout and template paths for the content type defined by $type.
  482. *
  483. * ### Usage:
  484. *
  485. * Render the response as an 'ajax' response.
  486. *
  487. * `$this->RequestHandler->renderAs($this, 'ajax');`
  488. *
  489. * Render the response as an xml file and force the result as a file download.
  490. *
  491. * `$this->RequestHandler->renderAs($this, 'xml', array('attachment' => 'myfile.xml');`
  492. *
  493. * @param Controller $controller A reference to a controller object
  494. * @param string $type Type of response to send (e.g: 'ajax')
  495. * @param array $options Array of options to use
  496. * @return void
  497. * @see RequestHandlerComponent::setContent()
  498. * @see RequestHandlerComponent::respondAs()
  499. */
  500. public function renderAs($controller, $type, $options = array()) {
  501. $defaults = array('charset' => 'UTF-8');
  502. if (Configure::read('App.encoding') !== null) {
  503. $defaults['charset'] = Configure::read('App.encoding');
  504. }
  505. $options = array_merge($defaults, $options);
  506. if ($type == 'ajax') {
  507. $controller->layout = $this->ajaxLayout;
  508. return $this->respondAs('html', $options);
  509. }
  510. $controller->ext = '.ctp';
  511. $viewClass = ucfirst($type);
  512. App::uses($viewClass . 'View', 'View');
  513. if (class_exists($viewClass . 'View')) {
  514. $controller->viewClass = $viewClass;
  515. } elseif (empty($this->_renderType)) {
  516. $controller->viewPath .= DS . $type;
  517. } else {
  518. $remove = preg_replace("/([\/\\\\]{$this->_renderType})$/", DS . $type, $controller->viewPath);
  519. $controller->viewPath = $remove;
  520. }
  521. $this->_renderType = $type;
  522. $controller->layoutPath = $type;
  523. if ($this->response->getMimeType($type)) {
  524. $this->respondAs($type, $options);
  525. }
  526. $helper = ucfirst($type);
  527. $isAdded = (
  528. in_array($helper, $controller->helpers) ||
  529. array_key_exists($helper, $controller->helpers)
  530. );
  531. if (!$isAdded) {
  532. App::uses('AppHelper', 'View/Helper');
  533. App::uses($helper . 'Helper', 'View/Helper');
  534. if (class_exists($helper . 'Helper')) {
  535. $controller->helpers[] = $helper;
  536. }
  537. }
  538. }
  539. /**
  540. * Sets the response header based on type map index name. This wraps several methods
  541. * available on CakeResponse. It also allows you to use Content-Type aliases.
  542. *
  543. * @param mixed $type Friendly type name, i.e. 'html' or 'xml', or a full content-type,
  544. * like 'application/x-shockwave'.
  545. * @param array $options If $type is a friendly type name that is associated with
  546. * more than one type of content, $index is used to select which content-type to use.
  547. * @return boolean Returns false if the friendly type name given in $type does
  548. * not exist in the type map, or if the Content-type header has
  549. * already been set by this method.
  550. * @see RequestHandlerComponent::setContent()
  551. */
  552. public function respondAs($type, $options = array()) {
  553. $defaults = array('index' => null, 'charset' => null, 'attachment' => false);
  554. $options = $options + $defaults;
  555. if (strpos($type, '/') === false) {
  556. $cType = $this->response->getMimeType($type);
  557. if ($cType === false) {
  558. return false;
  559. }
  560. if (is_array($cType) && isset($cType[$options['index']])) {
  561. $cType = $cType[$options['index']];
  562. }
  563. if (is_array($cType)) {
  564. if ($this->prefers($cType)) {
  565. $cType = $this->prefers($cType);
  566. } else {
  567. $cType = $cType[0];
  568. }
  569. }
  570. } else {
  571. $cType = $type;
  572. }
  573. if ($cType != null) {
  574. if (empty($this->request->params['requested'])) {
  575. $this->response->type($cType);
  576. }
  577. if (!empty($options['charset'])) {
  578. $this->response->charset($options['charset']);
  579. }
  580. if (!empty($options['attachment'])) {
  581. $this->response->download($options['attachment']);
  582. }
  583. return true;
  584. }
  585. return false;
  586. }
  587. /**
  588. * Returns the current response type (Content-type header), or null if not alias exists
  589. *
  590. * @return mixed A string content type alias, or raw content type if no alias map exists,
  591. * otherwise null
  592. */
  593. public function responseType() {
  594. return $this->mapType($this->response->type());
  595. }
  596. /**
  597. * Maps a content-type back to an alias
  598. *
  599. * @param mixed $cType Either a string content type to map, or an array of types.
  600. * @return mixed Aliases for the types provided.
  601. * @deprecated Use $this->response->mapType() in your controller instead.
  602. */
  603. public function mapType($cType) {
  604. return $this->response->mapType($cType);
  605. }
  606. /**
  607. * Maps a content type alias back to its mime-type(s)
  608. *
  609. * @param mixed $alias String alias to convert back into a content type. Or an array of aliases to map.
  610. * @return mixed Null on an undefined alias. String value of the mapped alias type. If an
  611. * alias maps to more than one content type, the first one will be returned.
  612. */
  613. public function mapAlias($alias) {
  614. if (is_array($alias)) {
  615. return array_map(array($this, 'mapAlias'), $alias);
  616. }
  617. $type = $this->response->getMimeType($alias);
  618. if ($type) {
  619. if (is_array($type)) {
  620. return $type[0];
  621. }
  622. return $type;
  623. }
  624. return null;
  625. }
  626. /**
  627. * Add a new mapped input type. Mapped input types are automatically
  628. * converted by RequestHandlerComponent during the startup() callback.
  629. *
  630. * @param string $type The type alias being converted, ie. json
  631. * @param array $handler The handler array for the type. The first index should
  632. * be the handling callback, all other arguments should be additional parameters
  633. * for the handler.
  634. * @return void
  635. * @throws CakeException
  636. */
  637. public function addInputType($type, $handler) {
  638. if (!is_array($handler) || !isset($handler[0]) || !is_callable($handler[0])) {
  639. throw new CakeException(__d('cake_dev', 'You must give a handler callback.'));
  640. }
  641. $this->_inputTypeMap[$type] = $handler;
  642. }
  643. }