Move dynamic segments from Premium plugin
[MAILPOET-2382]
This commit is contained in:
committed by
Jack Kitterhing
parent
0af9f09f50
commit
70a89b7939
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace MailPoet\Premium\DynamicSegments\Persistence\Loading;
|
||||
|
||||
use MailPoet\Premium\DynamicSegments\Mappers\DBMapper;
|
||||
use MailPoet\Premium\Models\DynamicSegment;
|
||||
|
||||
class SingleSegmentLoader {
|
||||
|
||||
/** @var DBMapper */
|
||||
private $mapper;
|
||||
|
||||
public function __construct(DBMapper $mapper) {
|
||||
$this->mapper = $mapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|int $segment_id
|
||||
* @return DynamicSegment
|
||||
*/
|
||||
function load($segment_id) {
|
||||
|
||||
$segment = DynamicSegment::findOne($segment_id);
|
||||
if (!$segment instanceof DynamicSegment) {
|
||||
throw new \InvalidArgumentException('Segment not found');
|
||||
}
|
||||
|
||||
$filters = $segment->dynamicSegmentFilters()->findMany();
|
||||
|
||||
return $this->mapper->mapSegment($segment, $filters);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user