当前位置: 首页>>代码示例>>PHP>>正文


PHP ReflectionClass::isIterateable方法代码示例

本文整理汇总了PHP中ReflectionClass::isIterateable方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionClass::isIterateable方法的具体用法?PHP ReflectionClass::isIterateable怎么用?PHP ReflectionClass::isIterateable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ReflectionClass的用法示例。


在下文中一共展示了ReflectionClass::isIterateable方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testIteratorClass

 /**
  * @covers \PHP\Manipulator\TokenContainer\Iterator
  */
 public function testIteratorClass()
 {
     $reflection = new \ReflectionClass('PHP\\Manipulator\\TokenContainer\\Iterator');
     $this->assertTrue($reflection->isIterateable());
     $this->assertTrue($reflection->implementsInterface('SeekableIterator'));
     $this->assertTrue($reflection->implementsInterface('Countable'));
     $this->assertTrue($reflection->hasMethod('previous'));
 }
开发者ID:robo47,项目名称:php-manipulator,代码行数:11,代码来源:IteratorTest.php

示例2: sanitize

 /**
  * Will sanitize mixed vars by capping recursion
  * and format them in a designer-friendly way by displaying objects' methods stubs
  * A bit dirty as this should be in another Class, but hey
  *
  * @param $value
  * @param int $maxRecursionDepth  The maximum depth of recursion
  * @param int $recursionDepth     The depth of recursion (used internally)
  * @return array|string
  */
 public function sanitize($value, $maxRecursionDepth = self::MAX_DEPTH, $recursionDepth = 0)
 {
     if (is_resource($value)) {
         return 'Resource';
     }
     if (is_array($value)) {
         return $this->sanitizeIterateable($value, $maxRecursionDepth, $recursionDepth);
     }
     if ($value instanceof InvokerException) {
         return $value->getMessage();
     }
     if (is_object($value)) {
         $class = new \ReflectionClass(get_class($value));
         if ($recursionDepth >= $maxRecursionDepth) {
             // We're full, just scrap the vital data
             $classInfo = $class->getName();
             if ($class->hasMethod('getId')) {
                 $getIdMethod = $class->getMethod('getId');
                 if (!$getIdMethod->getNumberOfRequiredParameters()) {
                     $id = $getIdMethod->invoke($value);
                     $classInfo .= $id !== null ? ' #' . $id : ' (no id)';
                 }
             }
             if ($class->hasMethod('__toString')) {
                 // robustness, we don't care about perf
                 try {
                     $classInfo .= ' ' . (string) $value;
                 } catch (\Exception $e) {
                     $classInfo .= '(string) casting throws Exception, please report or fix';
                 }
             }
             if ($value instanceof \DateTime) {
                 $classInfo .= ' : ' . $value->format('Y-m-d H:i:s');
             }
             return $classInfo;
         } else {
             // Get all accessors and their values
             $data = array();
             $data['class'] = '<span title="' . $class->getName() . '">' . $class->getShortName() . '</span>';
             if ($class->isIterateable()) {
                 $data['iterateable'] = $this->sanitizeIterateable($value, $maxRecursionDepth, $recursionDepth);
             } else {
                 $data['accessors'] = array();
                 foreach ($class->getMethods() as $method) {
                     if ($method->isPublic() && preg_match(self::METHOD_IS_ACCESSOR_REGEX, $method->getName())) {
                         $methodInfo = $method->getName() . '(';
                         foreach ($method->getParameters() as $parameter) {
                             $methodInfo .= '$' . $parameter->getName() . ', ';
                         }
                         $methodInfo = ($method->getNumberOfParameters() ? substr($methodInfo, 0, -2) : $methodInfo) . ')';
                         if (!$method->getNumberOfRequiredParameters()) {
                             // Get the value, we don't need params
                             try {
                                 $methodValue = $method->invoke($value);
                                 $data['accessors'][$methodInfo] = $this->sanitize($methodValue, $maxRecursionDepth, $recursionDepth + 1);
                             } catch (\Exception $e) {
                                 $data['accessors'][$methodInfo] = $this->sanitize(new InvokerException('Couldn\'t invoke method: Exception "' . get_class($e) . '" with message "' . $e->getMessage() . '"'), $maxRecursionDepth, $recursionDepth + 1);
                             }
                         } else {
                             // Get only method name and its params
                             $data['accessors'][] = $methodInfo;
                         }
                     }
                 }
             }
             return $data;
         }
     }
     if (is_string($value)) {
         $value = '(string) ' . $value;
     }
     if (is_int($value)) {
         $value = '(int) ' . $value;
     }
     if (is_float($value)) {
         $value = '(float) ' . $value;
     }
     if (is_null($value)) {
         $value = 'null';
     }
     if (is_bool($value)) {
         if ($value) {
             $value = '(bool) true';
         } else {
             $value = '(bool) false';
         }
     }
     return $value;
 }
