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


PHP ReflectionClass::isInstance方法代码示例

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


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

示例1: __invoke

 /**
  * Checks entity for this filter.
  *
  * @param mixed $entity
  *
  * @return bool
  */
 public function __invoke($entity)
 {
     if (!is_object($entity) || !$this->class->isInstance($entity)) {
         return false;
     }
     $accepted = true;
     foreach (array_keys($this->criteria) as $criteria) {
         $accepted = $accepted && $this->{'check' . ucfirst($criteria) . 'Criteria'}($entity);
         // Optimization.
         if (!$accepted) {
             return $accepted;
         }
     }
     return $accepted;
 }
开发者ID:alexeyshockov,项目名称:tizona,代码行数:22,代码来源:EntityFilter.php

示例2: iShouldGetAnInstanceOf

 /**
  * @Then /^I should get an instance of "([^"]*)"$/
  */
 public function iShouldGetAnInstanceOf($instance)
 {
     $rc = new \ReflectionClass($instance);
     if (!$rc->isInstance(false === strpos($instance, 'Factory') ? $this->feed : $this->factory)) {
         throw new \Exception('This is not the feed factory');
     }
 }
开发者ID:remontees,项目名称:FeedBundle,代码行数:10,代码来源:FeatureContext.php

示例3: cast

 /**
  * Casts an object to the class or interface represented
  * by this <tt>Class</tt> object.
  *
  * @param obj the object to be cast
  * @return blaze\lang\Object the object after casting, or null if obj is null
  *
  * @throws ClassCastException if the object is not
  * null and is not assignable to the type T.
  *
  * @since 1.5
  */
 public function cast(Reflectable $obj)
 {
     if (!$this->reflectionClass->isInstance($obj)) {
         throw new ClassCastException();
     }
     return $obj;
 }
开发者ID:robo47,项目名称:BlazeFramework,代码行数:19,代码来源:ClassWrapper.php

示例4: testIsInstance

 /**
  */
 public function testIsInstance()
 {
     $this->object->setName('\\Documentor\\Reflection\\ReflectionClass');
     $this->assertFalse($this->object->isInstance(new \stdClass()));
     $this->assertTrue($this->object->isInstance(new ReflectionClass()));
     $this->setExpectedException('\\InvalidArgumentException');
     $this->object->isInstance("string");
 }
开发者ID:neiluJ,项目名称:Documentor,代码行数:10,代码来源:ReflectionClassTest.php

示例5: testShoppingOrderRateRequestFactory

 public function testShoppingOrderRateRequestFactory()
 {
     $factory = $this->getApplicationContext()->getComponent('\\FS\\Components\\Shipping\\Factory\\ShoppingOrderRateRequestFactory');
     $options = $this->getApplicationContext()->getComponent('\\FS\\Components\\Options');
     $request = $factory->setPayload(array('order' => $this->order, 'options' => $options))->getRequest();
     $reflected = new \ReflectionClass('\\FS\\Components\\Shipping\\Factory\\FormattedRequestInterface');
     $this->assertTrue(true, $reflected->isInstance($request));
     $this->assertSame(array('from' => array('country' => 'CA', 'state' => 'QC', 'city' => 'POINTE-CLAIRE', 'postal_code' => 'H9R5P9', 'address' => '148 Brunswick', 'name' => 'FlagShip WooCommerce Test App', 'attn' => 'FlagShip Tester', 'phone' => '+1 866 320 8383', 'ext' => ''), 'to' => array('name' => 'WooCompany', 'attn' => 'Jeroen Sormani', 'address' => 'WooAddress', 'city' => 'WooCity', 'state' => 'NY', 'country' => 'US', 'postal_code' => '123456', 'phone' => ''), 'packages' => array('items' => array(0 => array('width' => 1, 'height' => 1, 'length' => 1, 'weight' => 4, 'description' => 'Flagship shipping package')), 'units' => 'imperial', 'type' => 'package'), 'payment' => array('payer' => 'F'), 'options' => array('address_correction' => true)), $request->getRequest());
 }
开发者ID:flagshipcompany,项目名称:flagship-for-woocommerce,代码行数:9,代码来源:RequestFactoryTestCase.php

示例6: add

 /**
  * @throws \InvalidArgumentException
  * @param ItemInterface $item
  * @return Feed
  */
 public function add(ItemInterface $item)
 {
     $rc = new \ReflectionClass($this->config['class']);
     if (!($rc->isInstance($item) || $item instanceof GenericItem)) {
         throw new \InvalidArgumentException('The class given MUST be an instance of "' . $this->config['class'] . '".');
     }
     $this->items[] = $item;
     $this->autoSlice();
     return $this;
 }
开发者ID:0x616469,项目名称:FeedBundle,代码行数:15,代码来源:Feed.php

