Skip to content

Commit

Permalink
Adding Wrapper object to avoid using Array, this object implements Ar…
Browse files Browse the repository at this point in the history
…rayAccess it should not break anything
  • Loading branch information
Plopix committed Aug 25, 2015
1 parent 0648faa commit d25aa36
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Core/Helper/eZ/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected function wrapResults( $results, $limit )
{
$location = $hit->valueObject;
$content = $this->repository->getContentService()->loadContentByContentInfo( $location->contentInfo );
$contentResults->addResult( [ 'content' => $content, 'location' => $location ] );
$contentResults->addResult( new Wrapper( $content, $location ) );
}
return $contentResults;
}
Expand Down
10 changes: 6 additions & 4 deletions Core/Helper/eZ/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ function () use ( $structure )
$searchResults = $searchResults['results'];
foreach ( $searchResults as $result )
{
$item = array();
$item['content'] = $this->repository->getContentService()->loadContent( $result->ContentObject->ID );
$item['location'] = $this->repository->getLocationService()->loadLocation( $result->NodeID );
$contentResults->addResult( $item );
$contentResults->addResult(
new Wrapper(
$this->repository->getContentService()->loadContent( $result->ContentObject->ID ),
$this->repository->getLocationService()->loadLocation( $result->NodeID )
)
);
}

return $contentResults;
Expand Down
113 changes: 113 additions & 0 deletions Core/Helper/eZ/Wrapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php
/**
* NovaeZExtraBundle Wrapper
*
* @package Novactive\Bundle\eZExtraBundle
* @author Novactive <[email protected]>
* @copyright 2015 Novactive
* @license https://github.com/Novactive/NovaeZSEOBundle/blob/master/LICENSE MIT Licence
*/

namespace Novactive\Bundle\eZExtraBundle\Core\Helper\eZ;

use eZ\Publish\API\Repository\Exceptions\PropertyNotFoundException;
use eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException;
use eZ\Publish\API\Repository\Values\Content\Content as ValueContent;
use eZ\Publish\API\Repository\Values\Content\Location as ValueLocation;

/**
* Class Wrapper
*/
class Wrapper implements \ArrayAccess
{
/**
* The Content
*
* @var ValueContent
*/
public $content;

/**
* The Location
*
* @var ValueLocation
*/
public $location;

/**
* Constructor
*
* @param ValueContent $content
* @param ValueLocation $location
*/
public function __construct( ValueContent $content, ValueLocation $location )
{
$this->content = $content;
$this->location = $location;
}

/**
* Getter
*
* @param string $name
*
* @return ValueContent|ValueLocation
* @throws PropertyNotFoundException
*/
public function __get( $name )
{
if ( property_exists( $this, $name ) )
{
return $this->$name;
}
throw new PropertyNotFoundException( "Can't find property: " . __CLASS__ . "->{$name}" );
}

/**
* Setter
*
* @param string $name
* @param mixed $value
*
* @throws PropertyReadOnlyException
*/
public function __set( $name, $value )
{
throw new PropertyReadOnlyException( "Can't set property: " . __CLASS__ . "->{$name}" );
}

/**
* {@inheritdoc}
*/
public function offsetExists( $offset )
{
return property_exists( $this, $offset );
}

/**
* {@inheritdoc}
*/
public function offsetGet( $offset )
{
if ( property_exists( $this, $offset ) )
{
return $this->$offset;
}
}

/**
* {@inheritdoc}
*/
public function offsetSet( $offset, $value )
{
throw new PropertyReadOnlyException( "Can't set property: " . __CLASS__ . "[{$offset}]" );
}

/**
* {@inheritdoc}
*/
public function offsetUnset( $offset )
{
throw new PropertyReadOnlyException( "Can't unset property: " . __CLASS__ . "[{$offset}]" );
}
}

0 comments on commit d25aa36

Please sign in to comment.