PageRenderTime 69ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/system/php/reflection/reflection.php

http://github.com/facebook/hiphop-php
PHP | 2634 lines | 1173 code | 167 blank | 1294 comment | 106 complexity | 821287e02e02577cf90ac246dba6cdc3 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?php
  2. ///////////////////////////////////////////////////////////////////////////////
  3. // helpers
  4. // This doc comment block generated by idl/sysdoc.php
  5. /**
  6. * ( excerpt from http://php.net/manual/en/class.reflector.php )
  7. *
  8. * Reflector is an interface implemented by all exportable Reflection
  9. * classes.
  10. *
  11. */
  12. interface Reflector {
  13. // This doc comment block generated by idl/sysdoc.php
  14. /**
  15. * ( excerpt from http://php.net/manual/en/reflector.tostring.php )
  16. *
  17. * To string. Warning: This function is currently not documented; only its
  18. * argument list is available.
  19. *
  20. */
  21. public function __toString();
  22. }
  23. // This doc comment block generated by idl/sysdoc.php
  24. /**
  25. * ( excerpt from http://php.net/manual/en/class.reflectionexception.php )
  26. *
  27. * The ReflectionException class.
  28. *
  29. */
  30. class ReflectionException extends Exception {
  31. }
  32. ///////////////////////////////////////////////////////////////////////////////
  33. // parameter
  34. // This doc comment block generated by idl/sysdoc.php
  35. /**
  36. * ( excerpt from http://php.net/manual/en/class.reflectionparameter.php )
  37. *
  38. * The ReflectionParameter class retrieves information about function's or
  39. * method's parameters.
  40. *
  41. * To introspect function parameters, first create an instance of the
  42. * ReflectionFunction or ReflectionMethod classes and then use their
  43. * ReflectionFunctionAbstract::getParameters() method to retrieve an array
  44. * of parameters.
  45. *
  46. */
  47. class ReflectionParameter implements Reflector {
  48. public $info;
  49. public $name;
  50. // This doc comment block generated by idl/sysdoc.php
  51. /**
  52. * ( excerpt from
  53. * http://php.net/manual/en/reflectionparameter.construct.php )
  54. *
  55. * Constructs a ReflectionParameter class. Warning: This function is
  56. * currently not documented; only its argument list is available.
  57. *
  58. * @func mixed The function to reflect parameters from.
  59. * @param mixed The parameter.
  60. *
  61. * @return mixed No value is returned.
  62. */
  63. public function __construct($func, $param) {
  64. if ($func && $param) {
  65. $params = $func->getParameters();
  66. $this->info = $params[$param]->info;
  67. $this->name = $this->info['name'];
  68. }
  69. }
  70. // This doc comment block generated by idl/sysdoc.php
  71. /**
  72. * ( excerpt from http://php.net/manual/en/reflectionparameter.tostring.php
  73. * )
  74. *
  75. * To string. Warning: This function is currently not documented; only its
  76. * argument list is available.
  77. *
  78. */
  79. public function __toString() {
  80. // TODO
  81. return "";
  82. }
  83. // This doc comment block generated by idl/sysdoc.php
  84. /**
  85. * ( excerpt from http://php.net/manual/en/reflectionparameter.export.php )
  86. *
  87. * Exports. Warning: This function is currently not documented; only its
  88. * argument list is available.
  89. *
  90. * @func mixed The function name.
  91. * @param mixed The parameter name.
  92. * @ret mixed Setting to TRUE will return the export, as opposed
  93. * to emitting it. Setting to FALSE (the default) will
  94. * do the opposite.
  95. *
  96. * @return mixed The exported reflection.
  97. */
  98. public static function export($func, $param, $ret=false) {
  99. $obj = new ReflectionParameter($func, $param);
  100. $str = (string)$obj;
  101. if ($ret) {
  102. return $str;
  103. }
  104. print $str;
  105. }
  106. // This doc comment block generated by idl/sysdoc.php
  107. /**
  108. * ( excerpt from http://php.net/manual/en/reflectionparameter.getname.php
  109. * )
  110. *
  111. * Gets the name of the parameter.
  112. *
  113. * @return mixed The name of the reflected parameter.
  114. */
  115. public function getName() {
  116. return $this->info['name'];
  117. }
  118. // This doc comment block generated by idl/sysdoc.php
  119. /**
  120. * ( excerpt from
  121. * http://php.net/manual/en/reflectionparameter.ispassedbyreference.php )
  122. *
  123. * Checks if the parameter is passed in by reference. Warning: This
  124. * function is currently not documented; only its argument list is
  125. * available.
  126. *
  127. * @return mixed TRUE if the parameter is passed in by reference,
  128. * otherwise FALSE
  129. */
  130. public function isPassedByReference() {
  131. return isset($this->info['ref']);
  132. }
  133. // This doc comment block generated by idl/sysdoc.php
  134. /**
  135. * ( excerpt from
  136. * http://php.net/manual/en/reflectionparameter.getdeclaringclass.php )
  137. *
  138. * Gets the declaring class. Warning: This function is currently not
  139. * documented; only its argument list is available.
  140. *
  141. * @return mixed A ReflectionClass object.
  142. */
  143. public function getDeclaringClass() {
  144. if (empty($this->info['class'])) {
  145. return null;
  146. }
  147. return new ReflectionClass($this->info['class']);
  148. }
  149. // This doc comment block generated by idl/sysdoc.php
  150. /**
  151. * ( excerpt from
  152. * http://php.net/manual/en/reflectionparameter.getdeclaringfunction.php )
  153. *
  154. * Gets the declaring function. Warning: This function is currently not
  155. * documented; only its argument list is available.
  156. *
  157. * @return mixed A ReflectionFunction object.
  158. */
  159. public function getDeclaringFunction() {
  160. if (empty($this->info['class'])) {
  161. return new ReflectionFunction($this->info['function']);
  162. }
  163. return new ReflectionMethod($this->info['class'], $this->info['function']);
  164. }
  165. // This doc comment block generated by idl/sysdoc.php
  166. /**
  167. * ( excerpt from http://php.net/manual/en/reflectionparameter.getclass.php
  168. * )
  169. *
  170. * Gets a class. Warning: This function is currently not documented; only
  171. * its argument list is available.
  172. *
  173. * @return mixed A ReflectionClass object.
  174. */
  175. public function getClass() {
  176. if (empty($this->info['type'])) {
  177. return null;
  178. }
  179. $ltype = strtolower($this->info['type']);
  180. if (hphp_scalar_typehints_enabled()) {
  181. $nonClassTypehints = array(
  182. 'bool' => 1,
  183. 'boolean' => 1,
  184. 'int' => 1,
  185. 'integer' => 1,
  186. 'real' => 1,
  187. 'double' => 1,
  188. 'float' => 1,
  189. 'string' => 1,
  190. 'array' => 1
  191. );
  192. if (isset($nonClassTypehints[$ltype])) {
  193. return null;
  194. }
  195. } else if ($ltype === 'array') {
  196. return null;
  197. }
  198. return new ReflectionClass($this->info['type']);
  199. }
  200. public function getTypehintText() {
  201. if (isset($this->info['type'])) {
  202. return $this->info['type'];
  203. }
  204. return '';
  205. }
  206. public function getTypeText() {
  207. if (isset($this->info['type_hint'])) {
  208. return $this->info['type_hint'];
  209. }
  210. return '';
  211. }
  212. // This doc comment block generated by idl/sysdoc.php
  213. /**
  214. * ( excerpt from http://php.net/manual/en/reflectionparameter.isarray.php
  215. * )
  216. *
  217. * Checks if the parameter expects an array.
  218. *
  219. * @return mixed TRUE if an array is expected, FALSE otherwise.
  220. */
  221. public function isArray() {
  222. return $this->info['type'] == 'array';
  223. }
  224. // This doc comment block generated by idl/sysdoc.php
  225. /**
  226. * ( excerpt from
  227. * http://php.net/manual/en/reflectionparameter.allowsnull.php )
  228. *
  229. * Checks whether the parameter allows NULL. Warning: This function is
  230. * currently not documented; only its argument list is available.
  231. *
  232. * @return mixed TRUE if NULL is allowed, otherwise FALSE
  233. */
  234. public function allowsNull() {
  235. return isset($this->info['nullable']);
  236. }
  237. // This doc comment block generated by idl/sysdoc.php
  238. /**
  239. * ( excerpt from
  240. * http://php.net/manual/en/reflectionparameter.isoptional.php )
  241. *
  242. * Checks if the parameter is optional.
  243. *
  244. * @return mixed TRUE if the parameter is optional, otherwise FALSE
  245. */
  246. public function isOptional() {
  247. return array_key_exists('default', $this->info);
  248. }
  249. // This doc comment block generated by idl/sysdoc.php
  250. /**
  251. * ( excerpt from
  252. * http://php.net/manual/en/reflectionparameter.isdefaultvalueavailable.php
  253. * )
  254. *
  255. * Checks if a default value for the parameter is available.
  256. *
  257. * @return mixed TRUE if a default value is available, otherwise
  258. * FALSE
  259. */
  260. public function isDefaultValueAvailable() {
  261. return array_key_exists('default', $this->info);
  262. }
  263. // This doc comment block generated by idl/sysdoc.php
  264. /**
  265. * ( excerpt from
  266. * http://php.net/manual/en/reflectionparameter.getdefaultvalue.php )
  267. *
  268. * Gets the default value of the parameter for a user-defined function or
  269. * method. If the parameter is not optional a ReflectionException will be
  270. * thrown.
  271. *
  272. * @return mixed The parameters default value.
  273. */
  274. public function getDefaultValue() {
  275. if (!$this->isOptional()) {
  276. throw new ReflectionException('Parameter is not optional');
  277. }
  278. $defaultValue = $this->info['default'];
  279. if ($defaultValue instanceof stdclass) {
  280. if (isset($defaultValue->class)) {
  281. return hphp_get_class_constant($defaultValue->class,
  282. $defaultValue->name);
  283. }
  284. hphp_throw_fatal_error($defaultValue->msg);
  285. }
  286. return $defaultValue;
  287. }
  288. /**
  289. * @deprecated
  290. */
  291. public function getDefaultValueText() {
  292. return $this->getDefaultValueConstantName();
  293. }
  294. // This doc comment block generated by idl/sysdoc.php
  295. /**
  296. * ( excerpt from
  297. * http://php.net/manual/en/reflectionparameter.getdefaultvalueconstantname.php
  298. * )
  299. *
  300. * Warning: This function is currently not documented; only its argument
  301. * list is available.
  302. *
  303. * @return mixed Returns string on success or NULL on failure.
  304. */
  305. public function getDefaultValueConstantName() {
  306. if (isset($this->info['defaultText'])) {
  307. return $this->info['defaultText'];
  308. }
  309. return '';
  310. }
  311. // This doc comment block generated by idl/sysdoc.php
  312. /**
  313. * ( excerpt from
  314. * http://php.net/manual/en/reflectionparameter.getposition.php )
  315. *
  316. * Gets the position of the parameter.
  317. *
  318. * @return mixed The position of the parameter, left to right,
  319. * starting at position #0.
  320. */
  321. public function getPosition() {
  322. return $this->info['index'];
  323. }
  324. public function getAttribute($name) {
  325. $attrs = $this->info['attributes'];
  326. return isset($attrs[$name]) ? $attrs[$name] : null;
  327. }
  328. public function getAttributes() {
  329. return $this->info['attributes'];
  330. }
  331. public function getAttributeRecursive($name) {
  332. $attrs = $this->getAttributesRecursive();
  333. return isset($attrs[$name]) ? $attrs[$name] : null;
  334. }
  335. public function getAttributesRecursive() {
  336. if (!isset($this->info['class'])) {
  337. return $this->getAttributes();
  338. }
  339. $attrs = array();
  340. $class = $this->getDeclaringClass();
  341. $function_name = $this->info['function'];
  342. $index = $this->info['index'];
  343. self::collectAttributes(&$attrs, $class, $function_name, $index);
  344. return $attrs;
  345. }
  346. // This doc comment block generated by idl/sysdoc.php
  347. /**
  348. * ( excerpt from
  349. * http://php.net/manual/en/reflectionparameter.iscallable.php )
  350. *
  351. * Warning: This function is currently not documented; only its argument
  352. * list is available.
  353. *
  354. * @return mixed Returns TRUE if the parameter is callable, FALSE if
  355. * it is not or NULL on failure.
  356. */
  357. public function isCallable() {
  358. return $this->info['type_hint'] === 'callable';
  359. }
  360. private static function collectAttributes(&$attrs, $class, $function_name,
  361. $index) {
  362. if ($class->hasMethod($function_name)) {
  363. $method = $class->getMethod($function_name);
  364. $params = $method->getParameters();
  365. if (count($params) >= $index) {
  366. $attrs += $params[$index]->getAttributes();
  367. }
  368. }
  369. $parent = $class->getParentClass();
  370. if ($parent) {
  371. self::collectAttributes(
  372. &$attrs,
  373. $parent,
  374. $function_name,
  375. $index);
  376. }
  377. }
  378. }
  379. ///////////////////////////////////////////////////////////////////////////////
  380. // This doc comment block generated by idl/sysdoc.php
  381. /**
  382. * ( excerpt from
  383. * http://php.net/manual/en/class.reflectionfunctionabstract.php )
  384. *
  385. * A parent class to ReflectionFunction, read its description for details.
  386. *
  387. */
  388. class ReflectionFunctionAbstract {
  389. public $info;
  390. // This doc comment block generated by idl/sysdoc.php
  391. /**
  392. * ( excerpt from
  393. * http://php.net/manual/en/reflectionfunctionabstract.getname.php )
  394. *
  395. * Get the name of the function. Warning: This function is currently not
  396. * documented; only its argument list is available.
  397. *
  398. * @return mixed The name of the function.
  399. */
  400. public function getName() {
  401. return $this->info['name'];
  402. }
  403. // This doc comment block generated by idl/sysdoc.php
  404. /**
  405. * ( excerpt from
  406. * http://php.net/manual/en/reflectionfunctionabstract.isinternal.php )
  407. *
  408. * Checks whether the function is internal, as opposed to user-defined.
  409. * Warning: This function is currently not documented; only its argument
  410. * list is available.
  411. *
  412. * @return mixed TRUE if it's internal, otherwise FALSE
  413. */
  414. public function isInternal() {
  415. return isset($this->info['internal']);
  416. }
  417. public function getClosure() {
  418. return $this->info['closure'];
  419. }
  420. // This doc comment block generated by idl/sysdoc.php
  421. /**
  422. * ( excerpt from
  423. * http://php.net/manual/en/reflectionfunctionabstract.isclosure.php )
  424. *
  425. * Checks whether it's a closure. Warning: This function is currently not
  426. * documented; only its argument list is available.
  427. *
  428. * @return mixed TRUE if it's a closure, otherwise FALSE
  429. */
  430. public function isClosure() {
  431. return !empty($this->info['is_closure']);
  432. }
  433. // This doc comment block generated by idl/sysdoc.php
  434. /**
  435. * ( excerpt from
  436. * http://php.net/manual/en/reflectionfunctionabstract.isgenerator.php )
  437. *
  438. * Warning: This function is currently not documented; only its argument
  439. * list is available.
  440. *
  441. * @return mixed Returns TRUE if the function is generator, FALSE if
  442. * it is not or NULL on failure.
  443. */
  444. public function isGenerator() {
  445. return !empty($this->info['is_generator']);
  446. }
  447. // This doc comment block generated by idl/sysdoc.php
  448. /**
  449. * ( excerpt from
  450. * http://php.net/manual/en/reflectionfunctionabstract.isuserdefined.php )
  451. *
  452. * Checks whether the function is user-defined, as opposed to internal.
  453. * Warning: This function is currently not documented; only its argument
  454. * list is available.
  455. *
  456. * @return mixed TRUE if it's user-defined, otherwise false;
  457. */
  458. public function isUserDefined() {
  459. return !isset($this->info['internal']);
  460. }
  461. // This doc comment block generated by idl/sysdoc.php
  462. /**
  463. * ( excerpt from
  464. * http://php.net/manual/en/reflectionfunctionabstract.getfilename.php )
  465. *
  466. * Gets the file name from a user-defined function. Warning: This function
  467. * is currently not documented; only its argument list is available.
  468. *
  469. * @return mixed The file name.
  470. */
  471. public function getFileName() {
  472. return $this->info['file'];
  473. }
  474. // This doc comment block generated by idl/sysdoc.php
  475. /**
  476. * ( excerpt from
  477. * http://php.net/manual/en/reflectionfunctionabstract.getstartline.php )
  478. *
  479. * Gets the starting line number of the function. Warning: This function
  480. * is currently not documented; only its argument list is available.
  481. *
  482. * @return mixed The starting line number.
  483. */
  484. public function getStartLine() {
  485. return $this->info['line1'];
  486. }
  487. // This doc comment block generated by idl/sysdoc.php
  488. /**
  489. * ( excerpt from
  490. * http://php.net/manual/en/reflectionfunctionabstract.getendline.php )
  491. *
  492. * Get the ending line number. Warning: This function is currently not
  493. * documented; only its argument list is available.
  494. *
  495. * @return mixed The ending line number of the user defined function,
  496. * or FALSE if unknown.
  497. */
  498. public function getEndLine() {
  499. return $this->info['line2'];
  500. }
  501. // This doc comment block generated by idl/sysdoc.php
  502. /**
  503. * ( excerpt from
  504. * http://php.net/manual/en/reflectionfunctionabstract.getdoccomment.php )
  505. *
  506. * Get a Doc comment from a function. Warning: This function is currently
  507. * not documented; only its argument list is available.
  508. *
  509. * @return mixed The doc comment if it exists, otherwise FALSE
  510. */
  511. public function getDocComment() {
  512. return $this->info['doc'];
  513. }
  514. // This doc comment block generated by idl/sysdoc.php
  515. /**
  516. * ( excerpt from
  517. * http://php.net/manual/en/reflectionfunctionabstract.getstaticvariables.php
  518. * )
  519. *
  520. * Get the static variables. Warning: This function is currently not
  521. * documented; only its argument list is available.
  522. *
  523. * @return mixed An array of static variables.
  524. */
  525. public function getStaticVariables() {
  526. return $this->info['static_variables'];
  527. }
  528. // This doc comment block generated by idl/sysdoc.php
  529. /**
  530. * ( excerpt from
  531. * http://php.net/manual/en/reflectionfunctionabstract.returnsreference.php
  532. * )
  533. *
  534. * Checks whether the function returns a reference. Warning: This function
  535. * is currently not documented; only its argument list is available.
  536. *
  537. * @return mixed TRUE if it returns a reference, otherwise FALSE
  538. */
  539. public function returnsReference() {
  540. return isset($this->info['ref']);
  541. }
  542. // This doc comment block generated by idl/sysdoc.php
  543. /**
  544. * ( excerpt from
  545. * http://php.net/manual/en/reflectionfunctionabstract.getparameters.php )
  546. *
  547. * Get the parameters as an array of ReflectionParameter. Warning: This
  548. * function is currently not documented; only its argument list is
  549. * available.
  550. *
  551. * @return mixed The parameters, as a ReflectionParameter object.
  552. */
  553. public function getParameters() {
  554. $ret = array();
  555. foreach ($this->info['params'] as $name => $info) {
  556. $param = new ReflectionParameter(null, null);
  557. $param->info = $info;
  558. $param->name = $info['name'];
  559. $ret[] = $param;
  560. }
  561. return $ret;
  562. }
  563. // This doc comment block generated by idl/sysdoc.php
  564. /**
  565. * ( excerpt from
  566. * http://php.net/manual/en/reflectionfunctionabstract.getnumberofparameters.php
  567. * )
  568. *
  569. * Get the number of parameters that a function defines, both optional and
  570. * required. Warning: This function is currently not documented; only its
  571. * argument list is available.
  572. *
  573. * @return mixed The number of parameters.
  574. */
  575. public function getNumberOfParameters() {
  576. return count($this->info['params']);
  577. }
  578. // This doc comment block generated by idl/sysdoc.php
  579. /**
  580. * ( excerpt from
  581. * http://php.net/manual/en/reflectionfunctionabstract.getnumberofrequiredparameters.php
  582. * )
  583. *
  584. * Get the number of required parameters that a function defines. Warning:
  585. * This function is currently not documented; only its argument list is
  586. * available.
  587. *
  588. * @return mixed The number of required parameters.
  589. */
  590. public function getNumberOfRequiredParameters() {
  591. $count = 0;
  592. $params = $this->getParameters();
  593. foreach ($params as $name => $param) {
  594. if ($param->isOptional()) {
  595. break;
  596. }
  597. $count++;
  598. }
  599. return $count;
  600. }
  601. public function getReturnTypeText() {
  602. if (isset($this->info['return_type'])) {
  603. return $this->info['return_type'];
  604. }
  605. return '';
  606. }
  607. }
  608. ///////////////////////////////////////////////////////////////////////////////
  609. // function
  610. // This doc comment block generated by idl/sysdoc.php
  611. /**
  612. * ( excerpt from http://php.net/manual/en/class.reflectionfunction.php )
  613. *
  614. * The ReflectionFunction class reports information about a function.
  615. *
  616. */
  617. class ReflectionFunction extends ReflectionFunctionAbstract
  618. implements Reflector {
  619. const IS_DEPRECATED = 262144;
  620. // This doc comment block generated by idl/sysdoc.php
  621. /**
  622. * ( excerpt from http://php.net/manual/en/reflectionfunction.construct.php
  623. * )
  624. *
  625. * Constructs a ReflectionFunction object.
  626. *
  627. * @name mixed The name of the function to reflect or a closure.
  628. *
  629. * @return mixed No value is returned.
  630. */
  631. public function __construct($name) {
  632. if ($name instanceof Closure) {
  633. $this->info = hphp_get_closure_info($name);
  634. } else {
  635. $this->info = hphp_get_function_info($name);
  636. if (empty($this->info)) {
  637. throw new ReflectionException("Function $name does not exist");
  638. }
  639. }
  640. }
  641. // This doc comment block generated by idl/sysdoc.php
  642. /**
  643. * ( excerpt from http://php.net/manual/en/reflectionfunction.tostring.php
  644. * )
  645. *
  646. * To string.
  647. *
  648. * @return mixed Returns ReflectionFunction::export()-like output for
  649. * the function.
  650. */
  651. public function __toString() {
  652. //TODO
  653. return "";
  654. }
  655. // This doc comment block generated by idl/sysdoc.php
  656. /**
  657. * ( excerpt from http://php.net/manual/en/reflectionfunction.export.php )
  658. *
  659. * Exports a Reflected function.
  660. *
  661. * @name mixed The reflection to export.
  662. * @ret mixed Setting to TRUE will return the export, as opposed
  663. * to emitting it. Setting to FALSE (the default) will
  664. * do the opposite.
  665. *
  666. * @return mixed If the return parameter is set to TRUE, then the
  667. * export is returned as a string, otherwise NULL is
  668. * returned.
  669. */
  670. public static function export($name, $ret=false) {
  671. $obj = new ReflectionFunction($name);
  672. $str = (string)$obj;
  673. if ($ret) {
  674. return $str;
  675. }
  676. print $str;
  677. }
  678. // This doc comment block generated by idl/sysdoc.php
  679. /**
  680. * ( excerpt from http://php.net/manual/en/reflectionfunction.invoke.php )
  681. *
  682. * Invokes a reflected function.
  683. *
  684. * @return mixed Returns the result of the invoked function call.
  685. */
  686. public function invoke() {
  687. $args = func_get_args();
  688. if (isset($this->info['closureobj'])) {
  689. $closure = $this->info['closureobj'];
  690. return hphp_invoke_method($closure, get_class($closure),
  691. '__invoke', $args);
  692. }
  693. return hphp_invoke($this->info['name'], $args);
  694. }
  695. // This doc comment block generated by idl/sysdoc.php
  696. /**
  697. * ( excerpt from
  698. * http://php.net/manual/en/reflectionfunction.invokeargs.php )
  699. *
  700. * Invokes the function and pass its arguments as array.
  701. *
  702. * @args mixed The passed arguments to the function as an array,
  703. * much like call_user_func_array() works.
  704. *
  705. * @return mixed Returns the result of the invoked function
  706. */
  707. public function invokeArgs($args) {
  708. if (isset($this->info['closureobj'])) {
  709. $closure = $this->info['closureobj'];
  710. return hphp_invoke_method($closure, get_class($closure),
  711. '__invoke', array_values($args));
  712. }
  713. return hphp_invoke($this->info['name'], array_values($args));
  714. }
  715. public function getAttribute($name) {
  716. $attrs = $this->info['attributes'];
  717. return isset($attrs[$name]) ? $attrs[$name] : null;
  718. }
  719. public function getAttributes() {
  720. return $this->info['attributes'];
  721. }
  722. public function getAttributeRecursive($name) {
  723. $attrs = $this->info['attributes'];
  724. return isset($attrs[$name]) ? $attrs[$name] : null;
  725. }
  726. public function getAttributesRecursive() {
  727. return $this->info['attributes'];
  728. }
  729. }
  730. ///////////////////////////////////////////////////////////////////////////////
  731. // class
  732. // This doc comment block generated by idl/sysdoc.php
  733. /**
  734. * ( excerpt from http://php.net/manual/en/class.reflectionclass.php )
  735. *
  736. * The ReflectionClass class reports information about a class.
  737. *
  738. */
  739. class ReflectionClass implements Reflector {
  740. const IS_IMPLICIT_ABSTRACT = 16 ;
  741. const IS_EXPLICIT_ABSTRACT = 32 ;
  742. const IS_FINAL = 64 ;
  743. public $name;
  744. private $info = null;
  745. private static $fetched = array();
  746. // This doc comment block generated by idl/sysdoc.php
  747. /**
  748. * ( excerpt from http://php.net/manual/en/reflectionclass.construct.php )
  749. *
  750. * Constructs a new ReflectionClass object. Warning: This function is
  751. * currently not documented; only its argument list is available.
  752. *
  753. * @name mixed Either a string containing the name of the class to
  754. * reflect, or an object.
  755. *
  756. * @return mixed No value is returned.
  757. */
  758. public function __construct($name) {
  759. if (is_object($name)) {
  760. $name = get_class($name);
  761. }
  762. $this->name = hphp_get_original_class_name($name);
  763. if (empty($this->name)) {
  764. throw new ReflectionException("Class $name does not exist");
  765. }
  766. }
  767. private function fetch($what) {
  768. if (!$this->info) {
  769. $this->info = self::fetch_recur($this->name);
  770. $this->info['properties'] += $this->info['private_properties'];
  771. }
  772. return $this->info[$what];
  773. }
  774. private static function fetch_recur($name) {
  775. if (isset(self::$fetched[$name])) return self::$fetched[$name];
  776. $info = hphp_get_class_info($name);
  777. if (empty($info)) {
  778. throw new ReflectionException("Class $name does not exist");
  779. }
  780. $info['attributes_rec'] = $info['attributes'];
  781. $abstract = isset($info['abstract']) || isset($info['interface']);
  782. // flattening the trees, so it's easier for lookups
  783. foreach ($info['interfaces'] as $interface => $_) {
  784. $p = self::fetch_recur($interface);
  785. if ($abstract) $info['methods'] += $p['methods'];
  786. $info['constants'] += $p['constants'];
  787. $info['interfaces'] += $p['interfaces'];
  788. }
  789. $parent = $info['parent'];
  790. if (!empty($parent)) {
  791. $p = self::fetch_recur($parent);
  792. if (isset($p['interface'])) {
  793. $info['interfaces'][$parent] = 1;
  794. } else {
  795. $info['properties'] += $p['properties'];
  796. }
  797. $info['methods'] += $p['methods'];
  798. $info['constants'] += $p['constants'];
  799. $info['interfaces'] += $p['interfaces'];
  800. $info['attributes_rec'] += $p['attributes_rec'];
  801. }
  802. self::$fetched[$name] = $info;
  803. return $info;
  804. }
  805. private function check($what) {
  806. if (!$this->info) {
  807. $this->info = self::fetch_recur($this->name);
  808. }
  809. return isset($this->info[$what]);
  810. }
  811. private function test($what, $name) {
  812. $v = $this->fetch($what);
  813. return $v && isset($v[$name]);
  814. }
  815. // This doc comment block generated by idl/sysdoc.php
  816. /**
  817. * ( excerpt from http://php.net/manual/en/reflectionclass.tostring.php )
  818. *
  819. * Returns the string representation of the ReflectionClass object.
  820. *
  821. * @return mixed A string representation of this ReflectionClass
  822. * instance.
  823. */
  824. public function __toString() {
  825. return "";
  826. }
  827. // This doc comment block generated by idl/sysdoc.php
  828. /**
  829. * ( excerpt from http://php.net/manual/en/reflectionclass.export.php )
  830. *
  831. * Exports a reflected class.
  832. *
  833. * @name mixed The reflection to export.
  834. * @ret mixed Setting to TRUE will return the export, as opposed
  835. * to emitting it. Setting to FALSE (the default) will
  836. * do the opposite.
  837. *
  838. * @return mixed If the return parameter is set to TRUE, then the
  839. * export is returned as a string, otherwise NULL is
  840. * returned.
  841. */
  842. public static function export($name, $ret=false) {
  843. $obj = new ReflectionClass($name);
  844. $str = (string)$obj;
  845. if ($ret) {
  846. return $str;
  847. }
  848. print $str;
  849. }
  850. // This doc comment block generated by idl/sysdoc.php
  851. /**
  852. * ( excerpt from http://php.net/manual/en/reflectionclass.getname.php )
  853. *
  854. * Gets the class name. Warning: This function is currently not
  855. * documented; only its argument list is available.
  856. *
  857. * @return mixed The class name.
  858. */
  859. public function getName() {
  860. return $this->name;
  861. }
  862. // This doc comment block generated by idl/sysdoc.php
  863. /**
  864. * ( excerpt from http://php.net/manual/en/reflectionclass.isinternal.php )
  865. *
  866. * Checks if the class is defined internally by an extension, or the core,
  867. * as opposed to user-defined.
  868. *
  869. * @return mixed Returns TRUE on success or FALSE on failure.
  870. */
  871. public function isInternal() {
  872. return $this->check('internal');
  873. }
  874. // This doc comment block generated by idl/sysdoc.php
  875. /**
  876. * ( excerpt from
  877. * http://php.net/manual/en/reflectionclass.isuserdefined.php )
  878. *
  879. * Checks whether the class is user-defined, as opposed to internal.
  880. *
  881. * @return mixed Returns TRUE on success or FALSE on failure.
  882. */
  883. public function isUserDefined() {
  884. return !$this->check('internal');
  885. }
  886. // This doc comment block generated by idl/sysdoc.php
  887. /**
  888. * ( excerpt from
  889. * http://php.net/manual/en/reflectionclass.isinstantiable.php )
  890. *
  891. * Checks if the class is instantiable.
  892. *
  893. * @return mixed Returns TRUE on success or FALSE on failure.
  894. */
  895. public function isInstantiable() {
  896. return !$this->check('abstract');
  897. }
  898. // This doc comment block generated by idl/sysdoc.php
  899. /**
  900. * ( excerpt from http://php.net/manual/en/reflectionclass.hasconstant.php
  901. * )
  902. *
  903. * Checks whether the class has a specific constant defined or not.
  904. *
  905. * @name mixed The name of the constant being checked for.
  906. *
  907. * @return mixed TRUE if the constant is defined, otherwise FALSE.
  908. */
  909. public function hasConstant($name) {
  910. return $this->test('constants', $name);
  911. }
  912. // This doc comment block generated by idl/sysdoc.php
  913. /**
  914. * ( excerpt from http://php.net/manual/en/reflectionclass.hasmethod.php )
  915. *
  916. * Checks whether a specific method is defined in a class.
  917. *
  918. * @name mixed Name of the method being checked for.
  919. *
  920. * @return mixed TRUE if it has the method, otherwise FALSE
  921. */
  922. public function hasMethod($name) {
  923. return $this->test('methods', strtolower($name));
  924. }
  925. // This doc comment block generated by idl/sysdoc.php
  926. /**
  927. * ( excerpt from http://php.net/manual/en/reflectionclass.hasproperty.php
  928. * )
  929. *
  930. * Checks whether the specified property is defined.
  931. *
  932. * @name mixed Name of the property being checked for.
  933. *
  934. * @return mixed TRUE if it has the property, otherwise FALSE
  935. */
  936. public function hasProperty($name) {
  937. return $this->test('properties', $name);
  938. }
  939. // This doc comment block generated by idl/sysdoc.php
  940. /**
  941. * ( excerpt from http://php.net/manual/en/reflectionclass.getfilename.php
  942. * )
  943. *
  944. * Gets the filename of the file in which the class has been defined.
  945. *
  946. * @return mixed Returns the filename of the file in which the class
  947. * has been defined. If the class is defined in the PHP
  948. * core or in a PHP extension, FALSE is returned.
  949. */
  950. public function getFileName() {
  951. return $this->fetch('file');
  952. }
  953. // This doc comment block generated by idl/sysdoc.php
  954. /**
  955. * ( excerpt from http://php.net/manual/en/reflectionclass.getstartline.php
  956. * )
  957. *
  958. * Get the starting line number. Warning: This function is currently not
  959. * documented; only its argument list is available.
  960. *
  961. * @return mixed The starting line number, as an integer.
  962. */
  963. public function getStartLine() {
  964. return $this->fetch('line1');
  965. }
  966. // This doc comment block generated by idl/sysdoc.php
  967. /**
  968. * ( excerpt from http://php.net/manual/en/reflectionclass.getendline.php )
  969. *
  970. * Gets end line number from a user-defined class definition.
  971. *
  972. * @return mixed The ending line number of the user defined class, or
  973. * FALSE if unknown.
  974. */
  975. public function getEndLine() {
  976. return $this->fetch('line2');
  977. }
  978. // This doc comment block generated by idl/sysdoc.php
  979. /**
  980. * ( excerpt from
  981. * http://php.net/manual/en/reflectionclass.getdoccomment.php )
  982. *
  983. * Gets doc comments from a class. Warning: This function is currently not
  984. * documented; only its argument list is available.
  985. *
  986. * @return mixed The doc comment if it exists, otherwise FALSE
  987. */
  988. public function getDocComment() {
  989. return $this->fetch('doc');
  990. }
  991. // This doc comment block generated by idl/sysdoc.php
  992. /**
  993. * ( excerpt from
  994. * http://php.net/manual/en/reflectionclass.getconstructor.php )
  995. *
  996. * Gets the constructor of the reflected class.
  997. *
  998. * @return mixed A ReflectionMethod object reflecting the class'
  999. * constructor, or NULL if the class has no
  1000. * constructor.
  1001. */
  1002. public function getConstructor() {
  1003. if ($this->hasMethod('__construct')) {
  1004. return $this->getMethod('__construct');
  1005. }
  1006. if (!$this->isTrait() && $this->hasMethod($name = $this->name)) {
  1007. return $this->getMethod($name);
  1008. }
  1009. return null;
  1010. }
  1011. // This doc comment block generated by idl/sysdoc.php
  1012. /**
  1013. * ( excerpt from http://php.net/manual/en/reflectionclass.getmethod.php )
  1014. *
  1015. * Gets a ReflectionMethod for a class method.
  1016. *
  1017. * @name mixed The method name to reflect.
  1018. *
  1019. * @return mixed A ReflectionMethod.
  1020. */
  1021. public function getMethod($name) {
  1022. if (!$this->info) {
  1023. $method = hphp_get_method_info($this->name, $name);
  1024. } else {
  1025. $lname = strtolower($name);
  1026. $methods = $this->info['methods'];
  1027. if (isset($methods[$lname])) $method = $methods[$lname];
  1028. }
  1029. if (empty($method)) {
  1030. $class = $this->name;
  1031. throw new ReflectionException("Method $class::$name does not exist");
  1032. }
  1033. $ret = new ReflectionMethod(null, null);
  1034. $ret->info = $method;
  1035. $ret->name = $method['name'];
  1036. $ret->class = $method['class'];
  1037. return $ret;
  1038. }
  1039. // This doc comment block generated by idl/sysdoc.php
  1040. /**
  1041. * ( excerpt from http://php.net/manual/en/reflectionclass.getmethods.php )
  1042. *
  1043. * Gets an array of methods for the class.
  1044. *
  1045. * @filter mixed Filter the results to include only methods with
  1046. * certain attributes. Defaults to no filtering.
  1047. *
  1048. * Any combination of ReflectionMethod::IS_STATIC,
  1049. * ReflectionMethod::IS_PUBLIC,
  1050. * ReflectionMethod::IS_PROTECTED,
  1051. * ReflectionMethod::IS_PRIVATE,
  1052. * ReflectionMethod::IS_ABSTRACT,
  1053. * ReflectionMethod::IS_FINAL.
  1054. *
  1055. * @return mixed An array of ReflectionMethod objects reflecting each
  1056. * method.
  1057. */
  1058. public function getMethods($filter = 0xFFFF) {
  1059. $ret = array();
  1060. $methods = $this->fetch('methods');
  1061. foreach ($methods as $name => $_) {
  1062. $m = $this->getMethod($name);
  1063. if ((($filter & ReflectionMethod::IS_PUBLIC)) && $m->isPublic() ||
  1064. (($filter & ReflectionMethod::IS_PROTECTED)) && $m->isProtected() ||
  1065. (($filter & ReflectionMethod::IS_PRIVATE)) && $m->isPrivate() ||
  1066. (($filter & ReflectionMethod::IS_STATIC)) && $m->isStatic() ||
  1067. (($filter & ReflectionMethod::IS_FINAL)) && $m->isFinal() ||
  1068. (($filter & ReflectionMethod::IS_ABSTRACT && $m->isAbstract()))) {
  1069. $ret[] = $m;
  1070. }
  1071. }
  1072. return $ret;
  1073. }
  1074. // This doc comment block generated by idl/sysdoc.php
  1075. /**
  1076. * ( excerpt from http://php.net/manual/en/reflectionclass.getproperty.php
  1077. * )
  1078. *
  1079. * Gets a ReflectionProperty for a class's property.
  1080. *
  1081. * @name mixed The property name.
  1082. *
  1083. * @return mixed A ReflectionProperty.
  1084. */
  1085. public function getProperty($name) {
  1086. $properties = $this->fetch('properties');
  1087. if (!isset($properties[$name])) {
  1088. $class = $this->info['name'];
  1089. throw new ReflectionException("Property $class::$name does not exist");
  1090. }
  1091. $cls = new ReflectionClass("ReflectionProperty");
  1092. $ret = $cls->newInstanceWithoutConstructor();
  1093. $ret->info = $properties[$name];
  1094. $ret->name = $name;
  1095. $ret->class = $this->info['name'];
  1096. return $ret;
  1097. }
  1098. // This doc comment block generated by idl/sysdoc.php
  1099. /**
  1100. * ( excerpt from
  1101. * http://php.net/manual/en/reflectionclass.getproperties.php )
  1102. *
  1103. * Retrieves reflected properties.
  1104. *
  1105. * @filter mixed The optional filter, for filtering desired property
  1106. * types. It's configured using the ReflectionProperty
  1107. * constants, and defaults to all property types.
  1108. *
  1109. * @return mixed An array of ReflectionProperty objects.
  1110. */
  1111. public function getProperties($filter = 0xFFFF) {
  1112. $ret = array();
  1113. foreach ($this->fetch('properties') as $name => $_) {
  1114. $p = $this->getProperty($name);
  1115. if (($filter & ReflectionProperty::IS_PUBLIC) && $p->isPublic() ||
  1116. ($filter & ReflectionProperty::IS_PROTECTED) && $p->isProtected() ||
  1117. ($filter & ReflectionProperty::IS_PRIVATE) && $p->isPrivate() ||
  1118. ($filter & ReflectionProperty::IS_STATIC) && $p->isStatic()) {
  1119. $ret[] = $p;
  1120. }
  1121. }
  1122. return $ret;
  1123. }
  1124. // This doc comment block generated by idl/sysdoc.php
  1125. /**
  1126. * ( excerpt from http://php.net/manual/en/reflectionclass.getconstants.php
  1127. * )
  1128. *
  1129. * Gets defined constants from a class. Warning: This function is
  1130. * currently not documented; only its argument list is available.
  1131. *
  1132. * @return mixed An array of constants. Constant name in key,
  1133. * constant value in value.
  1134. */
  1135. public function getConstants() {
  1136. return $this->fetch('constants');
  1137. }
  1138. // This doc comment block generated by idl/sysdoc.php
  1139. /**
  1140. * ( excerpt from http://php.net/manual/en/reflectionclass.getconstant.php
  1141. * )
  1142. *
  1143. * Gets the defined constant. Warning: This function is currently not
  1144. * documented; only its argument list is available.
  1145. *
  1146. * @name mixed Name of the constant.
  1147. *
  1148. * @return mixed Value of the constant.
  1149. */
  1150. public function getConstant($name) {
  1151. $constants = $this->fetch('constants');
  1152. if (!isset($constants[$name])) {
  1153. $class = $this->info['name'];
  1154. throw new ReflectionException("Class constant $class::$name does not exist");
  1155. }
  1156. return $constants[$name];
  1157. }
  1158. // This doc comment block generated by idl/sysdoc.php
  1159. /**
  1160. * ( excerpt from
  1161. * http://php.net/manual/en/reflectionclass.getinterfaces.php )
  1162. *
  1163. * Gets the interfaces.
  1164. *
  1165. * @return mixed An associative array of interfaces, with keys as
  1166. * interface names and the array values as
  1167. * ReflectionClass objects.
  1168. */
  1169. public function getInterfaces() {
  1170. $ret = array();
  1171. foreach ($this->fetch('interfaces') as $name => $_) {
  1172. $cls = new ReflectionClass($name);
  1173. if ($cls->isInterface()) {
  1174. $ret[$cls->getName()] = $cls;
  1175. }
  1176. }
  1177. return $ret;
  1178. }
  1179. // This doc comment block generated by idl/sysdoc.php
  1180. /**
  1181. * ( excerpt from http://php.net/manual/en/reflectionclass.gettraits.php )
  1182. *
  1183. * Warning: This function is currently not documented; only its argument
  1184. * list is available.
  1185. *
  1186. * @return mixed Returns an array with trait names in keys and
  1187. * instances of trait's ReflectionClass in values.
  1188. * Returns NULL in case of an error.
  1189. */
  1190. public function getTraits() {
  1191. $ret = array();
  1192. foreach ($this->fetch('traits') as $name => $_) {
  1193. $cls = new ReflectionClass($name);
  1194. if ($cls->isTrait()) {
  1195. $ret[$cls->getName()] = $cls;
  1196. }
  1197. }
  1198. return $ret;
  1199. }
  1200. // This doc comment block generated by idl/sysdoc.php
  1201. /**
  1202. * ( excerpt from
  1203. * http://php.net/manual/en/reflectionclass.getinterfacenames.php )
  1204. *
  1205. * Get the interface names.
  1206. *
  1207. * @return mixed A numerical array with interface names as the
  1208. * values.
  1209. */
  1210. public function getInterfaceNames() {
  1211. $ret = array();
  1212. foreach ($this->fetch('interfaces') as $name => $_) {
  1213. $cls = new ReflectionClass($name);
  1214. if ($cls->isInterface()) {
  1215. $ret[] = $cls->getName();
  1216. }
  1217. }
  1218. return $ret;
  1219. }
  1220. // This doc comment block generated by idl/sysdoc.php
  1221. /**
  1222. * ( excerpt from
  1223. * http://php.net/manual/en/reflectionclass.gettraitnames.php )
  1224. *
  1225. * Warning: This function is currently not documented; only its argument
  1226. * list is available.
  1227. *
  1228. * @return mixed Returns an array with trait names in values. Returns
  1229. * NULL in case of an error.
  1230. */
  1231. public function getTraitNames() {
  1232. $ret = array();
  1233. foreach ($this->fetch('traits') as $name => $_) {
  1234. $cls = new ReflectionClass($name);
  1235. if ($cls->isTrait()) {
  1236. $ret[] = $cls->getName();
  1237. }
  1238. }
  1239. return $ret;
  1240. }
  1241. // This doc comment block generated by idl/sysdoc.php
  1242. /**
  1243. * ( excerpt from
  1244. * http://php.net/manual/en/reflectionclass.gettraitaliases.php )
  1245. *
  1246. * Warning: This function is currently not documented; only its argument
  1247. * list is available.
  1248. *
  1249. * @return mixed Returns an array with new method names in keys and
  1250. * original names (in the format "TraitName::original")
  1251. * in values. Returns NULL in case of an error.
  1252. */
  1253. public function getTraitAliases() {
  1254. $ret = array();
  1255. foreach ($this->fetch('trait_aliases') as $old_name => $new_name) {
  1256. $ret[$old_name] = $new_name;
  1257. }
  1258. return $ret;
  1259. }
  1260. // This doc comment block generated by idl/sysdoc.php
  1261. /**
  1262. * ( excerpt from http://php.net/manual/en/reflectionclass.isinterface.php
  1263. * )
  1264. *
  1265. * Checks whether the class is an interface.
  1266. *
  1267. * @return mixed Returns TRUE on success or FALSE on failure.
  1268. */
  1269. public function isInterface() {
  1270. return $this->check('interface');
  1271. }
  1272. // This doc comment block generated by idl/sysdoc.php
  1273. /**
  1274. * ( excerpt from http://php.net/manual/en/reflectionclass.isabstract.php )
  1275. *
  1276. * Checks if the class is abstract.
  1277. *
  1278. * @return mixed Returns TRUE on success or FALSE on failure.
  1279. */
  1280. public function isAbstract() {
  1281. return $this->check('abstract');
  1282. }
  1283. // This doc comment block generated by idl/sysdoc.php
  1284. /**
  1285. * ( excerpt from http://php.net/manual/en/reflectionclass.isfinal.php )
  1286. *
  1287. * Checks if a class is final.
  1288. *
  1289. * @return mixed Returns TRUE on success or FALSE on failure.
  1290. */
  1291. public function isFinal() {
  1292. return $this->check('final');
  1293. }
  1294. // This doc comment block generated by idl/sysdoc.php
  1295. /**
  1296. * ( excerpt from http://php.net/manual/en/reflectionclass.istrait.php )
  1297. *
  1298. * Warning: This function is currently not documented; only its argument
  1299. * list is available.
  1300. *
  1301. * @return mixed Returns TRUE if this is a trait, FALSE otherwise.
  1302. * Returns NULL in case of an error.
  1303. */
  1304. public function isTrait() {
  1305. return $this->check('trait');
  1306. }
  1307. // This doc comment block generated by idl/sysdoc.php
  1308. /**
  1309. * ( excerpt from http://php.net/manual/en/reflectionclass.getmodifiers.php
  1310. * )
  1311. *
  1312. * Returns a bitfield of the access modifiers for this class.
  1313. *
  1314. * @return mixed Returns bitmask of modifier constants.
  1315. */
  1316. public function getModifiers() {
  1317. return $this->fetch('modifiers');
  1318. }
  1319. // This doc comment block generated by idl/sysdoc.php
  1320. /**
  1321. * ( excerpt from http://php.net/manual/en/reflectionclass.isinstance.php )
  1322. *
  1323. * Checks if an object is an instance of a class.
  1324. *
  1325. * @obj mixed The object being compared to.
  1326. *
  1327. * @return mixed Returns TRUE on success or FALSE on failure.
  1328. */
  1329. public function isInstance($obj) {
  1330. return hphp_instanceof($obj, $this->name);
  1331. }
  1332. // This doc comment block generated by idl/sysdoc.php
  1333. /**
  1334. * ( excerpt from http://php.net/manual/en/reflectionclass.newinstance.php
  1335. * )
  1336. *
  1337. * Creates a new instance of the class. The given arguments are passed to
  1338. * the class constructor.
  1339. *
  1340. */
  1341. public function newInstance() {
  1342. $args = func_get_args();
  1343. return hphp_create_object($this->name, $args);
  1344. }
  1345. // This doc comment block generated by idl/sysdoc.php
  1346. /**
  1347. * ( excerpt from
  1348. * http://php.net/manual/en/reflectionclass.newinstanceargs.php )
  1349. *
  1350. * Creates a new instance of the class, the given arguments are passed to
  1351. * the class constructor.
  1352. *
  1353. * @args mixed The parameters to be passed to the class constructor
  1354. * as an array.
  1355. *
  1356. * @return mixed Returns a new instance of the class.
  1357. */
  1358. public function newInstanceArgs($args) {
  1359. return hphp_create_object($this->name, array_values($args));
  1360. }
  1361. // This doc comment block generated by idl/sysdoc.php
  1362. /**
  1363. * ( excerpt from
  1364. * http://php.net/manual/en/reflectionclass.newinstancewithoutconstructor.php
  1365. * )
  1366. *
  1367. * Creates a new instance of the class without invoking the constructor.
  1368. *
  1369. */
  1370. public function newInstanceWithoutConstructor() {
  1371. return hphp_create_object_without_constructor($this->name);
  1372. }
  1373. // This doc comment block generated by idl/sysdoc.php
  1374. /**
  1375. * ( excerpt from
  1376. * http://php.net/manual/en/reflectionclass.getparentclass.php )
  1377. *
  1378. * Warning: This function is currently not documented; only its argument
  1379. * list is available.
  1380. *
  1381. * @return mixed A ReflectionClass.
  1382. */
  1383. public function getParentClass() {
  1384. $parent = $this->fetch('parent');
  1385. if (empty($parent)) {
  1386. return false;
  1387. }
  1388. return new ReflectionClass($parent);
  1389. }
  1390. // This doc comment block generated by idl/sysdoc.php
  1391. /**
  1392. * ( excerpt from http://php.net/manual/en/reflectionclass.issubclassof.php
  1393. * )
  1394. *
  1395. * Checks if the class is a subclass of a specified class or implements a
  1396. * specified interface.
  1397. *
  1398. * @cls mixed The class name being checked against.
  1399. *
  1400. * @return mixed Returns TRUE on success or FALSE on failure.
  1401. */
  1402. public function isSubclassOf($cls) {
  1403. if ($cls instanceof ReflectionClass) {
  1404. $cls = $cls->name;
  1405. }
  1406. return is_subclass_of($this->name, $cls);
  1407. }
  1408. // This doc comment block generated by idl/sysdoc.php
  1409. /**
  1410. * ( excerpt from
  1411. * http://php.net/manual/en/reflectionclass.getstaticproperties.php )
  1412. *
  1413. * Get the static properties. Warning: This function is currently not
  1414. * documented; only its argument list is available.
  1415. *
  1416. * @return mixed The static properties, as an array.
  1417. */
  1418. public function getStaticProperties() {
  1419. $ret = array();
  1420. foreach ($this->getProperties() as $prop) {
  1421. if ($prop->isStatic()) {
  1422. $ret[$prop->name] = $prop;
  1423. }
  1424. }
  1425. return $ret;
  1426. }
  1427. // This doc comment block generated by idl/sysdoc.php
  1428. /**
  1429. * ( excerpt from
  1430. * http://php.net/manual/en/reflectionclass.getstaticpropertyvalue.php )
  1431. *
  1432. * Gets the value of a static property on this class.
  1433. *
  1434. * @name mixed The name of the static property for which to return
  1435. * a value.
  1436. * @default mixed
  1437. *
  1438. * @return mixed The value of the static property.
  1439. */
  1440. public function getStaticPropertyValue($name, $default = null) {
  1441. if ($this->hasProperty($name) &&
  1442. $this->getProperty($name)->isStatic()) {
  1443. return hphp_get_static_property($this->name, $name, false);
  1444. }
  1445. return $default;
  1446. }
  1447. // This doc comment block generated by idl/sysdoc.php
  1448. /**
  1449. * ( excerpt from
  1450. * http://php.net/manual/en/reflectionclass.setstaticpropertyvalue.php )
  1451. *
  1452. * Sets static property value. Warning: This function is currently not
  1453. * documented; only its argument list is available.
  1454. *
  1455. * @name mixed Property name.
  1456. * @value mixed New property value.
  1457. *
  1458. * @return mixed No value is returned.
  1459. */
  1460. public function setStaticPropertyValue($name, $value) {
  1461. hphp_set_static_property($this->name, $name, $value, false);
  1462. }
  1463. // This doc comment block generated by idl/sysdoc.php
  1464. /**
  1465. * ( excerpt from
  1466. * http://php.net/manual/en/reflectionclass.getdefaultproperties.php )
  1467. *
  1468. * Gets default properties from a class (including inherited properties).
  1469. *
  1470. * This method only works for static properties when used on internal
  1471. * classes. The default value of a static class property can not be tracked
  1472. * when using this method on user defined classes.
  1473. *
  1474. * @return mixed An array of default properties, with the key being
  1475. * the name of the property and the value being the
  1476. * default value of the property or NULL if the
  1477. * property doesn't have a default value. The function
  1478. * does not distinguish between static and non static
  1479. * properties and does not take visibility modifiers
  1480. * into account.
  1481. */
  1482. public function getDefaultProperties() {
  1483. $ret = array();
  1484. foreach ($this->getProperties() as $prop) {
  1485. if ($prop->isDefault()) {
  1486. $ret[$prop->name] = $prop;
  1487. }
  1488. }
  1489. return $ret;
  1490. }
  1491. // This doc comment block generated by idl/sysdoc.php
  1492. /**
  1493. * ( excerpt from
  1494. * http://php.net/manual/en/reflectionclass.isiterateable.php )
  1495. *
  1496. * Checks whether the class is iterateable.
  1497. *
  1498. * @return mixed Returns TRUE on success or FALSE on failure.
  1499. */
  1500. public function isIterateable() {
  1501. return $this->isSubclassOf('ArrayAccess');
  1502. }
  1503. // This doc comment block generated by idl/sysdoc.php
  1504. /**
  1505. * ( excerpt from
  1506. * http://php.net/manual/en/reflectionclass.implementsinterface.php )
  1507. *
  1508. * Checks whether it implements an interface.
  1509. *
  1510. * @cls mixed The interface name.
  1511. *
  1512. * @return mixed Returns TRUE on success or FALSE on failure.
  1513. */
  1514. public function implementsInterface($cls) {
  1515. if ($cls instanceof ReflectionClass) {
  1516. $cls = $cls->name;
  1517. }
  1518. if (!interface_exists($cls)) {
  1519. throw new ReflectionException("$cls is not an Interface");
  1520. }
  1521. foreach ($this->fetch('interfaces') as $name => $_) {
  1522. if (strcasecmp($cls, $name) == 0) {
  1523. return true;
  1524. }
  1525. }
  1526. return false;
  1527. }
  1528. // This doc comment block generated by idl/sysdoc.php
  1529. /**
  1530. * ( excerpt from http://php.net/manual/en/reflectionclass.getextension.php
  1531. * )
  1532. *
  1533. * Gets a ReflectionExtension object for the extension which defined the
  1534. * class.
  1535. *
  1536. * @return mixed A ReflectionExtension object representing the
  1537. * extension which defined the class, or NULL for
  1538. * user-defined classes.
  1539. */
  1540. public function getExtension() {
  1541. return $this->fetch('extension');
  1542. }
  1543. // This doc comment block generated by idl/sysdoc.php
  1544. /**
  1545. * ( excerpt from
  1546. * http://php.net/manual/en/reflectionclass.getextensionname.php )
  1547. *
  1548. * Gets the name of the extension which defined the class.
  1549. *
  1550. * @return mixed The name of the extension which defined the class,
  1551. * or FALSE for user-defined classes.
  1552. */
  1553. public function getExtensionName() {
  1554. return $this->fetch('extension')->getName();
  1555. }
  1556. public function getAttribute($name) {
  1557. $attrs = $this->fetch('attributes');
  1558. return isset($attrs[$name]) ? $attrs[$name] : null;
  1559. }
  1560. public function getAttributes() {
  1561. return $this->fetch('attributes');
  1562. }
  1563. public function getAttributeRecursive($name) {
  1564. $attrs = $this->fetch('attributes_rec');
  1565. return isset($attrs[$name]) ? $attrs[$name] : null;
  1566. }
  1567. public function getAttributesRecursive() {
  1568. return $this->fetch('attributes_rec');
  1569. }
  1570. // This doc comment block generated by idl/sysdoc.php
  1571. /**
  1572. * ( excerpt from http://php.net/manual/en/reflectionclass.innamespace.php
  1573. * )
  1574. *
  1575. * Checks if this class is defined in a namespace.
  1576. *
  1577. * @return mixed Returns TRUE on success or FALSE on failure.
  1578. */
  1579. public function inNamespace() {
  1580. return strrpos($this->getName(), '\\') !== false;
  1581. }
  1582. // This doc comment block generated by idl/sysdoc.php
  1583. /**
  1584. * ( excerpt from
  1585. * http://php.net/manual/en/reflectionclass.getnamespacename.php )
  1586. *
  1587. * Gets the namespace name. Warning: This function is currently not
  1588. * documented; only its argument list is available.
  1589. *
  1590. * @return mixed The namespace name.
  1591. */
  1592. public function getNamespaceName() {
  1593. $pos = strrpos($this->getName(), '\\');
  1594. if ($pos === false) {
  1595. return '';
  1596. }
  1597. return substr($this->getName(), 0, $pos);
  1598. }
  1599. // This doc comment block generated by idl/sysdoc.php
  1600. /**
  1601. * ( excerpt from http://php.net/manual/en/reflectionclass.getshortname.php
  1602. * )
  1603. *
  1604. * Gets the short name of the class, the part without the namespace.
  1605. *
  1606. * @return mixed The class short name.
  1607. */
  1608. public function getShortName() {
  1609. $pos = strrpos($this->getName(), '\\');
  1610. if ($pos === false) {
  1611. return $this->getName();
  1612. }
  1613. return substr($this->getName(), $pos + 1);
  1614. }
  1615. }
  1616. ///////////////////////////////////////////////////////////////////////////////
  1617. // object
  1618. // This doc comment block generated by idl/sysdoc.php
  1619. /**
  1620. * ( excerpt from http://php.net/manual/en/class.reflectionobject.php )
  1621. *
  1622. * The ReflectionObject class reports information about an object.
  1623. *
  1624. */
  1625. class ReflectionObject extends ReflectionClass {
  1626. // This doc comment block generated by idl/sysdoc.php
  1627. /**
  1628. * ( excerpt from http://php.net/manual/en/reflectionobject.export.php )
  1629. *
  1630. * Exports a reflection. Warning: This function is currently not
  1631. * documented; only its argument list is available.
  1632. *
  1633. * @obj mixed The reflection to export.
  1634. * @ret mixed Setting to TRUE will return the export, as opposed
  1635. * to emitting it. Setting to FALSE (the default) will
  1636. * do the opposite.
  1637. *
  1638. * @return mixed If the return parameter is set to TRUE, then the
  1639. * export is returned as a string, otherwise NULL is
  1640. * returned.
  1641. */
  1642. public static function export($obj, $ret=false) {
  1643. $obj = new ReflectionObject($obj);
  1644. $str = (string)$obj;
  1645. if ($ret) {
  1646. return $str;
  1647. }
  1648. print $str;
  1649. }
  1650. }
  1651. ///////////////////////////////////////////////////////////////////////////////
  1652. // property
  1653. // This doc comment block generated by idl/sysdoc.php
  1654. /**
  1655. * ( excerpt from http://php.net/manual/en/class.reflectionproperty.php )
  1656. *
  1657. * The ReflectionProperty class reports information about classes
  1658. * properties.
  1659. *
  1660. */
  1661. class ReflectionProperty implements Reflector {
  1662. const IS_STATIC = 1;
  1663. const IS_PUBLIC = 256;
  1664. const IS_PROTECTED = 512;
  1665. const IS_PRIVATE = 1024;
  1666. public $info;
  1667. public $name;
  1668. public $class;
  1669. private $forceAccessible = false;
  1670. // This doc comment block generated by idl/sysdoc.php
  1671. /**
  1672. * ( excerpt from http://php.net/manual/en/reflectionproperty.construct.php
  1673. * )
  1674. *
  1675. * Warning: This function is currently not documented; only its argument
  1676. * list is available.
  1677. *
  1678. * @cls mixed The class name, that contains the property.
  1679. * @name mixed The name of the property being reflected.
  1680. *
  1681. * @return mixed No value is returned.
  1682. */
  1683. public function __construct($cls, $name) {
  1684. if ($cls && $name) {
  1685. if (!is_object($cls)) {
  1686. $cls = new ReflectionClass($cls);
  1687. } else {
  1688. $cls = new ReflectionClass(get_class($cls));
  1689. }
  1690. $prop = $cls->getProperty($name);
  1691. if ($prop) {
  1692. $this->info = $prop->info;
  1693. $this->name = $prop->name;
  1694. $this->class = $prop->class;
  1695. }
  1696. } else {
  1697. throw new ReflectionException("Parameters must not be null");
  1698. }
  1699. }
  1700. // This doc comment block generated by idl/sysdoc.php
  1701. /**
  1702. * ( excerpt from http://php.net/manual/en/reflectionproperty.tostring.php
  1703. * )
  1704. *
  1705. * To string. Warning: This function is currently not documented; only its
  1706. * argument list is available.
  1707. *
  1708. */
  1709. public function __toString() {
  1710. return "";
  1711. }
  1712. // This doc comment block generated by idl/sysdoc.php
  1713. /**
  1714. * ( excerpt from http://php.net/manual/en/reflectionproperty.export.php )
  1715. *
  1716. * Exports a reflection. Warning: This function is currently not
  1717. * documented; only its argument list is available.
  1718. *
  1719. * @cls mixed The reflection to export.
  1720. * @name mixed The property name.
  1721. * @ret mixed Setting to TRUE will return the export, as opposed
  1722. * to emitting it. Setting to FALSE (the default) will
  1723. * do the opposite.
  1724. */
  1725. public static function export($cls, $name, $ret=false) {
  1726. if (!is_object($cls)) {
  1727. $cls = new ReflectionClass($cls);
  1728. } else {
  1729. $cls = new ReflectionClass(get_class($cls));
  1730. }
  1731. $obj = $cls->getProperty($name);
  1732. $str = (string)$obj;
  1733. if ($ret) {
  1734. return $str;
  1735. }
  1736. print $str;
  1737. }
  1738. // This doc comment block generated by idl/sysdoc.php
  1739. /**
  1740. * ( excerpt from http://php.net/manual/en/reflectionproperty.getname.php )
  1741. *
  1742. * Gets the properties name. Warning: This function is currently not
  1743. * documented; only its argument list is available.
  1744. *
  1745. * @return mixed The name of the reflected property.
  1746. */
  1747. public function getName() {
  1748. return $this->info['name'];
  1749. }
  1750. // This doc comment block generated by idl/sysdoc.php
  1751. /**
  1752. * ( excerpt from http://php.net/manual/en/reflectionproperty.ispublic.php
  1753. * )
  1754. *
  1755. * Checks whether the property is public.
  1756. *
  1757. * @return mixed TRUE if the property is public, FALSE otherwise.
  1758. */
  1759. public function isPublic() {
  1760. return $this->info['access'] == 'public';
  1761. }
  1762. // This doc comment block generated by idl/sysdoc.php
  1763. /**
  1764. * ( excerpt from http://php.net/manual/en/reflectionproperty.isprivate.php
  1765. * )
  1766. *
  1767. * Checks whether the property is private.
  1768. *
  1769. * @return mixed TRUE if the property is private, FALSE otherwise.
  1770. */
  1771. public function isPrivate() {
  1772. return $this->info['access'] == 'private';
  1773. }
  1774. // This doc comment block generated by idl/sysdoc.php
  1775. /**
  1776. * ( excerpt from
  1777. * http://php.net/manual/en/reflectionproperty.isprotected.php )
  1778. *
  1779. * Checks whether the property is protected.
  1780. *
  1781. * @return mixed TRUE if the property is protected, FALSE otherwise.
  1782. */
  1783. public function isProtected() {
  1784. return $this->info['access'] == 'protected';
  1785. }
  1786. // This doc comment block generated by idl/sysdoc.php
  1787. /**
  1788. * ( excerpt from http://php.net/manual/en/reflectionproperty.isstatic.php
  1789. * )
  1790. *
  1791. * Checks whether the property is static.
  1792. *
  1793. * @return mixed TRUE if the property is static, FALSE otherwise.
  1794. */
  1795. public function isStatic() {
  1796. return isset($this->info['static']);
  1797. }
  1798. // This doc comment block generated by idl/sysdoc.php
  1799. /**
  1800. * ( excerpt from http://php.net/manual/en/reflectionproperty.isdefault.php
  1801. * )
  1802. *
  1803. * Checks whether the property is the default.
  1804. *
  1805. * @return mixed TRUE if the property was declared at compile-time,
  1806. * or FALSE if it was created at run-time.
  1807. */
  1808. public function isDefault() {
  1809. return $this->info['default'];
  1810. }
  1811. // This doc comment block generated by idl/sysdoc.php
  1812. /**
  1813. * ( excerpt from
  1814. * http://php.net/manual/en/reflectionproperty.setaccessible.php )
  1815. *
  1816. * Sets a property to be accessible. For example, it may allow protected
  1817. * and private properties to be accessed.
  1818. *
  1819. * @accessible mixed TRUE to allow accessibility, or FALSE.
  1820. *
  1821. * @return mixed No value is returned.
  1822. */
  1823. public function setAccessible($accessible) {
  1824. $this->forceAccessible = $accessible;
  1825. }
  1826. // This doc comment block generated by idl/sysdoc.php
  1827. /**
  1828. * ( excerpt from
  1829. * http://php.net/manual/en/reflectionproperty.getmodifiers.php )
  1830. *
  1831. * Gets the modifiers. Warning: This function is currently not documented;
  1832. * only its argument list is available.
  1833. *
  1834. * @return mixed A numeric representation of the modifiers.
  1835. */
  1836. public function getModifiers() {
  1837. return $this->info['modifiers'];
  1838. }
  1839. // This doc comment block generated by idl/sysdoc.php
  1840. /**
  1841. * ( excerpt from http://php.net/manual/en/reflectionproperty.getvalue.php
  1842. * )
  1843. *
  1844. * Gets the properties value.
  1845. *
  1846. * @obj mixed If the property is non-static an object must be
  1847. * provided to fetch the property from. If you want to
  1848. * fetch the default property without providing an
  1849. * object use ReflectionClass::getDefaultProperties()
  1850. * instead.
  1851. *
  1852. * @return mixed The current value of the property.
  1853. */
  1854. public function getValue($obj = null) {
  1855. if ($this->isStatic()) {
  1856. return hphp_get_static_property(
  1857. $this->info['class'],
  1858. $this->info['name'],
  1859. $this->forceAccessible
  1860. );
  1861. }
  1862. if ($obj) {
  1863. return hphp_get_property(
  1864. $obj,
  1865. $this->forceAccessible ? $this->info['class'] : null,
  1866. $this->info['name']
  1867. );
  1868. }
  1869. return null;
  1870. }
  1871. // This doc comment block generated by idl/sysdoc.php
  1872. /**
  1873. * ( excerpt from http://php.net/manual/en/reflectionproperty.setvalue.php
  1874. * )
  1875. *
  1876. * Sets (changes) the property's value.
  1877. *
  1878. * @obj mixed If the property is non-static an object must be
  1879. * provided to change the property on. If the property
  1880. * is static this parameter is left out and only value
  1881. * needs to be provided.
  1882. * @value mixed The new value.
  1883. *
  1884. * @return mixed No value is returned.
  1885. */
  1886. public function setValue($obj) {
  1887. $args = func_get_args();
  1888. if (count($args) > 1) {
  1889. $obj = array_shift($args);
  1890. }
  1891. $value = array_shift($args);
  1892. if ($this->isStatic()) {
  1893. hphp_set_static_property(
  1894. $this->info['class'],
  1895. $this->info['name'],
  1896. $value,
  1897. $this->forceAccessible
  1898. );
  1899. } else {
  1900. hphp_set_property(
  1901. $obj,
  1902. $this->forceAccessible ? $this->info['class'] : null,
  1903. $this->info['name'],
  1904. $value
  1905. );
  1906. }
  1907. }
  1908. // This doc comment block generated by idl/sysdoc.php
  1909. /**
  1910. * ( excerpt from
  1911. * http://php.net/manual/en/reflectionproperty.getdeclaringclass.php )
  1912. *
  1913. * Gets the declaring class. Warning: This function is currently not
  1914. * documented; only its argument list is available.
  1915. *
  1916. * @return mixed A ReflectionClass object.
  1917. */
  1918. public function getDeclaringClass() {
  1919. if (empty($this->info['class'])) {
  1920. return null;
  1921. }
  1922. return new ReflectionClass($this->info['class']);
  1923. }
  1924. // This doc comment block generated by idl/sysdoc.php
  1925. /**
  1926. * ( excerpt from
  1927. * http://php.net/manual/en/reflectionproperty.getdoccomment.php )
  1928. *
  1929. * Gets the doc comment. Warning: This function is currently not
  1930. * documented; only its argument list is available.
  1931. *
  1932. * @return mixed The doc comment.
  1933. */
  1934. public function getDocComment() {
  1935. return $this->info['doc'];
  1936. }
  1937. public function getTypeText() {
  1938. if (isset($this->info['type'])) {
  1939. return $this->info['type'];
  1940. }
  1941. return '';
  1942. }
  1943. }
  1944. ///////////////////////////////////////////////////////////////////////////////
  1945. // method
  1946. // This doc comment block generated by idl/sysdoc.php
  1947. /**
  1948. * ( excerpt from http://php.net/manual/en/class.reflectionmethod.php )
  1949. *
  1950. * The ReflectionMethod class reports information about a method.
  1951. *
  1952. */
  1953. class ReflectionMethod extends ReflectionFunctionAbstract
  1954. implements Reflector {
  1955. const IS_STATIC = 1;
  1956. const IS_PUBLIC = 256;
  1957. const IS_PROTECTED = 512;
  1958. const IS_PRIVATE = 1024;
  1959. const IS_ABSTRACT = 2;
  1960. const IS_FINAL = 4;
  1961. public $name;
  1962. public $class;
  1963. // This doc comment block generated by idl/sysdoc.php
  1964. /**
  1965. * ( excerpt from http://php.net/manual/en/reflectionmethod.construct.php )
  1966. *
  1967. * Constructs a new ReflectionMethod.
  1968. *
  1969. * @cls mixed Classname or object (instance of the class) that
  1970. * contains the method.
  1971. * @name mixed Name of the method.
  1972. *
  1973. * @return mixed No value is returned.
  1974. */
  1975. public function __construct($cls, $name = '') {
  1976. if ($cls === null && $name === null) {
  1977. // support clownery in ReflectionClass->getMethod()
  1978. // caller is responsible for setting method correctly
  1979. return;
  1980. }
  1981. if (!$name && is_string($cls)) {
  1982. $arr = explode('::', $cls);
  1983. if (count($arr) == 2) {
  1984. $cls = $arr[0];
  1985. $name = $arr[1];
  1986. }
  1987. }
  1988. $method = hphp_get_method_info($cls, $name);
  1989. if (!$method) {
  1990. $classname = is_object($cls) ? get_class($cls) : $cls;
  1991. throw new ReflectionException("Method $classname::$name does not exist");
  1992. }
  1993. $this->info = $method;
  1994. $this->name = $method['name'];
  1995. $this->class = $method['class'];
  1996. }
  1997. // This doc comment block generated by idl/sysdoc.php
  1998. /**
  1999. * ( excerpt from http://php.net/manual/en/reflectionmethod.tostring.php )
  2000. *
  2001. * Returns the string representation of the Reflection method object.
  2002. *
  2003. * @return mixed A string representation of this ReflectionMethod
  2004. * instance.
  2005. */
  2006. public function __toString() {
  2007. //TODO
  2008. return "";
  2009. }
  2010. // This doc comment block generated by idl/sysdoc.php
  2011. /**
  2012. * ( excerpt from http://php.net/manual/en/reflectionmethod.export.php )
  2013. *
  2014. * Exports a ReflectionMethod. Warning: This function is currently not
  2015. * documented; only its argument list is available.
  2016. *
  2017. * @cls mixed The class name.
  2018. * @name mixed The name of the method.
  2019. * @ret mixed Setting to TRUE will return the export, as opposed
  2020. * to emitting it. Setting to FALSE (the default) will
  2021. * do the opposite.
  2022. *
  2023. * @return mixed If the return parameter is set to TRUE, then the
  2024. * export is returned as a string, otherwise NULL is
  2025. * returned.
  2026. */
  2027. public static function export($cls, $name, $ret=false) {
  2028. if (!is_object($cls)) {
  2029. $cls = new ReflectionClass($cls);
  2030. } else {
  2031. $cls = new ReflectionClass(get_class($cls));
  2032. }
  2033. $obj = $cls->getMethod($name);
  2034. $str = (string)$obj;
  2035. if ($ret) {
  2036. return $str;
  2037. }
  2038. print $str;
  2039. }
  2040. // This doc comment block generated by idl/sysdoc.php
  2041. /**
  2042. * ( excerpt from http://php.net/manual/en/reflectionmethod.invoke.php )
  2043. *
  2044. * Invokes a reflected method.
  2045. *
  2046. * @obj mixed The object to invoke the method on. For static
  2047. * methods, pass null to this parameter.
  2048. *
  2049. * @return mixed Returns the method result.
  2050. */
  2051. public function invoke($obj) {
  2052. if ($this->info['accessible']) {
  2053. $args = func_get_args();
  2054. array_shift($args);
  2055. return hphp_invoke_method($obj, $this->info['class'], $this->info['name'],
  2056. $args);
  2057. }
  2058. else {
  2059. $className = $this->info['class'];
  2060. $funcName = $this->info['name'];
  2061. $access = $this->info['access'];
  2062. $msg = "Trying to invoke $access method $className::$funcName() from ";
  2063. $msg .= "scope ReflectionMethod";
  2064. throw new ReflectionException($msg);
  2065. }
  2066. }
  2067. // This doc comment block generated by idl/sysdoc.php
  2068. /**
  2069. * ( excerpt from http://php.net/manual/en/reflectionmethod.invokeargs.php
  2070. * )
  2071. *
  2072. * Invokes the reflected method and pass its arguments as array.
  2073. *
  2074. * @obj mixed The object to invoke the method on. In case of
  2075. * static methods, you can pass null to this parameter.
  2076. * @args mixed The parameters to be passed to the function, as an
  2077. * array.
  2078. *
  2079. * @return mixed Returns the method result.
  2080. */
  2081. public function invokeArgs($obj, $args) {
  2082. return hphp_invoke_method($obj, $this->info['class'], $this->info['name'],
  2083. array_values($args));
  2084. }
  2085. // This doc comment block generated by idl/sysdoc.php
  2086. /**
  2087. * ( excerpt from http://php.net/manual/en/reflectionmethod.isfinal.php )
  2088. *
  2089. * Checks if the method is final.
  2090. *
  2091. * @return mixed TRUE if the method is final, otherwise FALSE
  2092. */
  2093. public function isFinal() {
  2094. return isset($this->info['final']);
  2095. }
  2096. // This doc comment block generated by idl/sysdoc.php
  2097. /**
  2098. * ( excerpt from http://php.net/manual/en/reflectionmethod.isabstract.php
  2099. * )
  2100. *
  2101. * Checks if the method is abstract.
  2102. *
  2103. * @return mixed TRUE if the method is abstract, otherwise FALSE
  2104. */
  2105. public function isAbstract() {
  2106. return isset($this->info['abstract']);
  2107. }
  2108. // This doc comment block generated by idl/sysdoc.php
  2109. /**
  2110. * ( excerpt from http://php.net/manual/en/reflectionmethod.ispublic.php )
  2111. *
  2112. * Checks if the method is public.
  2113. *
  2114. * @return mixed TRUE if the method is public, otherwise FALSE
  2115. */
  2116. public function isPublic() {
  2117. return $this->info['access'] == "public";
  2118. }
  2119. // This doc comment block generated by idl/sysdoc.php
  2120. /**
  2121. * ( excerpt from http://php.net/manual/en/reflectionmethod.isprivate.php )
  2122. *
  2123. * Checks if the method is private. Warning: This function is currently
  2124. * not documented; only its argument list is available.
  2125. *
  2126. * @return mixed TRUE if the method is private, otherwise FALSE
  2127. */
  2128. public function isPrivate() {
  2129. return $this->info['access'] == "private";
  2130. }
  2131. // This doc comment block generated by idl/sysdoc.php
  2132. /**
  2133. * ( excerpt from http://php.net/manual/en/reflectionmethod.isprotected.php
  2134. * )
  2135. *
  2136. * Checks if the method is protected.
  2137. *
  2138. * @return mixed TRUE if the method is protected, otherwise FALSE
  2139. */
  2140. public function isProtected() {
  2141. return $this->info['access'] == "protected";
  2142. }
  2143. // This doc comment block generated by idl/sysdoc.php
  2144. /**
  2145. * ( excerpt from http://php.net/manual/en/reflectionmethod.isstatic.php )
  2146. *
  2147. * Checks if the method is static.
  2148. *
  2149. * @return mixed TRUE if the method is static, otherwise FALSE
  2150. */
  2151. public function isStatic() {
  2152. return isset($this->info['static']);
  2153. }
  2154. // This doc comment block generated by idl/sysdoc.php
  2155. /**
  2156. * ( excerpt from
  2157. * http://php.net/manual/en/reflectionmethod.isconstructor.php )
  2158. *
  2159. * Checks if the method is a constructor.
  2160. *
  2161. * @return mixed TRUE if the method is a constructor, otherwise FALSE
  2162. */
  2163. public function isConstructor() {
  2164. return isset($this->info['constructor']);
  2165. }
  2166. // This doc comment block generated by idl/sysdoc.php
  2167. /**
  2168. * ( excerpt from
  2169. * http://php.net/manual/en/reflectionmethod.isdestructor.php )
  2170. *
  2171. * Checks if the method is a destructor.
  2172. *
  2173. * @return mixed TRUE if the method is a destructor, otherwise FALSE
  2174. */
  2175. public function isDestructor() {
  2176. return $this->getName() == '__destruct';
  2177. }
  2178. // This doc comment block generated by idl/sysdoc.php
  2179. /**
  2180. * ( excerpt from
  2181. * http://php.net/manual/en/reflectionmethod.getmodifiers.php )
  2182. *
  2183. * Returns a bitfield of the access modifiers for this method.
  2184. *
  2185. * @return mixed A numeric representation of the modifiers. The
  2186. * modifiers are listed below. The actual meanings of
  2187. * these modifiers are described in the predefined
  2188. * constants.
  2189. */
  2190. public function getModifiers() {
  2191. return $this->info['modifiers'];
  2192. }
  2193. // This doc comment block generated by idl/sysdoc.php
  2194. /**
  2195. * ( excerpt from http://php.net/manual/en/reflectionmethod.getclosure.php
  2196. * )
  2197. *
  2198. * Warning: This function is currently not documented; only its argument
  2199. * list is available.
  2200. *
  2201. * @return mixed Returns Closure. Returns NULL in case of an error.
  2202. */
  2203. public function getClosure() {
  2204. return $this->info['closure'];
  2205. }
  2206. // This doc comment block generated by idl/sysdoc.php
  2207. /**
  2208. * ( excerpt from
  2209. * http://php.net/manual/en/reflectionmethod.getdeclaringclass.php )
  2210. *
  2211. * Gets the declaring class for the reflected method.
  2212. *
  2213. * @return mixed A ReflectionClass object of the class that the
  2214. * reflected method is part of.
  2215. */
  2216. public function getDeclaringClass() {
  2217. if (empty($this->info['class'])) {
  2218. return null;
  2219. }
  2220. return new ReflectionClass($this->info['class']);
  2221. }
  2222. // This doc comment block generated by idl/sysdoc.php
  2223. /**
  2224. * ( excerpt from
  2225. * http://php.net/manual/en/reflectionmethod.setaccessible.php )
  2226. *
  2227. * Sets a method to be accessible. For example, it may allow protected and
  2228. * private methods to be invoked.
  2229. *
  2230. * @accessible mixed TRUE to allow accessibility, or FALSE.
  2231. *
  2232. * @return mixed No value is returned.
  2233. */
  2234. public function setAccessible(bool $accessible) {
  2235. // Public methods are always accessible. Cannot manually
  2236. // set to not be accessible.
  2237. if ($this->info['access'] !== 'public') {
  2238. $this->info['accessible'] = $accessible;
  2239. }
  2240. }
  2241. public function getAttribute($name) {
  2242. $attrs = $this->info['attributes'];
  2243. return isset($attrs[$name]) ? $attrs[$name] : null;
  2244. }
  2245. public function getAttributes() {
  2246. return $this->info['attributes'];
  2247. }
  2248. public function getAttributeRecursive($name) {
  2249. $attrs = $this->info['attributes'];
  2250. if (isset($attrs[$name])) {
  2251. return $attrs[$name];
  2252. }
  2253. $p = get_parent_class($this->class);
  2254. if ($p === false) {
  2255. return null;
  2256. }
  2257. $rm = new ReflectionMethod($p, $this->name);
  2258. if ($rm->isPrivate()) {
  2259. return null;
  2260. }
  2261. return $rm->getAttributeRecursive($name);
  2262. }
  2263. public function getAttributesRecursive() {
  2264. $attrs = $this->info['attributes'];
  2265. $p = get_parent_class($this->class);
  2266. if ($p !== false) {
  2267. $rm = new ReflectionMethod($p, $this->name);
  2268. if (!$rm->isPrivate()) {
  2269. $attrs += $rm->getAttributesRecursive();
  2270. }
  2271. }
  2272. return $attrs;
  2273. }
  2274. }
  2275. ///////////////////////////////////////////////////////////////////////////////
  2276. // extension
  2277. // This doc comment block generated by idl/sysdoc.php
  2278. /**
  2279. * ( excerpt from http://php.net/manual/en/class.reflectionextension.php )
  2280. *
  2281. * The ReflectionExtension class reports information about an extension.
  2282. *
  2283. */
  2284. class ReflectionExtension implements Reflector {
  2285. private $name;
  2286. private $info;
  2287. // This doc comment block generated by idl/sysdoc.php
  2288. /**
  2289. * ( excerpt from
  2290. * http://php.net/manual/en/reflectionextension.construct.php )
  2291. *
  2292. * Construct a ReflectionExtension object.
  2293. *
  2294. * @name mixed Name of the extension.
  2295. *
  2296. * @return mixed A ReflectionExtension object.
  2297. */
  2298. public function __construct($name) {
  2299. $this->info = hphp_get_extension_info($name);
  2300. }
  2301. // This doc comment block generated by idl/sysdoc.php
  2302. /**
  2303. * ( excerpt from http://php.net/manual/en/reflectionextension.tostring.php
  2304. * )
  2305. *
  2306. * Exports a reflected extension and returns it as a string. This is the
  2307. * same as the ReflectionExtension::export() with the return set to TRUE.
  2308. *
  2309. * @return mixed Returns the exported extension as a string, in the
  2310. * same way as the ReflectionExtension::export().
  2311. */
  2312. public function __toString() {
  2313. return "";
  2314. }
  2315. // This doc comment block generated by idl/sysdoc.php
  2316. /**
  2317. * ( excerpt from http://php.net/manual/en/reflectionextension.export.php )
  2318. *
  2319. * Exports a reflected extension. The output format of this function is
  2320. * the same as the CLI argument --re [extension].
  2321. *
  2322. * @name mixed The reflection to export.
  2323. * @ret mixed Setting to TRUE will return the export, as opposed
  2324. * to emitting it. Setting to FALSE (the default) will
  2325. * do the opposite.
  2326. *
  2327. * @return mixed If the return parameter is set to TRUE, then the
  2328. * export is returned as a string, otherwise NULL is
  2329. * returned.
  2330. */
  2331. public static function export($name, $ret=false) {
  2332. $obj = new ReflectionExtension($name);
  2333. $str = (string)$obj;
  2334. if ($ret) {
  2335. return $str;
  2336. }
  2337. print $str;
  2338. }
  2339. // This doc comment block generated by idl/sysdoc.php
  2340. /**
  2341. * ( excerpt from http://php.net/manual/en/reflectionextension.getname.php
  2342. * )
  2343. *
  2344. * Gets the extensions name.
  2345. *
  2346. * @return mixed The extensions name.
  2347. */
  2348. public function getName() {
  2349. return $this->info['name'];
  2350. }
  2351. // This doc comment block generated by idl/sysdoc.php
  2352. /**
  2353. * ( excerpt from
  2354. * http://php.net/manual/en/reflectionextension.getversion.php )
  2355. *
  2356. * Gets the version of the extension.
  2357. *
  2358. * @return mixed The version of the extension.
  2359. */
  2360. public function getVersion() {
  2361. return $this->info['version'];
  2362. }
  2363. // This doc comment block generated by idl/sysdoc.php
  2364. /**
  2365. * ( excerpt from
  2366. * http://php.net/manual/en/reflectionextension.getfunctions.php )
  2367. *
  2368. * Get defined functions from an extension.
  2369. *
  2370. * @return mixed An associative array of ReflectionFunction objects,
  2371. * for each function defined in the extension with the
  2372. * keys being the function names. If no function are
  2373. * defined, an empty array is returned.
  2374. */
  2375. public function getFunctions() {
  2376. return $this->info['functions'];
  2377. }
  2378. // This doc comment block generated by idl/sysdoc.php
  2379. /**
  2380. * ( excerpt from
  2381. * http://php.net/manual/en/reflectionextension.getconstants.php )
  2382. *
  2383. * Get defined constants from an extension.
  2384. *
  2385. * @return mixed An associative array with constant names as keys.
  2386. */
  2387. public function getConstants() {
  2388. return $this->info['constants'];
  2389. }
  2390. // This doc comment block generated by idl/sysdoc.php
  2391. /**
  2392. * ( excerpt from
  2393. * http://php.net/manual/en/reflectionextension.getinientries.php )
  2394. *
  2395. * Get the ini entries for an extension.
  2396. *
  2397. * @return mixed An associative array with the ini entries as keys,
  2398. * with their defined values as values.
  2399. */
  2400. public function getINIEntries() {
  2401. return $this->info['ini'];
  2402. }
  2403. // This doc comment block generated by idl/sysdoc.php
  2404. /**
  2405. * ( excerpt from
  2406. * http://php.net/manual/en/reflectionextension.getclasses.php )
  2407. *
  2408. * Gets a list of classes from an extension.
  2409. *
  2410. * @return mixed An array of ReflectionClass objects, one for each
  2411. * class within the extension. If no classes are
  2412. * defined, an empty array is returned.
  2413. */
  2414. public function getClasses() {
  2415. return $this->info['classes'];
  2416. }
  2417. // This doc comment block generated by idl/sysdoc.php
  2418. /**
  2419. * ( excerpt from
  2420. * http://php.net/manual/en/reflectionextension.getclassnames.php )
  2421. *
  2422. * Gets a listing of class names as defined in the extension.
  2423. *
  2424. * @return mixed An array of class names, as defined in the
  2425. * extension. If no classes are defined, an empty array
  2426. * is returned.
  2427. */
  2428. public function getClassNames() {
  2429. $ret = array();
  2430. foreach ($this->info['classes'] as $cls) {
  2431. $ret[] = $cls->getName();
  2432. }
  2433. return $ret;
  2434. }
  2435. // This doc comment block generated by idl/sysdoc.php
  2436. /**
  2437. * ( excerpt from http://php.net/manual/en/reflectionextension.info.php )
  2438. *
  2439. * Prints out the " phpinfo()" snippet for the given extension.
  2440. *
  2441. * @return mixed Information about the extension.
  2442. */
  2443. public function info() {
  2444. return $this->info['info'];
  2445. }
  2446. }