Skip to content

Commit

Permalink
Fixed canonical object URL (closes #8)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkphl committed Aug 3, 2016
1 parent f077fb6 commit 76bf7f6
Show file tree
Hide file tree
Showing 13 changed files with 243 additions and 182 deletions.
6 changes: 2 additions & 4 deletions src/Object/Domain/Model/Object/AbstractObject.php
Expand Up @@ -305,7 +305,7 @@ public function getPropertyData($serialize = true)
*/
public function getAbsoluteUrl()
{
return getenv('APPARAT_BASE_URL').rtrim($this->locator->getRepository()->getUrl(), '/').strval($this->locator);
return $this->locator->toRepositoryUrl(false, false);
}

/**
Expand All @@ -315,9 +315,7 @@ public function getAbsoluteUrl()
*/
public function getCanonicalUrl()
{
$canonicalLocator = $this->locator->setRevision(Revision::current());
$canonicalUrl = ltrim($this->locator->getRepository()->getUrl(), '/').strval($canonicalLocator);
return getenv('APPARAT_BASE_URL').$canonicalUrl;
return $this->locator->toRepositoryUrl(false, true);
}

/**
Expand Down
49 changes: 26 additions & 23 deletions src/Object/Domain/Model/Object/Traits/SystemPropertiesTrait.php
Expand Up @@ -155,33 +155,11 @@ public function getLatitude()
*/
public function setLatitude($latitude)
{
/** @var SystemProperties $this */
$this->setSystemProperties($this->systemProperties->setLatitude($latitude));
return $this;
}

/**
* Set the system properties collection
*
* @param SystemProperties $systemProperties System property collection
* @param bool $overwrite Overwrite the existing collection (if present)
*/
protected function setSystemProperties(SystemProperties $systemProperties, $overwrite = false)
{
$this->systemProperties = $systemProperties;
$systemPropsState = spl_object_hash($this->systemProperties);

// If the system property collection state has changed
if (!$overwrite
&& !empty($this->collectionStates[SystemProperties::COLLECTION])
&& ($systemPropsState !== $this->collectionStates[SystemProperties::COLLECTION])
) {
// Flag this object as mutated
$this->setModifiedState();
}

$this->collectionStates[SystemProperties::COLLECTION] = $systemPropsState;
}

/**
* Return the longitude
*
Expand All @@ -200,6 +178,7 @@ public function getLongitude()
*/
public function setLongitude($longitude)
{
/** @var SystemProperties $this */
$this->setSystemProperties($this->systemProperties->setLongitude($longitude));
return $this;
}
Expand All @@ -222,10 +201,34 @@ public function getElevation()
*/
public function setElevation($elevation)
{
/** @var SystemProperties $this */
$this->setSystemProperties($this->systemProperties->setElevation($elevation));
return $this;
}

/**
* Set the system properties collection
*
* @param SystemProperties $systemProperties System property collection
* @param bool $overwrite Overwrite the existing collection (if present)
*/
protected function setSystemProperties(SystemProperties $systemProperties, $overwrite = false)
{
$this->systemProperties = $systemProperties;
$systemPropsState = spl_object_hash($this->systemProperties);

// If the system property collection state has changed
if (!$overwrite
&& !empty($this->collectionStates[SystemProperties::COLLECTION])
&& ($systemPropsState !== $this->collectionStates[SystemProperties::COLLECTION])
) {
// Flag this object as mutated
$this->setModifiedState();
}

$this->collectionStates[SystemProperties::COLLECTION] = $systemPropsState;
}

/**
* Set the object state to modified
*/
Expand Down
110 changes: 55 additions & 55 deletions src/Object/Domain/Model/Properties/AbstractProperties.php
Expand Up @@ -47,18 +47,6 @@
*/
abstract class AbstractProperties implements PropertiesInterface
{
/**
* Property data
*
* @var array
*/
protected $data = [];
/**
* Owner object
*
* @var ObjectInterface
*/
protected $object = null;
/**
* Absolute URL property
*
Expand All @@ -71,6 +59,18 @@ abstract class AbstractProperties implements PropertiesInterface
* @var string
*/
const PROPERTY_CANONICAL_URL = 'canonicalUrl';
/**
* Property data
*
* @var array
*/
protected $data = [];
/**
* Owner object
*
* @var ObjectInterface
*/
protected $object = null;

/**
* Meta properties constructor
Expand All @@ -94,6 +94,49 @@ public function getObject()
return $this->object;
}

/**
* Return the property values as array
*
* @param bool $serialize Serialize property objects
* @return array Property values
*/
public function toArray($serialize = true)
{
return $this->toSerializedArray($serialize, $this->data);
}

/**
* Return the potentially serialized property values
*
* @param boolean $serialize Serialize objects
* @param array $data Property values
* @return array Serialized property values
*/
protected function toSerializedArray($serialize, array $data)
{
// Filter all empty values
$data = array_filter($data);

// If the values should be serialized
if ($serialize) {
// Run through all properties
while (list($property, $value) = each($data)) {
// If the value is an array itself: Recurse
if (is_array($value)) {
$data[$property] = $this->toSerializedArray($serialize, $value);
// Else if the value is serializable
} elseif (is_object($value) &&
(new \ReflectionClass($value))->implementsInterface(SerializablePropertyInterface::class)
) {
/** @var $value SerializablePropertyInterface */
$data[$property] = $value->serialize();
}
}
}

return $data;
}

/**
* Normalize and sort a property value list
*
Expand Down Expand Up @@ -188,47 +231,4 @@ protected function mutatePropertiesProperty($property, PropertiesInterface $valu
// Else: return self reference
return $this;
}

/**
* Return the property values as array
*
* @param bool $serialize Serialize property objects
* @return array Property values
*/
public function toArray($serialize = true)
{
return $this->toSerializedArray($serialize, $this->data);
}

/**
* Return the potentially serialized property values
*
* @param boolean $serialize Serialize objects
* @param array $data Property values
* @return array Serialized property values
*/
protected function toSerializedArray($serialize, array $data)
{
// Filter all empty values
$data = array_filter($data);

// If the values should be serialized
if ($serialize) {
// Run through all properties
while (list($property, $value) = each($data)) {
// If the value is an array itself: Recurse
if (is_array($value)) {
$data[$property] = $this->toSerializedArray($serialize, $value);
// Else if the value is serializable
} elseif (is_object($value) &&
(new \ReflectionClass($value))->implementsInterface(SerializablePropertyInterface::class)
) {
/** @var $value SerializablePropertyInterface */
$data[$property] = $value->serialize();
}
}
}

return $data;
}
}
20 changes: 10 additions & 10 deletions src/Object/Domain/Model/Properties/SystemProperties.php
Expand Up @@ -241,6 +241,16 @@ public function __construct(array $data, ObjectInterface $object)
}
}