示例7: toObject

 /**
  * Dynamically generates the object from the declared properties of the given object or array
  *
  * @param array|object $object
  *
  * @return \stdClass
  */
 public static function toObject($object)
 {
     //	If we can't iterate over the thing, we bail
     if (!is_object($object) && !is_array($object) && !$object instanceof \Traversable) {
         return null;
     }
     if (is_array($object)) {
         //	Convert to an object
         $_properties = new \stdClass();
         foreach ($object as $_key => $_value) {
             $_properties->{$_key} = $_value;
         }
     } else {
         $_me = new \ReflectionObject($object);
         $_properties = $_me->getProperties();
     }
     //	We'll return this
     $_obj = new \stdClass();
     if (!empty($_properties)) {
         if (is_object($object)) {
             $_myClass = get_class($object);
         } else {
             $_myClass = '_array_';
         }
         foreach ($_properties as $_property) {
             //	Only want properties of $object hierarchy...
             if (isset($_property->class)) {
                 $_class = new \ReflectionClass($_property->class);
                 if (!empty($_class) && !$_class->isInstance($object) && !$_class->isSubclassOf($_myClass)) {
                     unset($_class);
                     continue;
                 }
                 unset($_class);
             }
             try {
                 $_realPropertyName = $_propertyName = ltrim($_property->name, '_ ');
                 if (false !== strpos($_propertyName, '_')) {
                     $_propertyName = Inflector::tag($_propertyName);
                 }
                 $_getter = 'get' . $_propertyName;
                 if (method_exists($object, $_getter)) {
                     $_propertyValue = $object->{$_getter}();
                     if (!is_scalar($_propertyValue)) {
                         $_propertyValue = self::toObject($_propertyValue);
                     }
                     $_obj->{$_realPropertyName} = $_propertyValue;
                 }
             } catch (\Exception $_ex) {
                 //	Just ignore, not a valid property if we can't read it with a getter
             }
         }
     }
     return $_obj;
 }
开发者ID:kisma,项目名称:kisma,代码行数:61,代码来源:Convert.php

示例8: __invoke

 /**
  * Compares two entities.
  *
  * @throws \InvalidArgumentException If entities can not be compared.
  *
  * @param mixed $entity1
  * @param mixed $entity2
  *
  * @return int
  */
 public function __invoke($entity1, $entity2)
 {
     if (!$this->class->isInstance($entity1) || !$this->class->isInstance($entity2)) {
         throw new \InvalidArgumentException();
     }
     $result = 0;
     foreach ($this->order as $property => $order) {
         $property1 = $entity1->{'get' . ucfirst($property)}();
         $property2 = $entity2->{'get' . ucfirst($property)}();
         $result = $this->{'compare' . ucfirst($this->properties[$property]) . 's'}($property1, $property2);
         if (self::ORDER_DESC == $order) {
             $result = -$result;
         }
         // Unless first success comparision.
         if ($result) {
             break;
         }
     }
     return $result;
 }
开发者ID:alexeyshockov,项目名称:tizona,代码行数:30,代码来源:EntityComparator.php

示例9: isInstanceOf

 /**
  * @param mixed                   $object
  * @param string|\ReflectionClass $class
  *
  * @return bool
  */
 public static function isInstanceOf($object, $class)
 {
     // TODO Validate $class.
     if (!is_object($class)) {
         $class = new \ReflectionClass($class);
     }
     if (is_object($object)) {
         return $class->isInstance($object);
     } else {
         return false;
     }
 }
开发者ID:alexeyshockov,项目名称:colada,代码行数:18,代码来源:TypeHelper.php

示例10: setApplicationContext

 public final function setApplicationContext(\FS\Context\ApplicationContextInterface $ctx = null)
 {
     if (!$this->ctx && !$this->isContextRequired()) {
         return $this;
     }
     $reflected = new \ReflectionClass($this->requiredContextClass());
     if (!$this->ctx && !$reflected->isInstance($ctx)) {
         throw new \Exception('Invalid application context: needs to be of type [' . $this->requiredContextClass() . ']');
     }
     $this->ctx = $ctx;
     return $this;
 }
开发者ID:flagshipcompany,项目名称:flagship-for-woocommerce,代码行数:12,代码来源:AbstractApplicationObjectSupport.php

示例11: get

 public static function get()
 {
     $args = func_get_args();
     $type = array_shift($args);
     $classname = ucwords($type) . __CLASS__;
     Log::debug(__CLASS__ . ': Getting new ' . $classname);
     $reflector = new ReflectionClass($classname);
     $dbdoclist = $reflector->newInstanceArgs($args);
     if ($reflector->isInstance($dbdoclist)) {
         return $dbdoclist;
     } else {
         Log::warning(__CLASS__ . ': Could not get new ' . $classname);
         return false;
     }
 }
开发者ID:runderwood,项目名称:redberry,代码行数:15,代码来源:class.dbdoclist.php

示例12: readEntity

 public function readEntity(RoutingContextInterface $context, \ReflectionClass $ref, &$isRead)
 {
     if (!$ref->implementsInterface(EntityInterface::class)) {
         return;
     }
     $request = $context->getRequest();
     if (!$request->hasEntity()) {
         return;
     }
     $entity = $request->getEntity();
     if ($ref->isInstance($entity)) {
         $isRead = true;
         return $entity;
     }
 }
开发者ID:koolkode,项目名称:rest,代码行数:15,代码来源:HttpEntityReader.php

示例13: get

 public static function get()
 {
     $args = func_get_args();
     $doc_type = array_shift($args);
     $class_name = ucwords($doc_type) . 'DBDoc';
     Log::debug(__CLASS__ . ': Getting instance of ' . $class_name);
     $reflector = new ReflectionClass($class_name);
     $dbdoc = $reflector->newInstanceArgs($args);
     Log::debug(__CLASS__ . ': Got new instance: ' . print_r($dbdoc, true));
     if ($reflector->isInstance($dbdoc)) {
         return $dbdoc;
     } else {
         Log::debug(__CLASS__ . ': Could not get ' . $class_name);
         return false;
     }
 }
开发者ID:runderwood,项目名称:redberry,代码行数:16,代码来源:class.dbdoc.php

示例14: reflect

 /**
  * Show reflection
  *
  * Show reflection
  *
  * <code>
  * Panda_Debug::reflect('BEAR_Form');  // Class
  * Panda_Debug::reflect($obj);        // Objecy
  * Panda_Debug::reflect('p');         // Function
  * </code>
  *
  * @param string $target      target
  * @param boll   $cehckParent check parent class
  *
  * @return void
  */
 public static function reflect($target, $cehckParent = false)
 {
     if (is_object($target)) {
         $target = get_class($target);
     }
     switch (true) {
         case function_exists($target):
             $ref = new ReflectionFunction($target);
             $info['name'] = $ref->isInternal() ? 'The internal ' : 'The user-defined ';
             $info['name'] .= $targetName = $ref->getName();
             $info['declare in'] = $ref->getFileName() . ' lines ' . $ref->getStartLine() . ' to ' . $ref->getEndline();
             $info['Documentation'] = $ref->getDocComment();
             $statics = $ref->getStaticVariables();
             if ($statics) {
                 $info['Static variables'] = $statics;
             }
             $type = 'function';
             break;
         case class_exists($target, false):
             $ref = new ReflectionClass($target);
             $type = 'class';
             $info['name'] = $ref->isInternal() ? 'The internal ' : 'The user-defined ';
             $info['name'] .= $ref->isAbstract() ? ' abstract ' : '';
             $info['name'] .= $ref->isFinal() ? ' final ' : '';
             $info['name'] .= $ref->isInterface() ? 'interface ' : 'class ';
             $info['name'] .= $targetName = $ref->getName();
             $info['declare in'] = $ref->getFileName() . ' lines ' . $ref->getStartLine() . ' to ' . $ref->getEndline();
             $info['modifiers'] = Reflection::getModifierNames($ref->getModifiers());
             $info['Documentation'] = $ref->getDocComment();
             $info['Implements'] = $ref->getInterfaces();
             $info['Constants'] = $ref->getConstants();
             foreach ($ref->getProperties() as $prop) {
                 // ReflectionProperty クラスのインスタンスを生成する
                 $propRef = new ReflectionProperty($targetName, $prop->name);
                 if ($propRef->isPublic()) {
                     $porps[] = $prop->name;
                 }
             }
             //            $info['Public Properties'] = $porps;
             foreach ($ref->getMethods() as $method) {
                 $methodRef = new ReflectionMethod($targetName, $method->name);
                 if ($methodRef->isPublic() || $method->isStatic()) {
                     $final = $method->isFinal() ? 'final ' : '';
                     $pubic = $method->isPublic() ? 'public ' : '';
                     $static = $method->isStatic() ? ' static ' : '';
                     $methods[] = sprintf("%s%s%s %s", $final, $pubic, $static, $method->name);
                 }
             }
             $info['Public Methods'] = $methods;
             if ($ref->isInstantiable() && is_object($target)) {
                 $info['isInstance ?'] = $ref->isInstance($target) ? 'yes' : 'no';
             }
             if ($parent) {
                 $info['parent'] .= $ref->getParentClass();
             }
             break;
         default:
             $type = 'Invalid Object/Class';
             $targetName = $target;
             $info = null;
             break;
     }
     print_a($info, "show_objects:1;label: Reflection of {$type} '{$targetName}'");
 }
开发者ID:sssAlchemy,项目名称:Panda,代码行数:80,代码来源:Debug.php

示例15: array

<?php

class A
{
}
class B extends A
{
}
interface I
{
}
class C implements I
{
}
class X
{
}
$classes = array("A", "B", "C", "I", "X");
$instances = array("myA" => new A(), "myB" => new B(), "myC" => new C(), "myX" => new X());
foreach ($classes as $class) {
    $rc = new ReflectionClass($class);
    foreach ($instances as $name => $instance) {
        echo "is {$name} a {$class}? ";
        var_dump($rc->isInstance($instance));
    }
}
开发者ID:badlamer,项目名称:hhvm,代码行数:26,代码来源:ReflectionClass_isInstance_basic.php


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