ApiPlatform\Core\Util\Reflection::getProperty PHP Method

getProperty() public method

Gets the property name associated with an accessor method.
public getProperty ( string $methodName ) : string | null
$methodName string
return string | null
    public function getProperty($methodName)
    {
        $pattern = implode('|', array_merge(self::ACCESSOR_PREFIXES, self::MUTATOR_PREFIXES));
        if (preg_match('/^(' . $pattern . ')(.+)$/i', $methodName, $matches)) {
            return $matches[2];
        }
    }

Usage Example

Example #1
0
 public function testWithBadMethodName()
 {
     $methodName = 'delGerard';
     $reflection = new Reflection();
     $return = $reflection->getProperty($methodName);
     $this->assertNotEquals($return, 'Gerard');
     $this->assertEquals($return, null);
 }
Reflection