本文整理汇总了PHP中ReflectionClass::hasProperty方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionClass::hasProperty方法的具体用法?PHP ReflectionClass::hasProperty怎么用?PHP ReflectionClass::hasProperty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionClass
的用法示例。
在下文中一共展示了ReflectionClass::hasProperty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testClassDeviceResult
public function testClassDeviceResult()
{
$class = new \ReflectionClass('UAParser\\Result\\Device');
$this->assertTrue($class->hasProperty('model'), 'property family does not exist anymore');
$this->assertTrue($class->hasProperty('brand'), 'property major does not exist anymore');
$this->assertTrue($class->hasProperty('family'), 'property family does not exist anymore');
}
示例2: process
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
foreach ($container->findTaggedServiceIds('mautic.event_subscriber') as $id => $tags) {
$definition = $container->findDefinition($id);
$classParents = class_parents($definition->getClass());
if (!in_array(CommonSubscriber::class, $classParents)) {
continue;
}
$definition->addMethodCall('setTemplating', [new Reference('mautic.helper.templating')]);
$definition->addMethodCall('setRequest', [new Reference('request_stack')]);
$definition->addMethodCall('setSecurity', [new Reference('mautic.security')]);
$definition->addMethodCall('setSerializer', [new Reference('jms_serializer')]);
$definition->addMethodCall('setSystemParameters', [new Parameter('mautic.parameters')]);
$definition->addMethodCall('setDispatcher', [new Reference('event_dispatcher')]);
$definition->addMethodCall('setTranslator', [new Reference('translator')]);
$definition->addMethodCall('setEntityManager', [new Reference('doctrine.orm.entity_manager')]);
$definition->addMethodCall('setRouter', [new Reference('router')]);
$class = $definition->getClass();
$reflected = new \ReflectionClass($class);
if ($reflected->hasProperty('logger')) {
$definition->addMethodCall('setLogger', [new Reference('monolog.logger.mautic')]);
}
// Temporary, for development purposes
if ($reflected->hasProperty('factory')) {
$definition->addMethodCall('setFactory', [new Reference('mautic.factory')]);
}
if (in_array(WebhookSubscriberBase::class, $classParents)) {
$definition->addMethodCall('setWebhookModel', [new Reference('mautic.webhook.model.webhook')]);
}
$definition->addMethodCall('init');
}
}
示例3: __get
/**
* Magic function which handles the properties accessibility.
* @param string $propertyName The property name.
*/
public function __get($propertyName)
{
switch ($propertyName) {
case '_baseExtendableObject':
return $this->_baseExtendableObject;
default:
$class = new \ReflectionClass($this);
if ($class->hasProperty($propertyName)) {
$property = $class->getProperty($propertyName);
$property->setAccessible(true);
return $property->getValue($this);
} else {
if ($class->hasProperty('_' . $propertyName)) {
$property = $class->getProperty('_' . $propertyName);
$property->setAccessible(true);
return $property->getValue($this);
} else {
$baseClass = new \ReflectionClass($_baseExtendableObject);
$method = $baseClass->getMethod('__get');
return $method->invoke($this, $propertyName);
}
}
return null;
}
}
示例4: testAddProperty
/**
*/
public function testAddProperty()
{
$prop = new ReflectionProperty('test');
$this->assertFalse($this->object->hasProperty('test'));
$this->object->addProperty($prop);
$this->assertTrue($this->object->hasProperty('test'));
}
示例5: testContracts
public function testContracts()
{
$this->assertTrue($this->reflectedObject->isAbstract());
$this->assertTrue($this->reflectedObject->hasMethod('getDefaultConfig'));
$this->assertTrue($this->reflectedObject->hasProperty('ts'));
$this->assertTrue($this->reflectedObject->hasProperty('shortcodes'));
$this->assertTrue($this->reflectedObject->hasProperty('config'));
}
示例6: getProperty
protected function getProperty($name)
{
if (!$this->target->hasProperty($name)) {
$message = sprintf('Property not found on object %s.', get_class($this->origin));
throw new OutOfBoundsException($message);
}
/** @var ReflectionProperty $property */
$property = $this->target->getProperty($name);
$property->setAccessible(true);
return $property;
}
示例7: add_hook_reflect
/**
* Adds the name of the specified hook to $hooks using reflection.
* @param $class_name
*/
private function add_hook_reflect($class_name)
{
$reflector = new ReflectionClass($class_name);
if (!$reflector->isAbstract() && $reflector->isSubclassOf("Hook") && $class_name !== "GenericHook" && $reflector->hasProperty("friendly_name")) {
$instance = $reflector->newInstance();
$name = $reflector->getProperty("friendly_name")->getValue($instance);
$this->hooks[$name] = "";
if ($this->get_config("Main", "web_hooks") && $reflector->hasProperty("web") && $reflector->getProperty("web")->getValue($instance)) {
$this->web_hooks[$name] = "";
}
}
}
示例8: getPropertyValue
/**
* @param $property_name
* @param $name
* @return \Symforce\CoreBundle\Annotation\SymforceAbstractAnnotation|array
* @throws \Exception
*/
public function getPropertyValue($property_name, $name, $fetch_values = false)
{
if (!$this->reflection->hasProperty($property_name)) {
throw new \Exception(sprintf("class property(%s->%s) not exists in file: %s ", $this->name, $property_name, $this->reflection->getFileName()));
}
if (!isset($this->properties_annotations[$property_name][$name])) {
throw new \Exception();
}
if ($fetch_values) {
$this->properties_annotations[$property_name][$name]->values;
}
return $this->properties_annotations[$property_name][$name]->value;
}
示例9: __construct
public function __construct($data = NULL)
{
if (!is_null($data) && !is_numeric($data) && !is_array($data) && !$data instanceof stdClass) {
throw new ShopException('Invalid $data type');
}
if (is_array($data) || $data instanceof stdClass) {
$this->loadFromArray((array) $data);
}
/**
* Look for Item repository.
* For IDE purposes like code completion $this->repo's type should be hinted in each Item the way I did in Cart.
*/
$repoClass = $this->getRepo();
$reflection = new ReflectionClass($repoClass);
$repoClass = (string) $reflection->getName();
$this->repo = $reflection->isInstantiable() ? new $repoClass() : null;
/**
* Look for srl field if it's not already set in class $meta
*/
$reflection = new ReflectionClass($this);
if ($srlField = $this->getMeta('srl')) {
//if srl is given
if (!$reflection->hasProperty($srlField)) {
throw new ShopException("Srl field '{$srlField}' doesn't exist");
}
} elseif ($reflection->hasProperty('srl')) {
$this->setMeta('srl', 'srl');
} else {
//else return the first _srl field
foreach ($this as $field => $value) {
if (substr($field, strlen($field) - 4, strlen($field)) === '_srl') {
$this->setMeta('srl', $field);
break;
}
}
if (!$this->getMeta('srl')) {
throw new ShopException('Couldn\'t identify the _srl column');
}
}
//data can also be a serial
if (is_numeric($data)) {
if ($obj = $this->repo->get($data, "get%E", get_called_class())) {
$this->copy($obj);
} else {
throw new ShopException("No such {$this->repo->entity} srl {$data}");
}
}
if (is_null(self::$cache)) {
self::$cache = new ShopCache();
}
}
示例10: __toString
public function __toString()
{
$object = new \ReflectionClass($this);
// Get the name of the constant type
$type = array_search($this->getType(), $object->getConstants());
// SimpleToken
if ($object->hasProperty('value')) {
return sprintf('Token: %s Value: %s', $type, $this->getValue());
} elseif ($object->hasProperty('name')) {
return sprintf('Token: %s Namespace: %s Name: %s', $type, $this->getNamespace(), $this->getName());
} else {
return sprintf('Token: %s', $type);
}
}
示例11: castObject
/**
* Casts objects to arrays and adds the dynamic property prefix.
*
* @param object $obj The object to cast
* @param \ReflectionClass $reflector The class reflector to use for inspecting the object definition
*
* @return array The array-cast of the object, with prefixed dynamic properties
*/
public static function castObject($obj, \ReflectionClass $reflector)
{
if ($reflector->hasMethod('__debugInfo')) {
$a = $obj->__debugInfo();
} elseif ($obj instanceof \Closure) {
$a = array();
} else {
$a = (array) $obj;
}
if ($obj instanceof \__PHP_Incomplete_Class) {
return $a;
}
if ($a) {
$combine = false;
$p = array_keys($a);
foreach ($p as $i => $k) {
if (isset($k[0]) && "" !== $k[0] && !$reflector->hasProperty($k)) {
$combine = true;
$p[$i] = self::PREFIX_DYNAMIC . $k;
} elseif (isset($k[16]) && "" === $k[16] && 0 === strpos($k, "class@anonymous")) {
$combine = true;
$p[$i] = "" . $reflector->getParentClass() . '@anonymous' . strrchr($k, "");
}
}
if ($combine) {
$a = array_combine($p, $a);
}
}
return $a;
}
示例12: postPersist
/**
* Este escucha permite esteblecer el consecutivo de las entidades
* al momento de ser almacenadas en base de datos
* @author Cesar Giraldo <cesargiraldo1108@gmail.com> 23/12/2015
* @param LifecycleEventArgs $args
*/
public function postPersist(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
$className = get_class($entity);
$entityManager = $args->getEntityManager();
$reflectedClass = new \ReflectionClass($className);
if ($reflectedClass->hasProperty('consecutive')) {
$consecutive = null;
$enabledEntity = false;
if ($entity instanceof Entity\Item) {
$enabledEntity = true;
//buscamos la cantidad de items que tiene creado un proyecto para asignar el consecutivo
$project = $entity->getProject();
$consecutive = $project->getLastItemConsecutive() + 1;
$project->setLastItemConsecutive($consecutive);
$entityManager->persist($project);
} elseif ($entity instanceof Entity\Sprint) {
$enabledEntity = true;
//buscamos la cantidad de items que tiene creado un proyecto para asignar el consecutivo
$project = $entity->getProject();
$consecutive = $project->getLastSprintConsecutive() + 1;
$project->setLastSprintConsecutive($consecutive);
$entityManager->persist($project);
}
if ($enabledEntity) {
if ($consecutive != null) {
$entity->setConsecutive($consecutive);
} else {
$entity->setConsecutive(1);
}
$entityManager->flush();
}
}
}
示例13: setBriefProperty
public function setBriefProperty($object, $name, $value, $expectedClass = null)
{
$reflection = new \ReflectionClass($object);
if (!$reflection->hasProperty($name)) {
return false;
}
$property = $reflection->getProperty($name);
$property->setAccessible(true);
if ($value instanceof Resource) {
$value = $value->getUri();
$annotation = $this->annotationReader->getPropertyAnnotation($property, 'Soil\\CommentsDigestBundle\\Annotation\\Entity');
if ($annotation) {
$expectedClass = $annotation->value ?: true;
var_dump($expectedClass);
try {
$entity = $this->resolver->getEntityForURI($value, $expectedClass);
} catch (\Exception $e) {
$entity = null;
echo "Problem with discovering" . PHP_EOL;
echo $e->getMessage() . PHP_EOL;
var_dump($value, $expectedClass);
echo PHP_EOL;
//FIXME: Add logging
}
if ($entity) {
$value = $entity;
}
}
} elseif ($value instanceof Literal) {
$value = $value->getValue();
}
$property->setValue($object, $value);
}
示例14: setPropertyValue
/**
* @param $tableField TableField
* @param $value object
* @param $propertyName string
* @param $destination object
* @return mixed|EntityProxy
*/
private function setPropertyValue($tableField, $value, $propertyName, $destination)
{
if (!is_null($value)) {
if ($tableField->isNumericType()) {
settype($value, "float");
} elseif ($tableField->isBoolType()) {
settype($value, "boolean");
} elseif ($tableField->isStringType()) {
settype($value, "string");
}
}
if ($fkConstraint = $tableField->getForeignKeyConstraint()) {
if ($fkConstraint->isOneToMany()) {
$referencedTableData = $fkConstraint->getForeignKeyField()->getTable();
$entity = $referencedTableData->getEntityInstance();
$value = new CollectionProxy($destination, $this->daoFactory->getDaoFromEntity($entity), $tableField);
} else {
$referencedTableData = $fkConstraint->getForeignKeyField()->getTable();
$entity = $referencedTableData->getEntityInstance();
$value = new EntityProxy($destination, $entity, $this->daoFactory->getDaoFromEntity($entity), $tableField);
}
}
if ($this->reflectionEntityClass->hasProperty($propertyName)) {
$property = $this->reflectionEntityClass->getProperty($propertyName);
if (!$property->isPublic()) {
$property->setAccessible(true);
$property->setValue($destination, $value);
$property->setAccessible(false);
} else {
$property->setValue($destination, $value);
}
} else {
$destination->{$propertyName} = $value;
}
}
示例15: process
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
foreach ($container->findTaggedServiceIds('mautic.model') as $id => $tags) {
$definition = $container->findDefinition($id);
$definition->addMethodCall('setEntityManager', [new Reference('doctrine.orm.entity_manager')]);
$definition->addMethodCall('setSecurity', [new Reference('mautic.security')]);
$definition->addMethodCall('setDispatcher', [new Reference('event_dispatcher')]);
$definition->addMethodCall('setTranslator', [new Reference('translator')]);
$definition->addMethodCall('setUserHelper', [new Reference('mautic.helper.user')]);
$modelClass = $definition->getClass();
$reflected = new \ReflectionClass($modelClass);
if ($reflected->hasMethod('setRouter')) {
$definition->addMethodCall('setRouter', [new Reference('router')]);
}
if ($reflected->hasMethod('setLogger')) {
$definition->addMethodCall('setLogger', [new Reference('monolog.logger.mautic')]);
}
if ($reflected->hasMethod('setSession')) {
$definition->addMethodCall('setSession', [new Reference('session')]);
}
// Temporary, for development purposes
if ($reflected->hasProperty('factory')) {
$definition->addMethodCall('setFactory', [new Reference('mautic.factory')]);
}
}
}