Make entity functions line up with propertyaccess.
This commit is contained in:
parent
cbe106d9ef
commit
058f306c15
|
@ -159,7 +159,7 @@ class RelaysController
|
|||
$remote->setRelay($relay);
|
||||
$remote->setType(Adapters::REMOTE_AZURARELAY);
|
||||
$remote->setDisplayName($mount->getDisplayName() . ' (' . $relay->getName() . ')');
|
||||
$remote->setIsVisibleOnPublicPages($relay->isIsVisibleOnPublicPages());
|
||||
$remote->setIsVisibleOnPublicPages($relay->getIsVisibleOnPublicPages());
|
||||
$remote->setAutodjBitrate($mount->getAutodjBitrate());
|
||||
$remote->setAutodjFormat($mount->getAutodjFormat());
|
||||
$remote->setUrl($relay->getBaseUrl());
|
||||
|
|
|
@ -175,6 +175,7 @@ class StationsController extends AbstractAdminApiCrudController
|
|||
if (!empty($data[$idKey])) {
|
||||
$data[$locationKey] = $data[$idKey];
|
||||
}
|
||||
unset($data[$idKey]);
|
||||
}
|
||||
|
||||
return parent::fromArray($data, $record, $context);
|
||||
|
|
|
@ -38,7 +38,7 @@ class ChartsAction
|
|||
$em->getRepository(Entity\Station::class)->findAll(),
|
||||
static function ($station) use ($acl) {
|
||||
/** @var Entity\Station $station */
|
||||
return $station->isEnabled() &&
|
||||
return $station->getIsEnabled() &&
|
||||
$acl->isAllowed(Acl::STATION_VIEW, $station->getId());
|
||||
}
|
||||
);
|
||||
|
|
|
@ -28,7 +28,7 @@ class StationsAction
|
|||
$em->getRepository(Entity\Station::class)->findAll(),
|
||||
static function ($station) use ($acl) {
|
||||
/** @var Entity\Station $station */
|
||||
return $station->isEnabled() &&
|
||||
return $station->getIsEnabled() &&
|
||||
$acl->isAllowed(Acl::STATION_VIEW, $station->getId());
|
||||
}
|
||||
);
|
||||
|
|
|
@ -15,7 +15,8 @@ class ToggleAction extends AbstractWebhooksAction
|
|||
{
|
||||
$record = $this->requireRecord($request->getStation(), $id);
|
||||
|
||||
$newValue = $record->toggleEnabled();
|
||||
$newValue = !$record->getIsEnabled();
|
||||
$record->setIsEnabled($newValue);
|
||||
|
||||
$this->em->persist($record);
|
||||
$this->em->flush();
|
||||
|
|
|
@ -24,7 +24,7 @@ class PlaylistAction
|
|||
$fa = $request->getStationFrontend();
|
||||
foreach ($station->getMounts() as $mount) {
|
||||
/** @var Entity\StationMount $mount */
|
||||
if (!$mount->isVisibleOnPublicPages()) {
|
||||
if (!$mount->getIsVisibleOnPublicPages()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ class PlaylistAction
|
|||
$adapter = $remote_proxy->getAdapter();
|
||||
$remote = $remote_proxy->getRemote();
|
||||
|
||||
if (!$remote->isVisibleOnPublicPages()) {
|
||||
if (!$remote->getIsVisibleOnPublicPages()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ class ProfileController
|
|||
$station = $request->getStation();
|
||||
$view = $request->getView();
|
||||
|
||||
if (!$station->isEnabled()) {
|
||||
if (!$station->getIsEnabled()) {
|
||||
return $view->renderToResponse($response, 'stations/profile/disabled');
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ class StationApiGenerator
|
|||
$mounts = [];
|
||||
if ($fa->supportsMounts() && $station->getMounts()->count() > 0) {
|
||||
foreach ($station->getMounts() as $mount) {
|
||||
if ($showAllMounts || $mount->isVisibleOnPublicPages()) {
|
||||
if ($showAllMounts || $mount->getIsVisibleOnPublicPages()) {
|
||||
$mounts[] = $mount->api($fa, $baseUri);
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ class StationApiGenerator
|
|||
$remotes = [];
|
||||
foreach ($remoteAdapters as $ra_proxy) {
|
||||
$remote = $ra_proxy->getRemote();
|
||||
if ($showAllMounts || $remote->isVisibleOnPublicPages()) {
|
||||
if ($showAllMounts || $remote->getIsVisibleOnPublicPages()) {
|
||||
$remotes[] = $remote->api($ra_proxy->getAdapter());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ class Relay implements IdentifiableEntityInterface
|
|||
$this->name = $this->truncateNullableString($name, 100);
|
||||
}
|
||||
|
||||
public function isIsVisibleOnPublicPages(): bool
|
||||
public function getIsVisibleOnPublicPages(): bool
|
||||
{
|
||||
return $this->is_visible_on_public_pages;
|
||||
}
|
||||
|
|
|
@ -286,11 +286,7 @@ class StationPlaylistMediaRepository extends Repository
|
|||
->getQuery()
|
||||
->getSingleScalarResult();
|
||||
|
||||
if ($notQueuedMediaCount === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return $notQueuedMediaCount === 0;
|
||||
}
|
||||
|
||||
public function isQueueEmpty(Entity\StationPlaylist $playlist): bool
|
||||
|
@ -312,11 +308,7 @@ class StationPlaylistMediaRepository extends Repository
|
|||
->getQuery()
|
||||
->getSingleScalarResult();
|
||||
|
||||
if ($notQueuedMediaCount === $totalMediaCount) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return $notQueuedMediaCount === $totalMediaCount;
|
||||
}
|
||||
|
||||
protected function getCountPlaylistMediaBaseQuery(Entity\StationPlaylist $playlist): QueryBuilder
|
||||
|
|
|
@ -42,7 +42,7 @@ class StationQueueRepository extends Repository
|
|||
|
||||
public function newRecordSentToAutoDj(Entity\StationQueue $queueRow): void
|
||||
{
|
||||
$queueRow->sentToAutoDj();
|
||||
$queueRow->setSentToAutodj();
|
||||
$this->em->persist($queueRow);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
|
|
@ -267,7 +267,7 @@ class SongHistory implements SongInterface, IdentifiableEntityInterface
|
|||
public function showInApis(): bool
|
||||
{
|
||||
if ($this->playlist instanceof StationPlaylist) {
|
||||
return !$this->playlist->isJingle();
|
||||
return !$this->playlist->getIsJingle();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -771,7 +771,7 @@ class Station implements Stringable, IdentifiableEntityInterface
|
|||
|
||||
public function getEnablePublicPage(): bool
|
||||
{
|
||||
return $this->enable_public_page && $this->isEnabled();
|
||||
return $this->enable_public_page && $this->getIsEnabled();
|
||||
}
|
||||
|
||||
public function setEnablePublicPage(bool $enable_public_page): void
|
||||
|
@ -799,7 +799,7 @@ class Station implements Stringable, IdentifiableEntityInterface
|
|||
$this->enable_on_demand_download = $enable_on_demand_download;
|
||||
}
|
||||
|
||||
public function isEnabled(): bool
|
||||
public function getIsEnabled(): bool
|
||||
{
|
||||
return $this->is_enabled;
|
||||
}
|
||||
|
|
|
@ -159,7 +159,7 @@ class StationMount implements
|
|||
$this->display_name = $this->truncateNullableString($display_name);
|
||||
}
|
||||
|
||||
public function isVisibleOnPublicPages(): bool
|
||||
public function getIsVisibleOnPublicPages(): bool
|
||||
{
|
||||
return $this->is_visible_on_public_pages;
|
||||
}
|
||||
|
|
|
@ -287,7 +287,7 @@ class StationPlaylist implements
|
|||
$this->is_enabled = $is_enabled;
|
||||
}
|
||||
|
||||
public function isJingle(): bool
|
||||
public function getIsJingle(): bool
|
||||
{
|
||||
return $this->is_jingle;
|
||||
}
|
||||
|
|
|
@ -136,15 +136,17 @@ class StationQueue implements SongInterface, IdentifiableEntityInterface
|
|||
$this->duration = $duration;
|
||||
}
|
||||
|
||||
public function isSentToAutoDj(): bool
|
||||
public function getSentToAutodj(): bool
|
||||
{
|
||||
return $this->sent_to_autodj;
|
||||
}
|
||||
|
||||
public function sentToAutoDj(): void
|
||||
public function setSentToAutodj(bool $newValue = true): void
|
||||
{
|
||||
if ($newValue) {
|
||||
$this->setTimestampCued(time());
|
||||
$this->sent_to_autodj = true;
|
||||
}
|
||||
$this->sent_to_autodj = $newValue;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -166,7 +168,7 @@ class StationQueue implements SongInterface, IdentifiableEntityInterface
|
|||
public function showInApis(): bool
|
||||
{
|
||||
if ($this->playlist instanceof StationPlaylist) {
|
||||
return !$this->playlist->isJingle();
|
||||
return !$this->playlist->getIsJingle();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -120,7 +120,7 @@ class StationRemote implements
|
|||
$this->relay = $relay;
|
||||
}
|
||||
|
||||
public function isVisibleOnPublicPages(): bool
|
||||
public function getIsVisibleOnPublicPages(): bool
|
||||
{
|
||||
return $this->is_visible_on_public_pages;
|
||||
}
|
||||
|
|
|
@ -154,7 +154,7 @@ class StationStreamer implements
|
|||
$this->comments = $comments;
|
||||
}
|
||||
|
||||
public function isActive(): bool
|
||||
public function getIsActive(): bool
|
||||
{
|
||||
return $this->is_active;
|
||||
}
|
||||
|
|
|
@ -128,17 +128,11 @@ class StationWebhook implements
|
|||
return $this->type;
|
||||
}
|
||||
|
||||
public function isEnabled(): bool
|
||||
public function getIsEnabled(): bool
|
||||
{
|
||||
return $this->is_enabled;
|
||||
}
|
||||
|
||||
public function toggleEnabled(): bool
|
||||
{
|
||||
$this->is_enabled = !$this->is_enabled;
|
||||
return $this->is_enabled;
|
||||
}
|
||||
|
||||
public function setIsEnabled(bool $is_enabled): void
|
||||
{
|
||||
$this->is_enabled = $is_enabled;
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Normalizer;
|
||||
|
||||
use App\Exception\NoGetterAvailableException;
|
||||
|
@ -10,12 +8,9 @@ use Doctrine\Common\Collections\Collection;
|
|||
use Doctrine\Inflector\Inflector;
|
||||
use Doctrine\Inflector\InflectorFactory;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Proxy\Proxy;
|
||||
use Doctrine\Persistence\Proxy;
|
||||
use ProxyManager\Proxy\GhostObjectInterface;
|
||||
use ReflectionClass;
|
||||
use ReflectionMethod;
|
||||
use ReflectionNamedType;
|
||||
use ReflectionParameter;
|
||||
use ReflectionProperty;
|
||||
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;
|
||||
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
|
||||
|
@ -356,85 +351,14 @@ class DoctrineEntityNormalizer extends AbstractNormalizer implements NormalizerA
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object $entity
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
*
|
||||
*/
|
||||
protected function setProperty(object $entity, string $key, mixed $value): mixed
|
||||
protected function setProperty(object $entity, string $key, mixed $value): void
|
||||
{
|
||||
$method_name = $this->getMethodName($key, 'set');
|
||||
|
||||
if (!method_exists($entity, $method_name)) {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
$method = new ReflectionMethod(get_class($entity), $method_name);
|
||||
$firstParam = $method->getParameters()[0];
|
||||
|
||||
$value = $this->castValue($firstParam, $value);
|
||||
return $entity->$method_name($value);
|
||||
}
|
||||
|
||||
protected function castValue(ReflectionParameter $firstParam, mixed $value): mixed
|
||||
{
|
||||
if (!$firstParam->hasType()) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$firstParamTypeObj = $firstParam->getType();
|
||||
|
||||
if (
|
||||
!($firstParamTypeObj instanceof ReflectionNamedType)
|
||||
|| !$firstParamTypeObj->isBuiltin()
|
||||
) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
switch ($firstParamTypeObj->getName()) {
|
||||
case 'string':
|
||||
if ($value === null) {
|
||||
if (!$firstParam->allowsNull()) {
|
||||
return '';
|
||||
}
|
||||
} else {
|
||||
return (string)$value;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'int':
|
||||
if ($value === null) {
|
||||
if (!$firstParam->allowsNull()) {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return (int)$value;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'float':
|
||||
if ($value === null) {
|
||||
if (!$firstParam->allowsNull()) {
|
||||
return 0.0;
|
||||
}
|
||||
} else {
|
||||
return (float)$value;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'bool':
|
||||
if ($value === null) {
|
||||
if (!$firstParam->allowsNull()) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return (bool)$value;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return $value;
|
||||
$entity->$method_name($value);
|
||||
}
|
||||
|
||||
protected function isEntity(mixed $class): bool
|
||||
|
@ -445,11 +369,7 @@ class DoctrineEntityNormalizer extends AbstractNormalizer implements NormalizerA
|
|||
: get_class($class);
|
||||
}
|
||||
|
||||
if (!is_string($class)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!class_exists($class)) {
|
||||
if (!is_string($class) || !class_exists($class)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -121,7 +121,7 @@ abstract class AbstractAdapter
|
|||
*/
|
||||
public function hasCommand(Entity\Station $station): bool
|
||||
{
|
||||
if ($this->environment->isTesting() || !$station->isEnabled()) {
|
||||
if ($this->environment->isTesting() || !$station->getIsEnabled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ class Annotations implements EventSubscriberInterface
|
|||
$playlist = $event->getPlaylist();
|
||||
if ($playlist instanceof Entity\StationPlaylist) {
|
||||
// Handle "Jingle mode" by sending the same metadata as the previous song.
|
||||
if ($playlist->isJingle()) {
|
||||
if ($playlist->getIsJingle()) {
|
||||
$event->addAnnotations([
|
||||
'jingle_mode' => 'true',
|
||||
]);
|
||||
|
|
|
@ -304,7 +304,7 @@ class ConfigWriter implements EventSubscriberInterface
|
|||
$playlistConfigLines[] = $playlistVarName . ' = cue_cut(id="cue_'
|
||||
. self::cleanUpString($playlistVarName) . '", ' . $playlistVarName . ')';
|
||||
|
||||
if ($playlist->isJingle()) {
|
||||
if ($playlist->getIsJingle()) {
|
||||
$playlistConfigLines[] = $playlistVarName . ' = drop_metadata(' . $playlistVarName . ')';
|
||||
}
|
||||
|
||||
|
@ -569,7 +569,7 @@ class ConfigWriter implements EventSubscriberInterface
|
|||
$mediaFilePath = $mediaBaseDir . $mediaFile->getPath();
|
||||
$mediaAnnotations = $this->liquidsoap->annotateMedia($mediaFile);
|
||||
|
||||
if ($playlist->isJingle()) {
|
||||
if ($playlist->getIsJingle()) {
|
||||
$mediaAnnotations['is_jingle_mode'] = 'true';
|
||||
unset($mediaAnnotations['media_id']);
|
||||
} else {
|
||||
|
|
|
@ -86,7 +86,7 @@ class Configuration
|
|||
$supervisorConfig = [];
|
||||
$supervisorConfigFile = $this->getSupervisorConfigFile($station);
|
||||
|
||||
if (!$station->isEnabled()) {
|
||||
if (!$station->getIsEnabled()) {
|
||||
@unlink($supervisorConfigFile);
|
||||
$this->reloadSupervisorForStation($station);
|
||||
return;
|
||||
|
|
|
@ -179,7 +179,7 @@ class Icecast extends AbstractFrontend
|
|||
$mount['genre'] = $station->getGenre();
|
||||
}
|
||||
|
||||
if (!$mount_row->isVisibleOnPublicPages()) {
|
||||
if (!$mount_row->getIsVisibleOnPublicPages()) {
|
||||
$mount['hidden'] = 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ class CheckRequests extends AbstractTask
|
|||
// Log the item in SongHistory.
|
||||
$sq = Entity\StationQueue::fromRequest($request);
|
||||
$sq->setTimestampCued(time());
|
||||
$sq->sentToAutodj();
|
||||
$sq->setSentToAutodj();
|
||||
|
||||
$this->em->persist($sq);
|
||||
$this->em->flush();
|
||||
|
|
|
@ -82,7 +82,7 @@ class NowPlayingTask extends AbstractTask implements EventSubscriberInterface
|
|||
$nowplaying = [];
|
||||
|
||||
foreach ($this->iterateStations() as $station) {
|
||||
if (!$station->isEnabled()) {
|
||||
if (!$station->getIsEnabled()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -220,7 +220,7 @@ class NowPlayingTask extends AbstractTask implements EventSubscriberInterface
|
|||
}
|
||||
}
|
||||
|
||||
$sq->sentToAutodj();
|
||||
$sq->setSentToAutodj();
|
||||
|
||||
$this->em->persist($sq);
|
||||
$this->em->flush();
|
||||
|
|
|
@ -57,7 +57,7 @@ class Dispatcher
|
|||
/** @var Entity\StationWebhook[] $enabledWebhooks */
|
||||
$enabledWebhooks = $station->getWebhooks()->filter(
|
||||
function (Entity\StationWebhook $webhook) {
|
||||
return $webhook->isEnabled();
|
||||
return $webhook->getIsEnabled();
|
||||
}
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue