protected function setResponseParam($name, $value, $isHtml = false) { if (!$isHtml) { $reflection = new ReflectionUtil(); $value = $reflection->htmlEscForResponseItem($value); } $this->response->{$name} = $value; }
public function execute($actionParams) { $action = $this->expression; list($beanClass, $methodName) = BeanUtil::getBeanAndProperties($action); $beanInstance = BeanLocator::get($beanClass); return ReflectionUtil::callMethod($beanInstance, $methodName, $actionParams); }
public static function objectToArray($obj) { $content['res'] = $obj; foreach ($content['res'] as $key => $value) { if (is_object($value)) { $class_name = get_class($value); $reflection = new ReflectionUtil($class_name); $arr = $reflection->getPropertyNamesAndValuesAsArray($value); $content['response'][$key] = $arr; } else { if (is_array($value)) { //$content['response'][$key] = $value; } else { $content['response'][$key] = $value; } } } return $content; }
private function updateModel(MovicoRequest $req) { $vars = $req->getPostVars(); foreach ($vars as $var) { list($beanClass, $nestedProperty) = BeanUtil::getBeanAndProperties($var->getName(), true); ReflectionUtil::callNestedSetter(BeanLocator::get($beanClass), $nestedProperty, $var->getConvertedValue()); } $files = $req->getFiles(); foreach ($files as $key => $fileArray) { $file = new UploadedFile($fileArray); list($beanClass, $nestedProperty) = BeanUtil::getBeanAndProperties($key, true); ReflectionUtil::callNestedSetter(BeanLocator::get($beanClass), $nestedProperty, $file); } }
private function generateCustomServices(Entity $entity) { $result = ""; $methods = ReflectionUtil::getSubclassMethods($entity->getName() . "Service"); foreach ($methods as $method) { if (!$method->isPublic()) { continue; } $name = $method->name; $paramNames = array(); foreach ($method->getParameters() as $param) { $paramNames[] = "\$" . $param->name; } $skeleton = $name . "(" . implode(", ", $paramNames) . ")"; $result .= "\tpublic static function {$skeleton} {\n" . "\t\treturn self::getService()->{$skeleton};\n" . "\t}\n\n"; } return $result; }
public static function toIndexedArray($objects, $key, $value = null) { self::checkTypes($objects); if (is_null($value)) { $value = $key; } StringUtil::checkTypes($key, $value); if (empty($objects)) { return array(); } $result = array(); foreach ($objects as $object) { $keyString = ReflectionUtil::callNestedGetter($object, $key); $valueString = ReflectionUtil::callNestedGetter($object, $value); $result[$keyString] = $valueString; } return $result; }
<?php require_once "fullshop.php"; class ReflectionUtil { static function getMethodSource(ReflectionMethod $method) { $path = $method->getFileName(); $lines = @file($path); $from = $method->getStartLine(); $to = $method->getEndLine(); $len = $to - $from + 1; return implode(array_slice($lines, $from - 1, $len)); } } $class = new ReflectionClass('CdProduct'); $method = $class->getMethod('getSummaryLine'); print ReflectionUtil::getMethodSource($method);
/** * Given object must be compatible with DAO type. * @param object $object * @throws IncorrectTypeException */ protected function checkType($object) { if (!$object instanceof $this->type) { throw new IncorrectTypeException(ReflectionUtil::getObjectType($object)); } }
public function htmlEscForResponseItem($object) { if (empty($object)) { return null; } if (is_object($object)) { $class_name = get_class($object); $reflection = new ReflectionUtil($class_name); $properties = $reflection->reflectedClass->getProperties(); foreach ($properties as $property) { $name = $property->getName(); if (is_object($object->{$name})) { $object->{$name} = $reflection->htmlEscForResponseItem($object->{$name}); } else { if (is_array($object->{$name})) { $object->{$name} = $object->{$name}; } else { $object->{$name} = htmlspecialchars($object->{$name}); } } } } else { if (is_array($object)) { $object = $this->htmlEscForArrays($object); } else { $object = htmlspecialchars($object); } } return $object; }
<?php require_once "fullshop.php"; require_once "business/ShopProduct3.php"; class ReflectionUtil { static function getClassSource(ReflectionClass $class) { $path = $class->getFileName(); $lines = @file($path); $from = $class->getStartLine(); $to = $class->getEndLine(); $len = $to - $from + 1; return implode(array_slice($lines, $from - 1, $len)); } } print ReflectionUtil::getClassSource(new ReflectionClass('CdProduct')); print ReflectionUtil::getClassSource(new ReflectionClass('business\\ShopProduct3'));
$obj = ActionHandler::handleAction($action); if ($output_type == "xml") { header('Content-Type: text/xml'); print '<?xml version="1.0" encoding="utf-8"?>'; print "<response><status>SUCCESS</status>"; print "</response>"; } elseif ($output_type == "json") { include_once '../libs/json/JSON.php'; $json = new Services_JSON(); $content = array(); $content['request'] = $obj->getRequest(); $content['res'] = $obj->getResponse(); foreach ($content['res'] as $key => $value) { if (is_object($value)) { $class_name = get_class($value); $reflection = new ReflectionUtil($class_name); $arr = $reflection->getPropertyNamesAndValuesAsArray($value); $content['response'][$key] = $arr; } else { $content['response'][$key] = $value; } } unset($content['res']); $output = $json->encode($content); print_r($output); exit; } elseif ($output_type == "query_string") { $content['res'] = $obj->getResponse(); foreach ($content['res'] as $key => $value) { echo "&{$key}={$value}"; }
foreach ($methods as $method) { print infoMethod($method); print "\n------\n"; } function infoMethod(ReflectionMethod $someMethod) { $name = $someMethod->getName(); return $name; } class ReflectionUtil { static function sourceCodeMethod(ReflectionMethod $method) { $path = $method->getFileName(); $lines = @file($path); $from = $method->getStartLine(); $to = $method->getEndLine(); $len = $to - $from + 1; $result = implode(array_slice($lines, $from - 1, $len)); return $result; } } $class = new ReflectionClass('CDProduct'); $method = $class->getMethod('getSummaryLine'); print ReflectionUtil::sourceCodeMethod($method) . "\n"; function getData(ReflectionClass $anyclass) { $name = $anyclass->getName(); return $name; } print getData($prod_class);
private function getBeanValue($valueExpression, $rowIndex = null) { list($beanClass, $nestedProperty) = BeanUtil::getBeanAndProperties($valueExpression); try { $beanObj = BeanLocator::get($beanClass); } catch (NoSuchBeanException $e) { try { $dataSeries = $this->getFirstAncestorOfType("DataSeries"); if ($dataSeries->getVar() !== $beanClass || is_null($rowIndex)) { throw new NoSuchBeanException($beanClass); } $rows = $dataSeries->getRows(); $beanObj = $rows[$rowIndex]; } catch (NoSuchAnchestorComponentException $e) { throw new NoSuchBeanException($beanClass); } } return ReflectionUtil::callNestedGetter($beanObj, $nestedProperty); }
public function getRows() { list($beanClass, $nestedProperty) = BeanUtil::getBeanAndProperties($this->value); $beanObj = BeanLocator::get($beanClass); return ReflectionUtil::callNestedGetter($beanObj, $nestedProperty); }
} } class ReflectionUtil { static function getClassSource(ReflectionClass $class) { $path = $class->getFilename(); $lines = @file($path); $from = $class->getStartLine(); $to = $class->getEndLine(); $len = $to - $from + 1; return implode(array_slice($lines, $from - 1, $len)); } } echo "<pre>"; print ReflectionUtil::getClassSource(new ReflectionClass("returns")); exit; function classData(ReflectionClass $class) { $details = ""; $name = $class->getName(); if ($class->isUserDefined()) { $details .= "{$name} is user defined \n"; } if ($class->isInternal()) { $details .= "{$name} is built-in\n"; } if ($class->isInternal()) { $details .= "{$name} is interface \n"; } if ($class->isAbstract()) {