Exemplo n.º 1
0
    /**
     * Add a complex type by recursivly using all the class properties fetched via Reflection.
     *
     * @param  string $type Name of the class to be specified
     * @return string XSD Type for the given PHP type
     */
    public function addComplexType($type)
    {
        if(!class_exists($type)) {
            throw new Exception\InvalidArgumentException(sprintf(
                'Cannot add a complex type %s that is not an object or where '
              . 'class could not be found in \'DefaultComplexType\' strategy.', $type
            ));
        }

        if (($soapType = $this->scanRegisteredTypes($type)) !== null) {
            return $soapType;
        }

        $dom = $this->getContext()->toDomDocument();
        $class = new \ReflectionClass($type);

        $soapTypeName = $this->getContext()->translateType($type);
        $soapType     = 'tns:' . $soapTypeName;

        // Register type here to avoid recursion
        $this->getContext()->addType($type, $soapType);


        $defaultProperties = $class->getDefaultProperties();

        $defaultProperties = $class->getDefaultProperties();

        $complexType = $dom->createElement('xsd:complexType');
        $complexType->setAttribute('name', $soapTypeName);

        $all = $dom->createElement('xsd:all');

        foreach ($class->getProperties() as $property) {
            if ($property->isPublic() && preg_match_all('/@var\s+([^\s]+)/m', $property->getDocComment(), $matches)) {

                /**
                 * @todo check if 'xsd:element' must be used here (it may not be compatible with using 'complexType'
                 * node for describing other classes used as attribute types for current class
                 */
                $element = $dom->createElement('xsd:element');
                $element->setAttribute('name', $propertyName = $property->getName());
                $element->setAttribute('type', $this->getContext()->getType(trim($matches[1][0])));

                // If the default value is null, then this property is nillable.
                if ($defaultProperties[$propertyName] === null) {
                    $element->setAttribute('nillable', 'true');
                }

                $all->appendChild($element);
            }
        }

        $complexType->appendChild($all);
        $this->getContext()->getSchema()->appendChild($complexType);

        return $soapType;
    }
 /**
  * Tests if an object has the required attributes and they have the correct value.
  *
  * Returns true, if and only if the object defines ALL attributes and they have the expected value
  *
  * @param object $other
  *
  * @return bool
  */
 protected function matches($other)
 {
     $this->result = [];
     $success = true;
     $reflection = new \ReflectionClass($other);
     $properties = $reflection->getDefaultProperties();
     foreach ($this->defaultAttributes as $prop => $value) {
         if (is_int($prop)) {
             $prop = $value;
             $value = null;
         }
         if (array_key_exists($prop, $properties)) {
             try {
                 \PHPUnit_Framework_Assert::assertSame($value, $properties[$prop]);
                 $this->result[$prop] = true;
             } catch (\PHPUnit_Framework_ExpectationFailedException $e) {
                 $message = $e->toString();
                 if ($comparisonFailure = $e->getComparisonFailure()) {
                     $message .= sprintf("\n%30sExpected: %s\n%30sActual  : %s\n", '', $comparisonFailure->getExpectedAsString(), '', $comparisonFailure->getActualAsString());
                 }
                 $this->result[$prop] = $message;
                 $success = false;
             }
         } else {
             $this->result[$prop] = 'Attribute is not defined.';
             $success = false;
         }
     }
     return $success;
 }
 /**
  * put your comment there...
  * 
  * @param mixed $class
  * @param mixed $options
  */
 public function define($className, $options = array())
 {
     $definition = array();
     $definition['options'] = $options;
     // Get class properties to find out the events!
     $class = new ReflectionClass($className);
     $properties = $class->getProperties(ReflectionProperty::IS_PROTECTED);
     $values = $class->getDefaultProperties();
     // protected (static + non-static) represent an event!
     foreach ($properties as $property) {
         $propertyName = $property->getName();
         $propertyClass = $property->getDeclaringClass()->getName();
         if (strpos($propertyName, $options['prefix']) === 0) {
             // Get event properties!
             $eventName = substr($propertyName, strlen($options['prefix']));
             // If the event is already defined inherits the options!
             $inheritedOptions = array();
             if (isset($this->definitions[$propertyClass]['events'][$propertyName])) {
                 $inheritedOptions = $this->definitions[$propertyClass]['events'][$propertyName]['type'];
             }
             $definition['events'][$propertyName] = array('fullName' => $propertyName, 'name' => $eventName, 'class' => $propertyClass, 'id' => $eventName, 'type' => array_merge($options, $inheritedOptions, (array) $values[$propertyName]));
         }
     }
     $this->definitions[$className] = $this->extend($definition);
     return $this;
 }
