Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"Survey says..." -- Richard Dawson, weenie, on "Family Feud"


devel / comp.lang.php / a question on

SubjectAuthor
* a question onMeredith Montgomery
`* a question on a PayPal's ReflectionUtil (Was: Re: a question on)Meredith Montgomery
 `* Re: a question on a PayPal's ReflectionUtil (Was: Re: a question on)J.O. Aho
  `- Re: a question on a PayPal's ReflectionUtil (Was: Re: a question on)V

1
a question on

<864k12ertd.fsf@levado.to>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=539&group=comp.lang.php#539

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!aioe.org!0Z6C6fhbX6bqLEMQtPplTA.user.46.165.242.91.POSTED!not-for-mail
From: mmontgomery@levado.to (Meredith Montgomery)
Newsgroups: comp.lang.php
Subject: a question on
Date: Thu, 02 Jun 2022 17:25:18 -0300
Organization: Aioe.org NNTP Server
Message-ID: <864k12ertd.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="24387"; posting-host="0Z6C6fhbX6bqLEMQtPplTA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
Cancel-Lock: sha1:6o3gJHgFlWomACT432kPj93HHgY=
 by: Meredith Montgomery - Thu, 2 Jun 2022 20:25 UTC

The file

PayPal/Common/ReflectionUtil.php

--- whose content I show entirely below --- seems to be a class with
only static methods and static properties. Now, check the procedure

public static function propertyAnnotations($class, $propertyName)

It contains the chunk

if (!($refl =& self::$propertiesRefl[$class][$propertyName])) {
$getter = self::getter($class, $propertyName);
$refl = new \ReflectionMethod($class, $getter);
self::$propertiesRefl[$class][$propertyName] = $refl;
}

So $refl is instantiated and it is stored in

self::$propertiesRefl[$class][$propertyName]

which is a private static array. This means it cannot be acessed from
the ``outside''. Also, no other chunk in this class uses
$propertiesRefl.

Question. Why are they storing $refl if nobody uses it all, not even
the very class that defines it?

Thank you for any information on this.

(*) PayPal/Common/ReflectionUtil.php

<?php

namespace PayPal\Common;
use PayPal\Exception\PayPalConfigurationException;

/**
* Class ReflectionUtil
*
* @package PayPal\Common
*/
class ReflectionUtil
{

/**
* Reflection Methods
*
* @var \ReflectionMethod[]
*/
private static $propertiesRefl = array();

/**
* Properties Type
*
* @var string[]
*/
private static $propertiesType = array();

/**
* Gets Property Class of the given property.
* If the class is null, it returns null.
* If the property is not found, it returns null.
*
* @param $class
* @param $propertyName
* @return null|string
* @throws PayPalConfigurationException
*/
public static function getPropertyClass($class, $propertyName)
{
if ($class == get_class(new PayPalModel())) {
// Make it generic if PayPalModel is used for generating this
return get_class(new PayPalModel());
}

// If the class doesn't exist, or the method doesn't exist, return null.
if (!class_exists($class) || !method_exists($class, self::getter($class, $propertyName))) {
return null;
}

if (($annotations = self::propertyAnnotations($class, $propertyName)) && isset($annotations['return'])) {
$param = $annotations['return'];
}

if (isset($param)) {
$anno = preg_split("/[\s\[\]]+/", $param);
return $anno[0];
} else {
throw new PayPalConfigurationException("Getter function for '$propertyName' in '$class' class should have a proper return type.");
}
}

/**
* Checks if the Property is of type array or an object
*
* @param $class
* @param $propertyName
* @return null|boolean
* @throws PayPalConfigurationException
*/
public static function isPropertyClassArray($class, $propertyName)
{
// If the class doesn't exist, or the method doesn't exist, return null.
if (!class_exists($class) || !method_exists($class, self::getter($class, $propertyName))) {
return null;
}

if (($annotations = self::propertyAnnotations($class, $propertyName)) && isset($annotations['return'])) {
$param = $annotations['return'];
}

if (isset($param)) {
return substr($param, -strlen('[]'))==='[]';
} else {
throw new PayPalConfigurationException("Getter function for '$propertyName' in '$class' class should have a proper return type.");
}
}

/**
* Retrieves Annotations of each property
*
* @param $class
* @param $propertyName
* @throws \RuntimeException
* @return mixed
*/
public static function propertyAnnotations($class, $propertyName)
{
$class = is_object($class) ? get_class($class) : $class;
if (!class_exists('ReflectionProperty')) {
throw new \RuntimeException("Property type of " . $class . "::{$propertyName} cannot be resolved");
}

if ($annotations =& self::$propertiesType[$class][$propertyName]) {
return $annotations;
}

if (!($refl =& self::$propertiesRefl[$class][$propertyName])) {
$getter = self::getter($class, $propertyName);
$refl = new \ReflectionMethod($class, $getter);
self::$propertiesRefl[$class][$propertyName] = $refl;
}

// todo: smarter regexp
if ( !preg_match_all(
'~\@([^\s@\(]+)[\t ]*(?:\(?([^\n@]+)\)?)?~i',
$refl->getDocComment(),
$annots,
PREG_PATTERN_ORDER)) {
return null;
}
foreach ($annots[1] as $i => $annot) {
$annotations[strtolower($annot)] = empty($annots[2][$i]) ? TRUE : rtrim($annots[2][$i], " \t\n\r)");
}

return $annotations;
}

/**
* preg_replace_callback callback function
*
* @param $match
* @return string
*/
private static function replace_callback($match)
{
return ucwords($match[2]);
}

/**
* Returns the properly formatted getter function name based on class name and property
* Formats the property name to a standard getter function
*
* @param string $class
* @param string $propertyName
* @return string getter function name
*/
public static function getter($class, $propertyName)
{
return method_exists($class, "get" . ucfirst($propertyName)) ?
"get" . ucfirst($propertyName) :
"get" . preg_replace_callback("/([_\-\s]?([a-z0-9]+))/", "self::replace_callback", $propertyName);
}
}

a question on a PayPal's ReflectionUtil (Was: Re: a question on)

<86r146dcxj.fsf@levado.to>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=541&group=comp.lang.php#541

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!aioe.org!0Z6C6fhbX6bqLEMQtPplTA.user.46.165.242.91.POSTED!not-for-mail
From: mmontgomery@levado.to (Meredith Montgomery)
Newsgroups: comp.lang.php
Subject: a question on a PayPal's ReflectionUtil (Was: Re: a question on)
Date: Thu, 02 Jun 2022 17:32:08 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86r146dcxj.fsf@levado.to>
References: <864k12ertd.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="29789"; posting-host="0Z6C6fhbX6bqLEMQtPplTA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
Cancel-Lock: sha1:kgyg0I27aiD0Xk5qwtLAZ8Y8Qr0=
X-Notice: Filtered by postfilter v. 0.9.2
 by: Meredith Montgomery - Thu, 2 Jun 2022 20:32 UTC

Sorry about the incomplete subject. I'm fixing that. I think I also
understood a bit more about the code I'm asking, so I'm going to add an
addendum. Sorry about this small mess.

Meredith Montgomery <mmontgomery@levado.to> writes:

> The file
>
> PayPal/Common/ReflectionUtil.php
>
> --- whose content I show entirely below --- seems to be a class with
> only static methods and static properties. Now, check the procedure
>
> public static function propertyAnnotations($class, $propertyName)
>
> It contains the chunk
>
> if (!($refl =& self::$propertiesRefl[$class][$propertyName])) {
> $getter = self::getter($class, $propertyName);
> $refl = new \ReflectionMethod($class, $getter);
> self::$propertiesRefl[$class][$propertyName] = $refl;
> }
>
> So $refl is instantiated and it is stored in
>
> self::$propertiesRefl[$class][$propertyName]
>
> which is a private static array. This means it cannot be acessed from
> the ``outside''. Also, no other chunk in this class uses
> $propertiesRefl.
>
> Question. Why are they storing $refl if nobody uses it all, not even
> the very class that defines it?

Actually, it clearly does use $refl. It's used right at the first line
in the chunk above. It is set merely so the if-inner-code is only
executed once in its lifetime. Why? Can you just clarify to me what's
going on this class? I'm not understanding it too clearly. Thank you!

>
> (*) PayPal/Common/ReflectionUtil.php
>
> <?php
>
> namespace PayPal\Common;
> use PayPal\Exception\PayPalConfigurationException;
>
> /**
> * Class ReflectionUtil
> *
> * @package PayPal\Common
> */
> class ReflectionUtil
> {
>
> /**
> * Reflection Methods
> *
> * @var \ReflectionMethod[]
> */
> private static $propertiesRefl = array();
>
> /**
> * Properties Type
> *
> * @var string[]
> */
> private static $propertiesType = array();
>
>
> /**
> * Gets Property Class of the given property.
> * If the class is null, it returns null.
> * If the property is not found, it returns null.
> *
> * @param $class
> * @param $propertyName
> * @return null|string
> * @throws PayPalConfigurationException
> */
> public static function getPropertyClass($class, $propertyName)
> {
> if ($class == get_class(new PayPalModel())) {
> // Make it generic if PayPalModel is used for generating this
> return get_class(new PayPalModel());
> }
>
> // If the class doesn't exist, or the method doesn't exist, return null.
> if (!class_exists($class) || !method_exists($class, self::getter($class, $propertyName))) {
> return null;
> }
>
> if (($annotations = self::propertyAnnotations($class, $propertyName)) && isset($annotations['return'])) {
> $param = $annotations['return'];
> }
>
> if (isset($param)) {
> $anno = preg_split("/[\s\[\]]+/", $param);
> return $anno[0];
> } else {
> throw new PayPalConfigurationException("Getter function for '$propertyName' in '$class' class should have a proper return type.");
> }
> }
>
> /**
> * Checks if the Property is of type array or an object
> *
> * @param $class
> * @param $propertyName
> * @return null|boolean
> * @throws PayPalConfigurationException
> */
> public static function isPropertyClassArray($class, $propertyName)
> {
> // If the class doesn't exist, or the method doesn't exist, return null.
> if (!class_exists($class) || !method_exists($class, self::getter($class, $propertyName))) {
> return null;
> }
>
> if (($annotations = self::propertyAnnotations($class, $propertyName)) && isset($annotations['return'])) {
> $param = $annotations['return'];
> }
>
> if (isset($param)) {
> return substr($param, -strlen('[]'))==='[]';
> } else {
> throw new PayPalConfigurationException("Getter function for '$propertyName' in '$class' class should have a proper return type.");
> }
> }
>
> /**
> * Retrieves Annotations of each property
> *
> * @param $class
> * @param $propertyName
> * @throws \RuntimeException
> * @return mixed
> */
> public static function propertyAnnotations($class, $propertyName)
> {
> $class = is_object($class) ? get_class($class) : $class;
> if (!class_exists('ReflectionProperty')) {
> throw new \RuntimeException("Property type of " . $class . "::{$propertyName} cannot be resolved");
> }
>
> if ($annotations =& self::$propertiesType[$class][$propertyName]) {
> return $annotations;
> }
>
> if (!($refl =& self::$propertiesRefl[$class][$propertyName])) {
> $getter = self::getter($class, $propertyName);
> $refl = new \ReflectionMethod($class, $getter);
> self::$propertiesRefl[$class][$propertyName] = $refl;
> }
>
> // todo: smarter regexp
> if ( !preg_match_all(
> '~\@([^\s@\(]+)[\t ]*(?:\(?([^\n@]+)\)?)?~i',
> $refl->getDocComment(),
> $annots,
> PREG_PATTERN_ORDER)) {
> return null;
> }
> foreach ($annots[1] as $i => $annot) {
> $annotations[strtolower($annot)] = empty($annots[2][$i]) ? TRUE : rtrim($annots[2][$i], " \t\n\r)");
> }
>
> return $annotations;
> }
>
> /**
> * preg_replace_callback callback function
> *
> * @param $match
> * @return string
> */
> private static function replace_callback($match)
> {
> return ucwords($match[2]);
> }
>
> /**
> * Returns the properly formatted getter function name based on class name and property
> * Formats the property name to a standard getter function
> *
> * @param string $class
> * @param string $propertyName
> * @return string getter function name
> */
> public static function getter($class, $propertyName)
> {
> return method_exists($class, "get" . ucfirst($propertyName)) ?
> "get" . ucfirst($propertyName) :
> "get" . preg_replace_callback("/([_\-\s]?([a-z0-9]+))/", "self::replace_callback", $propertyName);
> }
> }

Re: a question on a PayPal's ReflectionUtil (Was: Re: a question on)

<jftmv5FplujU1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=542&group=comp.lang.php#542

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: user@example.net (J.O. Aho)
Newsgroups: comp.lang.php
Subject: Re: a question on a PayPal's ReflectionUtil (Was: Re: a question on)
Date: Fri, 3 Jun 2022 08:10:44 +0200
Lines: 51
Message-ID: <jftmv5FplujU1@mid.individual.net>
References: <864k12ertd.fsf@levado.to> <86r146dcxj.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net vAEjE8QCxpZtDWjgpBD5FA1XZWbMB42K78kYSjURAeDrabGrg9
Cancel-Lock: sha1:5UWmVLPp49KfR11o4elvk0EBN38=
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.9.1
Content-Language: en-US-large
In-Reply-To: <86r146dcxj.fsf@levado.to>
 by: J.O. Aho - Fri, 3 Jun 2022 06:10 UTC

On 02/06/2022 22.32, Meredith Montgomery wrote:
> Sorry about the incomplete subject. I'm fixing that. I think I also
> understood a bit more about the code I'm asking, so I'm going to add an
> addendum. Sorry about this small mess.
>
> Meredith Montgomery <mmontgomery@levado.to> writes:
>
>> The file
>>
>> PayPal/Common/ReflectionUtil.php
>>
>> --- whose content I show entirely below --- seems to be a class with
>> only static methods and static properties. Now, check the procedure
>>
>> public static function propertyAnnotations($class, $propertyName)
>>
>> It contains the chunk
>>
>> if (!($refl =& self::$propertiesRefl[$class][$propertyName])) {
>> $getter = self::getter($class, $propertyName);
>> $refl = new \ReflectionMethod($class, $getter);
>> self::$propertiesRefl[$class][$propertyName] = $refl;
>> }
>>
>> So $refl is instantiated and it is stored in
>>
>> self::$propertiesRefl[$class][$propertyName]
>>
>> which is a private static array. This means it cannot be acessed from
>> the ``outside''. Also, no other chunk in this class uses
>> $propertiesRefl.
>>
>> Question. Why are they storing $refl if nobody uses it all, not even
>> the very class that defines it?
>
> Actually, it clearly does use $refl. It's used right at the first line
> in the chunk above. It is set merely so the if-inner-code is only
> executed once in its lifetime. Why? Can you just clarify to me what's
> going on this class? I'm not understanding it too clearly. Thank you!

Yes, the inner code in this section will be called once for each
combination of "class" and "propertyName".
The function will return a array of annotations (read a bit about it
here: https://www.educba.com/php-annotations )

It's most likely used to setup correct check for input values client
side and maybe even for post value validation.

--

//Aho

Re: a question on a PayPal's ReflectionUtil (Was: Re: a question on)

<04a6eb3e-52ae-4593-b513-5ed7c567d5d3n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=815&group=comp.lang.php#815

  copy link   Newsgroups: comp.lang.php
X-Received: by 2002:a05:620a:5c:b0:742:7e2b:68d2 with SMTP id t28-20020a05620a005c00b007427e2b68d2mr6227427qkt.7.1679062066217;
Fri, 17 Mar 2023 07:07:46 -0700 (PDT)
X-Received: by 2002:a81:d302:0:b0:541:359c:103a with SMTP id
y2-20020a81d302000000b00541359c103amr4573750ywi.8.1679062065966; Fri, 17 Mar
2023 07:07:45 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.php
Date: Fri, 17 Mar 2023 07:07:45 -0700 (PDT)
In-Reply-To: <jftmv5FplujU1@mid.individual.net>
Injection-Info: google-groups.googlegroups.com; posting-host=85.253.157.133; posting-account=ogslnwoAAACd9vU9PADzlWBA81fSuNpL
NNTP-Posting-Host: 85.253.157.133
References: <864k12ertd.fsf@levado.to> <86r146dcxj.fsf@levado.to> <jftmv5FplujU1@mid.individual.net>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <04a6eb3e-52ae-4593-b513-5ed7c567d5d3n@googlegroups.com>
Subject: Re: a question on a PayPal's ReflectionUtil (Was: Re: a question on)
From: techfan55555@hotmail.com (V)
Injection-Date: Fri, 17 Mar 2023 14:07:46 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3570
 by: V - Fri, 17 Mar 2023 14:07 UTC

Let's get to know each other. Me: http://kohtumispaik.000webhostapp.com/Infovahetusteks/dpic/1679061026.gif

Have a nice day......

On Friday, June 3, 2022 at 8:10:54 AM UTC+2, J.O. Aho wrote:
> On 02/06/2022 22.32, Meredith Montgomery wrote:
> > Sorry about the incomplete subject. I'm fixing that. I think I also
> > understood a bit more about the code I'm asking, so I'm going to add an
> > addendum. Sorry about this small mess.
> >
> > Meredith Montgomery <mmont...@levado.to> writes:
> >
> >> The file
> >>
> >> PayPal/Common/ReflectionUtil.php
> >>
> >> --- whose content I show entirely below --- seems to be a class with
> >> only static methods and static properties. Now, check the procedure
> >>
> >> public static function propertyAnnotations($class, $propertyName)
> >>
> >> It contains the chunk
> >>
> >> if (!($refl =& self::$propertiesRefl[$class][$propertyName])) {
> >> $getter = self::getter($class, $propertyName);
> >> $refl = new \ReflectionMethod($class, $getter);
> >> self::$propertiesRefl[$class][$propertyName] = $refl;
> >> }
> >>
> >> So $refl is instantiated and it is stored in
> >>
> >> self::$propertiesRefl[$class][$propertyName]
> >>
> >> which is a private static array. This means it cannot be acessed from
> >> the ``outside''. Also, no other chunk in this class uses
> >> $propertiesRefl.
> >>
> >> Question. Why are they storing $refl if nobody uses it all, not even
> >> the very class that defines it?
> >
> > Actually, it clearly does use $refl. It's used right at the first line
> > in the chunk above. It is set merely so the if-inner-code is only
> > executed once in its lifetime. Why? Can you just clarify to me what's
> > going on this class? I'm not understanding it too clearly. Thank you!
> Yes, the inner code in this section will be called once for each
> combination of "class" and "propertyName".
> The function will return a array of annotations (read a bit about it
> here: https://www.educba.com/php-annotations )
>
> It's most likely used to setup correct check for input values client
> side and maybe even for post value validation.
>
> --
>
> //Aho

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor