mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-11 03:53:13 +00:00
57 lines
1.1 KiB
PHP
57 lines
1.1 KiB
PHP
<?php
|
|
/*
|
|
* This file is part of Phraseanet
|
|
*
|
|
* (c) 2005-2016 Alchemy
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Alchemy\Phrasea\Search;
|
|
|
|
use Assert\Assertion;
|
|
|
|
trait SubdefsAware
|
|
{
|
|
/**
|
|
* @var SubdefView[]
|
|
*/
|
|
private $subdefs = [];
|
|
|
|
/**
|
|
* @param SubdefView[] $subdefs
|
|
*/
|
|
public function setSubdefs($subdefs)
|
|
{
|
|
Assertion::allIsInstanceOf($subdefs, SubdefView::class);
|
|
|
|
$this->subdefs = [];
|
|
|
|
foreach ($subdefs as $subdef) {
|
|
$this->subdefs[$subdef->getSubdef()->get_name()] = $subdef;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param string $name
|
|
* @return SubdefView
|
|
*/
|
|
public function getSubdef($name)
|
|
{
|
|
if (isset($this->subdefs[$name])) {
|
|
return $this->subdefs[$name];
|
|
}
|
|
|
|
throw new \OutOfBoundsException(sprintf('There are no subdef named "%s"', $name));
|
|
}
|
|
|
|
/**
|
|
* @return SubdefView
|
|
*/
|
|
public function getSubdefs()
|
|
{
|
|
return $this->subdefs;
|
|
}
|
|
}
|