Exemplo n.º 4
0
 /**
  * Initialize preferences
  *
  * @access	public
  * @param	array
  * @return	void
  */
 public function initialize(array $config = array(), $reset = TRUE)
 {
     $reflection = new ReflectionClass($this);
     if ($reset === TRUE) {
         $defaults = $reflection->getDefaultProperties();
         foreach (array_keys($defaults) as $key) {
             if ($key[0] === '_') {
                 continue;
             }
             if (isset($config[$key])) {
                 if ($reflection->hasMethod('set_' . $key)) {
                     $this->{'set_' . $key}($config[$key]);
                 } else {
                     $this->{$key} = $config[$key];
                 }
             } else {
                 $this->{$key} = $defaults[$key];
             }
         }
     } else {
         foreach ($config as $key => &$value) {
             if ($key[0] !== '_' && $reflection->hasProperty($key)) {
                 if ($reflection->hasMethod('set_' . $key)) {
                     $this->{'set_' . $key}($value);
                 } else {
                     $this->{$key} = $value;
                 }
             }
         }
     }
     // if a file_name was provided in the config, use it instead of the user input
     // supplied file name for all uploads until initialized again
     $this->_file_name_override = $this->file_name;
     return $this;
 }
Exemplo n.º 5
0
 /**
  * Testing annotations.
  *
  * @test
  * @covers \Bairwell\Hydrator\Annotations\From
  */
 public function testAnnotations()
 {
     $sut = new From();
     $reflection = new \ReflectionClass($sut);
     $this->assertTrue($reflection->isFinal());
     $properties = $reflection->getDefaultProperties();
     $expectedProperties = ['sources' => [], 'field' => null, 'conditions' => []];
     foreach ($expectedProperties as $k => $v) {
         $this->assertArrayHasKey($k, $properties);
         $this->assertEquals($v, $properties[$k]);
     }
     $comments = $reflection->getDocComment();
     $expected = preg_quote('@Annotation');
     $results = preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches);
     $this->assertEquals(1, $results);
     $expected = preg_quote('@Target({"PROPERTY"})');
     $this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches));
     //
     $property = $reflection->getProperty('sources');
     $comments = $property->getDocComment();
     $expected = '@var\\s+array';
     $this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches));
     $expected = '@Required';
     $this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches));
     // field
     $property = $reflection->getProperty('field');
     $comments = $property->getDocComment();
     $expected = '@var\\s+string';
     $this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches));
     // conditions
     $property = $reflection->getProperty('conditions');
     $comments = $property->getDocComment();
     $expected = '@var\\s+array';
     $this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches));
 }
Exemplo n.º 6
0
 /**
  * reads the form members and fills __formdata
  */
 public function __construct()
 {
     $this->__formdata = new \stdClass();
     $reflection = new \ReflectionClass(get_class($this));
     $this->__formdata->fields = $reflection->getDefaultProperties();
     unset($this->__formdata->fields['__formdata']);
 }
Exemplo n.º 7
0
/**
 * Get a list of standard columns.
 */