开发者ID:ehough,项目名称:emailerrors-bundle,代码行数:99,代码来源:DumpyTwigFilter.php

示例3: testContainerIsIterator

 /**
  * @dataProvider dataProvider
  */
 public function testContainerIsIterator($container, $set)
 {
     $reflection = new \ReflectionClass($container);
     $this->assertTrue($reflection->isIterateable());
 }
开发者ID:squareproton,项目名称:bond,代码行数:8,代码来源:ContainerTest.php

示例4: isInstance

print "\n";
print "--- isInstance() ---\n";
var_dump($rb->isInstance(new B()));
var_dump($rb->isInstance(new C()));
print "\n";
print "--- isInstantiable() ---\n";
var_dump($rb->isInstantiable());
print "\n";
print "--- isInterface() ---\n";
var_dump($rb->isInterface());
print "\n";
print "--- isInternal() ---\n";
var_dump($rb->isInternal());
print "\n";
print "--- isIterateable() ---\n";
var_dump($rb->isIterateable());
print "\n";
print "--- isSubclassOf() ---\n";
var_dump($rb->isSubclassOf('A'));
var_dump($rb->isSubclassOf('C'));
print "\n";
print "--- isUserDefined() ---\n";
var_dump($rb->isUserDefined());
print "\n";
print "--- newInstance() ---\n";
var_dump($rb->newInstance());
print "\n";
print "--- newInstanceArgs() ---\n";
var_dump($rb->newInstanceArgs());
print "\n";
print "--- get_defined_functions() ---\n";
开发者ID:alphaxxl,项目名称:hhvm,代码行数:31,代码来源:reflection.php

示例5: fHandle

 /**
  *  handles the m* calls
  *  
  *  if you have a list of values, then you can use this function to run the same function on
  *  all the values (similar to array_map). If your values are objects, then you can do stuff
  *  like: out::m($list_of_obj,'->getOne()->isvalid()'). lets, say you want to get see what
  *  the trim output of your list of strings, then do: out::m($list_of_str,'trim');         
  *      
  *  @todo allow the method names to be an array were the first index is the name and
  *        the second -> N is the arguments to pass into the method (eg, array('method',$arg1,$arg2,...))   
  *      
  *  @param  string  $method the externally called method
  *  @param  array $func_arg_list  the args passed into $method
  *  @return out_call   
  */
 private static function fHandle($method, $func_arg_list = array())
 {
     $call_handler = null;
     $list = $func_arg_list[0];
     $method_list = array_slice($func_arg_list, 1);
     $is_valid_list = false;
     if (!empty($method_list)) {
         $is_valid_list = is_array($list);
         if (empty($is_valid_list) && is_object($list)) {
             // http://www.php.net/manual/en/reflectionclass.isiterateable.php
             $rclass = new ReflectionClass(get_class($val));
             $is_valid_list = $rclass->isIterateable();
         }
         //if
     }
     //if
     if ($is_valid_list) {
         $call_handler = self::getCall($method);
         $format_handler = new out_format($call_handler->config());
         $output = array();
         foreach ($list as $key => $val) {
             foreach ($method_list as $method) {
                 if (is_object($val)) {
                     $output[] = sprintf('%d - %s', $key, $format_handler->wrap('span', get_class($val), out_config::COLOR_INDEX));
                     if ($method[0] == '-') {
                         // the method is something like: ->getThis()->get() so eval it...
                         $arg_handler = new out_arg($method, eval(sprintf('return $val%s;', $method)));
                         $arg_handler->config($call_handler->config());
                         $output[] = $format_handler->indent("\t", $arg_handler->out());
                     } else {
                         if (method_exists($val, $method)) {
                             $arg_handler = new out_arg(sprintf('->%s()', $method), call_user_func(array($val, $method)));
                             $arg_handler->config($call_handler->config());
                             $output[] = $format_handler->indent("\t", $arg_handler->out());
                         } else {
                             $output[] = $format_handler->indent("\t", sprintf('->%s() undefined', $method));
                         }
                         //if/else
                     }
                     //if/else
                 } else {
                     $output[] = sprintf('%d - %s', $key, $format_handler->wrap('span', $val, out_config::COLOR_INDEX));
                     // since $val isn't an object, then use it as the value to pass to a function...
                     $arg_handler = new out_arg(sprintf('%s(%s)', $method, $val), call_user_func($method, $val));
                     $arg_handler->config($call_handler->config());
                     $output[] = $format_handler->indent("\t", $arg_handler->out());
                 }
                 //if/else
             }
             //foreach
         }
         //foreach
         $output[] = '';
         $arg_handler = new out_arg('', join("\r\n", $output));
         $arg_handler->type(out_arg::TYPE_STRING_GENERATED);
         $call_handler->set($arg_handler);
     }
     //if
     return $call_handler;
 }
