Пример #1
0
 /**
  * Adds a Property. If Property already exists an Exception will be thrown.
  *
  * @param Property $property
  *
  * @return $this
  *
  * @throws \Exception
  */
 public function add(Property $property)
 {
     // Property already exists?
     if (null !== $this->get($property->getName())) {
         throw new \Exception("Property with name '{$property->getName()}' already exists");
     }
     $this->elements[] = $property;
     return $this;
 }
Пример #2
0
 public function loadXML($xml)
 {
     $dom = new \SimpleXMLElement($xml);
     if (!isset($dom->tokenXPath) || count($dom->tokenXPath) != 1) {
         throw new \LengthException('exactly one tokenXPath has to be provided');
     }
     $this->tokenXPath = $dom->tokenXPath;
     if (!isset($dom->tokenValueXPath) || count($dom->tokenValueXPath) != 1) {
         throw new \LengthException('exactly one tokenValueXPath has to be provided');
     }
     $this->tokenValueXPath = $dom->tokenValueXPath;
     if (!isset($dom->properties) || !isset($dom->properties->property) || count($dom->properties->property) == 0) {
         throw new \LengthException('no token properties defined');
     }
     $n = 1;
     $names = array();
     foreach ($dom->properties->property as $i) {
         $prop = new Property($i, $n++);
         $this->properties[] = $prop;
         $names[] = $prop->getName();
     }
     if (count($names) !== count(array_unique($names))) {
         throw new \RuntimeException('property names are not unique');
     }
     if (isset($dom->namespaces) && isset($dom->namespaces->namespace)) {
         foreach ($dom->namespaces->namespace as $i) {
             $this->namespaces[(string) $i->prefix[0]] = (string) $i->uri[0];
         }
     }
 }
Пример #3
0
 /**
  * @param Property $property
  */
 public function add(Property $property)
 {
     $propertyName = $property->getName();
     if (isset($this->properties[$propertyName])) {
         $existantProperty = $this->properties[$propertyName];
         $this->properties[$propertyName] = $existantProperty->merge($property);
     } else {
         $this->properties[$propertyName] = $property;
     }
 }
Пример #4
0
 public function __construct(Property $property, User $user, $action)
 {
     $this->user = $user;
     $this->property = $property;
     $this->name = $property->getName();
     $this->datatype = $property->getDatatype();
     $this->description = $property->getDescription();
     $this->descr = $property->getDescr();
     $this->action = $action;
     $this->action_time = new \DateTime();
 }
Пример #5
0
 /**
  * Bit of a messy way to add properties at a position.  Just so it doesn't muck about the generated property order.
  * As it's an associative array there's not a lot else that can be done.
  * It's not crucial that the order stays the same either.
  *
  * @param Property $property
  * @param null $insert_position
  * @param boolean $get_only
  */
 public function addProperty(Property $property, $insert_position = null, $get_only = false)
 {
     $key_name = strtolower($property->getName());
     if (isset($this->properties[$key_name]) && $get_only) {
         return;
     }
     $property->setModel($this);
     //This is so it can be retrospectively added in the case of deprecation.
     if ($insert_position !== null) {
         $properties = array();
         $property_position = 0;
         foreach ($this->properties as $existing_name => $existing_property) {
             if ($property_position++ === $insert_position) {
                 $properties[$key_name] = $property;
             }
             $properties[$existing_name] = $existing_property;
         }
         //Otherwise it's at the end (or after)
         if ($insert_position >= $property_position) {
             $properties[$key_name] = $property;
         }
         $this->properties = $properties;
     } else {
         $this->properties[$key_name] = $property;
     }
 }
Пример #6
0
 /**
  * Store an xtended (unspecified, vendor extension) property.
  * @param Property $property The property to store.
  * @param string $uid The uid of the CONTACT to associate the new
  * record with.
  * @return integer The ID of the newly created record.
  */
 private function storeXtendedProperty(Property $property, $uid)
 {
     assert($this->connection !== null);
     assert(!empty($uid));
     assert(is_string($uid));
     $stmt = $this->prepareCannedQuery('store', 'xtended');
     $stmt->bindValue(':uid', $uid);
     $stmt->bindValue(':name', $property->getName());
     $stmt->bindValue(':value', $property->getValue());
     $stmt->bindValue(':valuetype', $property->getValueType(false));
     $stmt->bindValue('pref', $property->getPref(false), \PDO::PARAM_INT);
     $stmt->bindValue(':mediatype', $property->getMediaType());
     $stmt->bindValue(':propGroup', $property->getGroup());
     $stmt->execute();
     $propertyID = $this->connection->lastInsertId();
     $this->associateTypes($property, $propertyID, 'xtended');
     return $propertyID;
 }
Пример #7
0
 public function addProperty(Property $property)
 {
     $this->properties[$property->getName()] = $property;
     return $this;
 }
Пример #8
0
 /**
  * Whether or a given property is available in the collection of
  * properties for this object instance
  *
  * @param \Puml\Model\Property $property
  *
  * @return boolean
  * @since 0.1
  */
 public function hasProperty(Property $property)
 {
     return isset($this->properties[$property->getName()]);
 }
Пример #9
0
 public function with(Property $property) : self
 {
     $clone = clone $this;
     $clone->properties[$property->getName()] = $property;
     return $clone;
 }
Пример #10
0
 public function addProperty(Property $property)
 {
     $property->setEntity($this);
     $this->properties[$property->getName()] = $property;
 }
Пример #11
0
 public function addProperty(Property $property)
 {
     $this->properties[strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $property->getName()))] = $property;
 }