function columns_get_standard()
{
    $t_reflection = new ReflectionClass('BugData');
    $t_columns = $t_reflection->getDefaultProperties();
    $t_columns['selection'] = null;
    $t_columns['edit'] = null;
    # Overdue icon column (icons appears if an issue is beyond due_date)
    $t_columns['overdue'] = null;
    if (OFF == config_get('enable_profiles')) {
        unset($t_columns['os']);
        unset($t_columns['os_build']);
        unset($t_columns['platform']);
    }
    if (config_get('enable_eta') == OFF) {
        unset($t_columns['eta']);
    }
    if (config_get('enable_projection') == OFF) {
        unset($t_columns['projection']);
    }
    if (config_get('enable_product_build') == OFF) {
        unset($t_columns['build']);
    }
    # The following fields are used internally and don't make sense as columns
    unset($t_columns['_stats']);
    unset($t_columns['profile_id']);
    unset($t_columns['sticky']);
    unset($t_columns['loading']);
    return array_keys($t_columns);
}
Exemplo n.º 8
0
 private function discriminateClass(\ReflectionClass $class, array $data)
 {
     $properties = $class->getDefaultProperties();
     if (!empty($properties["modelDiscriminatorMap"])) {
         $discriminator = $properties["modelDiscriminatorMap"];
         if (empty($discriminator["discriminatorField"])) {
             throw new ModelException("Cannot use the discriminator map for '{$class->getName()}'. No discriminator field was configured.");
         }
         $field = $discriminator["discriminatorField"];
         if (empty($data[$field])) {
             throw new ModelException("The discriminator field '{$field}' for '{$class->getName()}' was not found in the data set.");
         }
         $baseNamespace = !empty($discriminator["subclassNamespace"]) ? $discriminator["subclassNamespace"] : $class->getNamespaceName();
         $classNameSuffix = !empty($discriminator["subclassSuffix"]) ? $discriminator["subclassSuffix"] : "";
         $map = !empty($discriminator["map"]) ? $discriminator["map"] : [];
         // generate the class name
         $value = $data[$field];
         if (empty($map[$value])) {
             throw new ModelException("The discriminator value '{$value}' was not registered in the map");
         }
         $className = $map[$value] !== true ? $map[$value] : $this->toStudlyCaps($value);
         // if this is not a valid class, try it with the base namespace
         if (!class_exists($className)) {
             $className = $baseNamespace . "\\" . $className;
             if (!class_exists($className)) {
                 $className .= $classNameSuffix;
             }
         }
         // create the reflection object. This will throw an exception if the class does not exist, as is expected.
         $class = new \ReflectionClass($className);
     }
     return $class;
 }
 /**
  * A basic functional test example.
  *
  * @return void
  */
 public function testHtmlBuilderQuoteFlags()
 {
     $htmlBuilderReflection = new ReflectionClass(new HtmlBuilder());
     $quoteFlags = $htmlBuilderReflection->getDefaultProperties()['quoteFlags'];
     $this->assertArrayHasKey('ENT_COMPAT', $quoteFlags);
     $this->assertArrayHasKey('ENT_QUOTES', $quoteFlags);
     $this->assertArrayHasKey('ENT_NOQUOTES', $quoteFlags);
     $this->assertArrayHasKey('ENT_IGNORE', $quoteFlags);
     $this->assertArrayHasKey('ENT_SUBSTITUTE', $quoteFlags);
     $this->assertArrayHasKey('ENT_DISALLOWED', $quoteFlags);
     $this->assertArrayHasKey('ENT_HTML401', $quoteFlags);
     $this->assertArrayHasKey('ENT_XML1', $quoteFlags);
     $this->assertArrayHasKey('ENT_XHTML', $quoteFlags);
     $this->assertArrayHasKey('ENT_HTML5', $quoteFlags);
     $this->assertContains(2, $quoteFlags);
     $this->assertContains(3, $quoteFlags);
     $this->assertContains(0, $quoteFlags);
     $this->assertContains(4, $quoteFlags);
     $this->assertContains(8, $quoteFlags);
     $this->assertContains(128, $quoteFlags);
     $this->assertContains(16, $quoteFlags);
     $this->assertContains(32, $quoteFlags);
     $this->assertContains(48, $quoteFlags);
     $this->assertEquals(ENT_COMPAT, $quoteFlags['ENT_COMPAT']);
     $this->assertEquals(ENT_QUOTES, $quoteFlags['ENT_QUOTES']);
     $this->assertEquals(ENT_NOQUOTES, $quoteFlags['ENT_NOQUOTES']);
     $this->assertEquals(ENT_IGNORE, $quoteFlags['ENT_IGNORE']);
     $this->assertEquals(ENT_SUBSTITUTE, $quoteFlags['ENT_SUBSTITUTE']);
     $this->assertEquals(ENT_DISALLOWED, $quoteFlags['ENT_DISALLOWED']);
     $this->assertEquals(ENT_HTML401, $quoteFlags['ENT_HTML401']);
     $this->assertEquals(ENT_XML1, $quoteFlags['ENT_XML1']);
     $this->assertEquals(ENT_XHTML, $quoteFlags['ENT_XHTML']);
     $this->assertEquals(ENT_HTML5, $quoteFlags['ENT_HTML5']);
 }