开发者ID:Jaymon,项目名称:out,代码行数:75,代码来源:out_class.php

示例6: getIterator

{
    public function getIterator()
    {
    }
}
class ExtendsIteratorImpl extends IteratorImpl
{
}
class ExtendsIteratorAggregateImpl extends IterarorAggregateImpl
{
}
class A
{
}
$classes = array('Traversable', 'Iterator', 'IteratorAggregate', 'ExtendsIterator', 'ExtendsIteratorAggregate', 'IteratorImpl', 'IterarorAggregateImpl', 'ExtendsIteratorImpl', 'ExtendsIteratorAggregateImpl', 'A');
foreach ($classes as $class) {
    $rc = new ReflectionClass($class);
    echo "Is {$class} iterable? ";
    var_dump($rc->isIterateable());
}
echo "\nTest invalid params:\n";
$rc = new ReflectionClass('IteratorImpl');
var_dump($rc->isIterateable(null));
var_dump($rc->isIterateable(null, null));
var_dump($rc->isIterateable(1));
var_dump($rc->isIterateable(1.5));
var_dump($rc->isIterateable(true));
var_dump($rc->isIterateable('X'));
var_dump($rc->isIterateable(null));
echo "\nTest static invocation:\n";
ReflectionClass::isIterateable();
开发者ID:badlamer,项目名称:hhvm,代码行数:31,代码来源:ReflectionClass_isIterateable_001.php

示例7: isIterateable

 /**
  * {@inheritdoc}
  */
 public function isIterateable()
 {
     return $this->reflectionClass->isIterateable();
 }
开发者ID:roave,项目名称:better-reflection,代码行数:7,代码来源:ReflectionObject.php

示例8: __construct

 /**
  * 构造函数
  *
  * @param mixed $class
  */
 private function __construct($class)
 {
     if (!$class instanceof ReflectionClass) {
         $class = new ReflectionClass($class);
     }
     $this->name = $class->getName();
     $this->filename = $class->getFilename();
     $this->is_interface = $class->isInterface();
     $this->is_abstract = $class->isAbstract();
     $this->is_final = $class->isFinal();
     $this->is_iterateable = $class->isIterateable();
     $this->start_line = $class->getStartLine();
     $this->end_line = $class->getEndLine();
     $this->_reflection_class = $class;
 }
开发者ID:Debenson,项目名称:openwan,代码行数:20,代码来源:class.php

示例9: dump_iterateable

function dump_iterateable($obj)
{
    $reflection = new ReflectionClass($obj);
    var_dump($reflection->isIterateable());
}
开发者ID:badlamer,项目名称:hhvm,代码行数:5,代码来源:ReflectionClass_isIterateable_variation1.php


注:本文中的ReflectionClass::isIterateable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。