/**
* Return the object draft mode
*
* @return boolean Object draft mode
*/
public function isDraft()
{
return !($this->published instanceof \DateTimeInterface);
}

/**
* Return the object ID
*
Expand Down Expand Up @@ -271,16 +281,6 @@ public function getRevision()
return $this->revision;
}

/**
* Return the object draft mode
*
* @return boolean Object draft mode
*/
public function isDraft()
{
return !($this->published instanceof \DateTimeInterface);
}

/**
* Return the object publication state
*
Expand Down
13 changes: 6 additions & 7 deletions src/Object/Domain/Model/Uri/ApparatUrl.php
Expand Up @@ -48,13 +48,6 @@
*/
class ApparatUrl extends ObjectUrl
{
/**
* Valid schemes
*
* @var array
*/
protected static $schemes = [self::SCHEME_APRT => true, self::SCHEME_APRTS => true];

/**
* APRT-Schema
*
Expand All @@ -67,6 +60,12 @@ class ApparatUrl extends ObjectUrl
* @var string
*/
const SCHEME_APRTS = 'aprts';
/**
* Valid schemes
*
* @var array
*/
protected static $schemes = [self::SCHEME_APRT => true, self::SCHEME_APRTS => true];

/**
* Apparat URL constructor
Expand Down

0 comments on commit 76bf7f6

Please sign in to comment.