Exemplo n.º 10
0
 /**
  * Add a complex type by recursivly using all the class properties fetched via Reflection.
  *
  * @param  string $type Name of the class to be specified
  * @return string XSD Type for the given PHP type
  */
 public function addComplexType($type)
 {
     if (!class_exists($type)) {
         #require_once "Zend/Soap/Wsdl/Exception.php";
         throw new Zend_Soap_Wsdl_Exception(sprintf("Cannot add a complex type %s that is not an object or where " . "class could not be found in 'DefaultComplexType' strategy.", $type));
     }
     $dom = $this->getContext()->toDomDocument();
     $class = new ReflectionClass($type);
     $defaultProperties = $class->getDefaultProperties();
     $complexType = $dom->createElement('xsd:complexType');
     $complexType->setAttribute('name', $type);
     $all = $dom->createElement('xsd:all');
     foreach ($class->getProperties() as $property) {
         if ($property->isPublic() && preg_match_all('/@var\\s+([^\\s]+)/m', $property->getDocComment(), $matches)) {
             /**
              * @todo check if 'xsd:element' must be used here (it may not be compatible with using 'complexType'
              * node for describing other classes used as attribute types for current class
              */
             $element = $dom->createElement('xsd:element');
             $element->setAttribute('name', $propertyName = $property->getName());
             $element->setAttribute('type', $this->getContext()->getType(trim($matches[1][0])));
             // If the default value is null, then this property is nillable.
             if ($defaultProperties[$propertyName] === null) {
                 $element->setAttribute('nillable', 'true');
             }
             $all->appendChild($element);
         }
     }
     $complexType->appendChild($all);
     $this->getContext()->getSchema()->appendChild($complexType);
     $this->getContext()->addType($type);
     return "tns:{$type}";
 }
 /**
  * Restores all static attributes in user-defined classes from this snapshot.
  *
  * @param Snapshot $snapshot
  */
 public function restoreStaticAttributes(Snapshot $snapshot)
 {
     $current = new Snapshot($snapshot->blacklist(), false, false, false, false, true, false, false, false, false);
     $newClasses = array_diff($current->classes(), $snapshot->classes());
     unset($current);
     foreach ($snapshot->staticAttributes() as $className => $staticAttributes) {
         foreach ($staticAttributes as $name => $value) {
             $reflector = new ReflectionProperty($className, $name);
             $reflector->setAccessible(true);
             $reflector->setValue($value);
         }
     }
     foreach ($newClasses as $className) {
         $class = new \ReflectionClass($className);
         $defaults = $class->getDefaultProperties();
         foreach ($class->getProperties() as $attribute) {
             if (!$attribute->isStatic()) {
                 continue;
             }
             $name = $attribute->getName();
             if ($snapshot->blacklist()->isStaticAttributeBlacklisted($className, $name)) {
                 continue;
             }
             if (!isset($defaults[$name])) {
                 continue;
             }
             $attribute->setAccessible(true);
             $attribute->setValue($defaults[$name]);
         }
     }
 }
