public static function fromReflection(ZendL_Reflection_Class $reflectionClass) { $class = new self(); $class->setSourceContent($class->getSourceContent()); $class->setSourceDirty(false); if ($reflectionClass->getDocComment() != '') { $class->setDocblock(ZendL_Tool_CodeGenerator_Php_Docblock::fromReflection($reflectionClass->getDocblock())); } $class->setAbstract($reflectionClass->isAbstract()); $class->setName($reflectionClass->getName()); if ($parentClass = $reflectionClass->getParentClass()) { $class->setExtendedClass($parentClass->getName()); } $class->setImplementedInterfaces($reflectionClass->getInterfaceNames()); $properties = array(); foreach ($reflectionClass->getProperties() as $reflectionProperty) { if ($reflectionProperty->getDeclaringClass()->getName() == $class->getName()) { $properties[] = ZendL_Tool_CodeGenerator_Php_Property::fromReflection($reflectionProperty); } } $class->setProperties($properties); $methods = array(); foreach ($reflectionClass->getMethods() as $reflectionMethod) { if ($reflectionMethod->getDeclaringClass()->getName() == $class->getName()) { $methods[] = ZendL_Tool_CodeGenerator_Php_Method::fromReflection($reflectionMethod); } } $class->setMethods($methods); return $class; }
/** * @param array $data * @return Schema */ public static function factory(array $data) { $schema = new self(); $schema->setName(self::stockProperty($data, SchemaEnum::NAME)); if (isset($data[SchemaEnum::LINKS])) { $schema->setLinks($data[SchemaEnum::LINKS]); } if (isset($data[SchemaEnum::PROPERTIES])) { $schema->setProperties($data[SchemaEnum::PROPERTIES]); } if (isset($data[SchemaEnum::ADDITIONAL_PROPERTIES])) { $schema->setAdditionalProperties($data[SchemaEnum::ADDITIONAL_PROPERTIES]); } return $schema; }
public static function getLatest($limit) { $limit = (int) $limit; $logs = array(); $pdo = DataSource::load(); $statement = 'SELECT log.*, brand.name AS brandName, brand.brandColor AS brandColor, brand.slug AS brandSlug FROM log LEFT JOIN brand ON log.brand = brand.id ORDER BY log.date DESC LIMIT :limit'; $preparedStatement = $pdo->prepare($statement); $preparedStatement->bindParam('limit', $limit, PDO::PARAM_INT); $preparedStatement->execute(); $logsData = $preparedStatement->fetchAll(); foreach ($logsData as $logData) { $log = new self(); $log->setProperties($logData); $logs[] = $log; } return $logs; }
/** * fromReflection() - build a Code Generation Php Object from a Class Reflection * * @param \Zend\Reflection\ReflectionClass $reflectionClass * @return \Zend\CodeGenerator\Php\PhpClass */ public static function fromReflection(\Zend\Reflection\ReflectionClass $reflectionClass) { $class = new self(); $class->setSourceContent($class->getSourceContent()); $class->setSourceDirty(false); if ($reflectionClass->getDocComment() != '') { $class->setDocblock(PhpDocblock::fromReflection($reflectionClass->getDocblock())); } $class->setAbstract($reflectionClass->isAbstract()); // set the namespace if ($reflectionClass->inNamespace()) { $class->setNamespaceName($reflectionClass->getNamespaceName()); } $class->setName($reflectionClass->getName()); if ($parentClass = $reflectionClass->getParentClass()) { $class->setExtendedClass($parentClass->getName()); $interfaces = array_diff($reflectionClass->getInterfaces(), $parentClass->getInterfaces()); } else { $interfaces = $reflectionClass->getInterfaces(); } $interfaceNames = array(); foreach($interfaces AS $interface) { $interfaceNames[] = $interface->getName(); } $class->setImplementedInterfaces($interfaceNames); $properties = array(); foreach ($reflectionClass->getProperties() as $reflectionProperty) { if ($reflectionProperty->getDeclaringClass()->getName() == $class->getName()) { $properties[] = PhpProperty::fromReflection($reflectionProperty); } } $class->setProperties($properties); $methods = array(); foreach ($reflectionClass->getMethods() as $reflectionMethod) { if ($reflectionMethod->getDeclaringClass()->getName() == $class->getName()) { $methods[] = PhpMethod::fromReflection($reflectionMethod); } } $class->setMethods($methods); return $class; }
/** * Creates a mapping object. * * @param array|\Elastica\Type\Mapping $mapping Mapping object or properties array * * @throws \Elastica\Exception\InvalidException If invalid type * * @return self */ public static function create($mapping) { if (is_array($mapping)) { $mappingObject = new self(); $mappingObject->setProperties($mapping); } else { $mappingObject = $mapping; } if (!$mappingObject instanceof self) { throw new InvalidException('Invalid object type'); } return $mappingObject; }
/** * * @param string $name * @param array $data * @return Fixture * @throws FixtureException */ public static function create($name, array $data) { $converter = isset($data['converter']) ? $data['converter'] : 'default'; $fixture = new self($name, $converter); if (!isset($data['data'])) { throw new FixtureException("missing data property"); } foreach ($data['data'] as $key => $value) { $fixture->add(new FixtureData($key, $value)); } if (isset($data['properties'])) { $fixture->setProperties(new ParameterBag($data['properties'])); } return $fixture; }
/** * Finds a specified instance of the model in the database. * * @param int $number Specifies which model instance to find; the 1st, 2nd, 3rd, ..... * * @return array Returns the particular instance of the model. */ public static function find($number) { if (!is_int($number)) { throw new InvalidArgumentException("The parameter {$number} is not an integer. An integer is required instead."); } if ($number <= 0) { throw new InvalidArgumentException("The parameter {$number} is not a positive integer. A positive integer is required instead."); } $result = new self(); $record = self::$_connection->findRecord(self::$_table, $number - 1); $result->setProperties($record[0]); return $result; }
public static function getAll() { $categories = array(); $pdo = DataSource::load(); $statement = 'SELECT * FROM category'; $preparedStatement = $pdo->prepare($statement); $preparedStatement->execute(); $categoriesData = $preparedStatement->fetchAll(); foreach ($categoriesData as $categoryData) { $category = new self(); $category->setProperties($categoryData); $categories[] = $category; } return $categories; }