Exemplo n.º 12
0
 public static function getPages($exclude_filled = false, $add_page = false)
 {
     $selected_pages = array();
     if (!($files = Tools::scandir(_PS_ROOT_DIR_ . '/controllers/front/', 'php', '', true))) {
         die(Tools::displayError('Cannot scan root directory'));
     }
     // Exclude pages forbidden
     $exlude_pages = array('category', 'changecurrency', 'cms', 'footer', 'header', 'pagination', 'product', 'product-sort', 'statistics');
     foreach ($files as $file) {
         if ($file != 'index.php' && !in_array(strtolower(str_replace('Controller.php', '', $file)), $exlude_pages)) {
             $class_name = str_replace('.php', '', $file);
             if (class_exists($class_name)) {
                 $reflection = new ReflectionClass(str_replace('.php', '', $file));
             }
             if (isset($reflection) && $reflection) {
                 $properties = $reflection->getDefaultProperties();
             }
             if (isset($properties['php_self'])) {
                 $selected_pages[$properties['php_self']] = $properties['php_self'];
             } else {
                 if (preg_match('/^[a-z0-9_.-]*\\.php$/i', $file)) {
                     $selected_pages[strtolower(str_replace('Controller.php', '', $file))] = strtolower(str_replace('Controller.php', '', $file));
                 } else {
                     if (preg_match('/^([a-z0-9_.-]*\\/)?[a-z0-9_.-]*\\.php$/i', $file)) {
                         $selected_pages[strtolower(sprintf(Tools::displayError('%2$s (in %1$s)'), dirname($file), str_replace('Controller.php', '', basename($file))))] = strtolower(str_replace('Controller.php', '', basename($file)));
                     }
                 }
             }
         }
     }
     // Add modules controllers to list (this function is cool !)
     foreach (glob(_PS_MODULE_DIR_ . '*/controllers/front/*.php') as $file) {
         $filename = Tools::strtolower(basename($file, '.php'));
         if ($filename == 'index') {
             continue;
         }
         $module = Tools::strtolower(basename(dirname(dirname(dirname($file)))));
         $selected_pages[$module . ' - ' . $filename] = 'module-' . $module . '-' . $filename;
     }
     // Exclude page already filled
     if ($exclude_filled) {
         $metas = Meta::getMetas();
         foreach ($metas as $meta) {
             if (in_array($meta['page'], $selected_pages)) {
                 unset($selected_pages[array_search($meta['page'], $selected_pages)]);
             }
         }
     }
     // Add selected page
     if ($add_page) {
         $name = $add_page;
         if (preg_match('#module-([a-z0-9_-]+)-([a-z0-9]+)$#i', $add_page, $m)) {
             $add_page = $m[1] . ' - ' . $m[2];
         }
         $selected_pages[$add_page] = $name;
         asort($selected_pages);
     }
     return $selected_pages;
 }
 public function offsetUnset($offset)
 {
     if ($this->offsetExists($offset)) {
         $rc = new \ReflectionClass(static::class);
         $defaults = $rc->getDefaultProperties();
         $this->{$offset} = $defaults[$offset];
     }
 }
Exemplo n.º 14
0
 public function yamlToViewDefinition($path)
 {
     $definitionContent = file_get_contents($path);
     $yaml = new Parser();
     $definition = $yaml->parse($definitionContent);
     $reflection = new \ReflectionClass(ObjectCrud::class);
     return array_merge($reflection->getDefaultProperties(), $definition);
 }
Exemplo n.º 15
0
 protected function _processSpecialties()
 {
     $specialties = array();
     if ($this->_providerReflection->hasMethod('getSpecialties')) {
         $specialties = $this->_provider->getSpecialties();
         if (!is_array($specialties)) {
             throw new ZendL_Tool_Rpc_Exception('Provider ' . get_class($this->_provider) . ' must return an array for method getSpecialties().');
         }
     } else {
         $defaultProperties = $this->_providerReflection->getDefaultProperties();
         $specialties = isset($defaultProperties['_specialties']) ? $defaultProperties['_specialties'] : array();
         if (!is_array($specialties)) {
             throw new ZendL_Tool_Rpc_Exception('Provider ' . get_class($this->_provider) . '\'s property $_specialties must be an array.');
         }
     }
     $this->_specialties = array_merge(array('_Global'), $specialties);
 }
Exemplo n.º 16
0
 /**
  * @return array
  */
 public function jsonSerialize()
 {
     $reflection = new \ReflectionClass($this);
     $properties = $reflection->getDefaultProperties();
     foreach ($properties as $field => $value) {
         $data[$field] = $this->{'get' . $field}();
     }
     return $data;
 }
Exemplo n.º 17
0
 function getDefaultValue($name)
 {
     if (property_exists($this, $name)) {
         $c = new \ReflectionClass($this);
         $props = $c->getDefaultProperties();
         return isset($props[$name]) ? $props[$name] : null;
     }
     return null;
 }
 public function __construct()
 {
     $reflect = new \ReflectionClass($this);
     $properties = $reflect->getDefaultProperties();
     foreach ($properties as $property => $value) {
         $this->{$property} = new Nil();
     }
     $this->properties = $properties;
 }
Exemplo n.º 19
0
 public function bind($array)
 {
     $class = new \ReflectionClass($this);
     $properties = $class->getDefaultProperties();
     foreach (array_intersect_key($array, $properties) as $key => $value) {
         $method = "set" . ucfirst($key);
         $class->hasMethod($method) ? $this->{$method}($value) : ($this->{$key} = $value);
     }
     return $this;
 }
Exemplo n.º 20
0
 /**
  * Returns the default configuration for a node class.
  *
  * @param string $className
  * @return mixed
  */
 public static function getDefaultConfiguration($className)
 {
     $configuration = null;
     $class = new ReflectionClass($className);
     $defaults = $class->getDefaultProperties();
     if (isset($defaults['configuration'])) {
         $configuration = $defaults['configuration'];
     }
     return $configuration;
 }
Exemplo n.º 21
0
 /**
  * returns the default value of a property in a class
  *
  * @param string $property
  * @param string $className
  * @return mixed
  */
 public static function getFromClass($property, $className)
 {
     $result = null;
     $reflection = new \ReflectionClass($className);
     $properties = $reflection->getDefaultProperties();
     if (array_key_exists($property, $properties)) {
         $result = $properties[$property];
     }
     return $result;
 }
Exemplo n.º 22
0
 /**
  * Constructs a Plugin object.
  *
  * Builds up the plugin definition and invokes the get() method for any
  * classed annotations that were used.
  */
 public function __construct($values)
 {
     $reflection = new \ReflectionClass($this);
     // Only keep actual default values by ignoring NULL values.
     $defaults = array_filter($reflection->getDefaultProperties(), function ($value) {
         return $value !== NULL;
     });
     $parsed_values = $this->parse($values);
     $this->definition = NestedArray::mergeDeep($defaults, $parsed_values);
 }
Exemplo n.º 23
0
 static function stGetObjFields()
 {
     $class = get_called_class();
     $objFields = array();
     foreach (Object::stGetHierarchy($class) as $class) {
         $reflex = new ReflectionClass($class);
         $properties = $reflex->getDefaultProperties();
         $objFields = array_merge($objFields, $properties["objFields"]);
     }
     return $objFields;
 }
 /**
  * Constructor.
  *
  * @param \ReflectionClass $class   ReflectionClass object.
  * @param array            $options Configuration options.
  */
 public function __construct(\ReflectionClass $class, array $options = array())
 {
     parent::__construct($options);
     $this->class = $class;
     $this->properties = $class->getProperties();
     $this->defaults = $class->getDefaultProperties();
     // sort by property name
     usort($this->properties, function ($prop1, $prop2) {
         return $prop1->name < $prop2->name ? -1 : 1;
     });
 }
Exemplo n.º 25
0
 public function testCreate()
 {
     $chargeForm = new ChargeForm();
     $chargeForm->load(require 'data/charge.php', '');
     $this->assertTrue($chargeForm->validate());
     $data = $chargeForm->create()->__toArray();
     $this->assertTrue(is_array($data));
     $reflectionClass = new ReflectionClass('\\idarex\\pingppyii2\\CodeAutoCompletion\\Charge');
     $properties = $reflectionClass->getDefaultProperties();
     $this->assertTrue(array_diff_key($data, $properties) == []);
 }
Exemplo n.º 26
0
 /**
  * 设置私有属性
  * @param $data
  */
 public function setOptions($data)
 {
     $ref = new ReflectionClass('AuthService');
     $properties = array_keys($ref->getDefaultProperties());
     if (!empty($data) && is_array($data)) {
         foreach ($data as $key => $val) {
             if (in_array($key, $properties)) {
                 $this->{$key} = $val;
             }
         }
     }
 }
 public final function __construct()
 {
     $input = func_get_args();
     $this->beforeConstruct($input);
     $reflection = new ReflectionClass(get_class($this));
     $this->function_defaults = $reflection->getDefaultProperties();
     $this->function_parameters = array_keys($this->function_defaults);
     $this->parseParameters($input, true);
     $this->afterConstruct($input);
     if (isset($this->function_autorun) && $this->function_autorun === true) {
         $this->run();
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function matches($other)
 {
     $this->getterName = 'get' . ucfirst($this->propertyName);
     if (!method_exists($other, $this->getterName)) {
         $this->getterName = 'is' . ucfirst($this->propertyName);
     }
     if (!method_exists($other, $this->getterName)) {
         $message = sprintf("Entity %s doesn't have a get%s() or is%s() getters for property %s", get_class($other), 'get' . ucfirst($this->propertyName), 'is' . ucfirst($this->propertyName), $this->propertyName);
         throw new \PHPUnit_Framework_Exception($message);
     }
     $class = new \ReflectionClass($other);
     $defaultProperties = $class->getDefaultProperties();
     return call_user_func_array([$other, $this->getterName], []) === $defaultProperties[$this->propertyName];
 }
Exemplo n.º 29
0
 public function getFixedProperties()
 {
     if (!$this->_fixedProperties) {
         $this->_fixedProperties = [];
         $class = new \ReflectionClass($this);
         $publicProperties = $class->getProperties(\ReflectionProperty::IS_PUBLIC);
         $defaults = $class->getDefaultProperties();
         foreach ($publicProperties as $prop) {
             if ($defaults[$prop->name] !== null) {
                 $this->_fixedProperties[$prop->name] = $defaults[$prop->name];
             }
         }
     }
     return $this->_fixedProperties;
 }
Exemplo n.º 30
0
 protected function getProtectedProperty($objectOrClass, $property)
 {
     if (is_object($objectOrClass)) {
         $propertyRef = new \ReflectionProperty($objectOrClass, $property);
         $propertyRef->setAccessible(true);
         return $propertyRef->getValue($objectOrClass);
     } else {
         $classRef = new \ReflectionClass($objectOrClass);
         $properties = $classRef->getDefaultProperties();
         if (!isset($properties[$property])) {
             throw new \Exception('Property "' . $property . '" not found in class "' . $objectOrClass . '"');
         }
         return $properties[$property];
     }
 }