repo
stringlengths
7
63
file_url
stringlengths
81
284
file_path
stringlengths
5
200
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:02:33
2026-01-05 05:24:06
truncated
bool
2 classes
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Application/Webservice/ContactGroupsWebservice.php
centreon/src/Centreon/Application/Webservice/ContactGroupsWebservice.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ namespace Centreon\Application\Webservice; use Centreon\Application\DataRepresenter\Response; use Centreon\Application\Serializer; use Centreon\Domain\Repository\ContactGroupRepository; use Centreon\Infrastructure\Webservice; use Centreon\ServiceProvider; /** * @OA\Tag(name="centreon_contact_groups", description="Web Service for Contact Groups") */ class ContactGroupsWebservice extends Webservice\WebServiceAbstract implements Webservice\WebserviceAutorizeRestApiInterface { use Webservice\DependenciesTrait; /** * {@inheritDoc} */ public static function getName(): string { return 'centreon_contact_groups'; } /** * {@inheritDoc} */ public static function dependencies(): array { return [ ServiceProvider::CENTREON_PAGINATION, ]; } /** * @OA\Get( * path="/internal.php?object=centreon_contact_groups&action=list", * description="Get contact groups list", * tags={"centreon_contact_groups"}, * security={{"Session": {}}}, * @OA\Parameter( * in="query", * name="object", * @OA\Schema( * type="string", * enum={"centreon_contact_groups"}, * default="centreon_contact_groups" * ), * description="the name of the API object class", * required=true * ), * @OA\Parameter( * in="query", * name="action", * @OA\Schema( * type="string", * enum={"list"}, * default="list" * ), * description="the name of the action in the API class", * required=true * ), * @OA\Parameter( * in="query", * name="name", * @OA\Schema( * type="string" * ), * description="filter the list by name", * required=false * ), * @OA\Parameter( * in="query", * name="id", * @OA\Schema( * type="string" * ), * description="filter the list by id", * required=false * ), * @OA\Parameter( * in="query", * name="offset", * @OA\Schema( * type="integer" * ), * description="offset", * required=false * ), * @OA\Parameter( * in="query", * name="limit", * @OA\Schema( * type="integer" * ), * description="limit", * required=false * ), * @OA\Response( * response="200", * description="OK", * @OA\JsonContent( * @OA\Property( * property="entities", * type="array", * @OA\Items(ref="#/components/schemas/ImageEntity") * ), * @OA\Property( * property="pagination", * ref="#/components/schemas/Pagination" * ) * ) * ) * ) * * Get contact groups list * * @throws \RestBadRequestException * @return Response */ public function getList(): Response { // process request $request = $this->query(); $limit = isset($request['limit']) ? (int) $request['limit'] : null; $offset = isset($request['offset']) ? (int) $request['offset'] : null; $sortField = $request['sortf'] ?? null; $sortOrder = $request['sorto'] ?? 'ASC'; $filters = []; if (isset($request['search']) && $request['search']) { $filters['search'] = $request['search']; } if (isset($request['searchByIds']) && $request['searchByIds']) { $filters['ids'] = explode(',', $request['searchByIds']); } $pagination = $this->services->get(ServiceProvider::CENTREON_PAGINATION); $pagination->setRepository(ContactGroupRepository::class); $pagination->setContext(Serializer\ContactGroup\ListContext::context()); $pagination->setFilters($filters); $pagination->setLimit($limit); $pagination->setOffset($offset); $pagination->setOrder($sortField, $sortOrder); return $pagination->getResponse(); } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Application/Webservice/TopologyWebservice.php
centreon/src/Centreon/Application/Webservice/TopologyWebservice.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ namespace Centreon\Application\Webservice; use App\Kernel; use Centreon\Application\DataRepresenter\Response; use Centreon\Application\DataRepresenter\Topology\NavigationList; use Centreon\Domain\Entity\Topology; use Centreon\Domain\Repository\TopologyRepository; use Centreon\Infrastructure\Webservice; use Centreon\ServiceProvider; use Core\Common\Infrastructure\FeatureFlags; use OpenApi\Annotations as OA; /** * @OA\Tag(name="centreon_topology", description="Web Service for Topology") */ class TopologyWebservice extends Webservice\WebServiceAbstract implements Webservice\WebserviceAutorizePublicInterface { /** @var int */ private const POLLER_PAGE = 60901; private ?FeatureFlags $featureFlags = null; /** * @throws \Exception */ public function __construct() { $featureFlags = Kernel::createForWeb()->getContainer()->get(FeatureFlags::class); parent::__construct(); if (! ($featureFlags instanceof FeatureFlags)) { throw new \Exception('Unable to retrieve the FeatureFlags service'); } $this->featureFlags = $featureFlags; } /** * List of required services * * @return array */ public static function dependencies(): array { return [ ServiceProvider::CENTREON_DB_MANAGER, ]; } /** * Name of web service object * * @return string */ public static function getName(): string { return 'centreon_topology'; } /** * @OA\Get( * path="/internal.php?object=centreon_topology&action=getTopologyByPage", * description="Get topology object by page id", * tags={"centreon_topology"}, * @OA\Parameter( * in="query", * name="object", * @OA\Schema( * type="string", * enum={"centreon_topology"}, * default="centreon_topology" * ), * description="the name of the API object class", * required=true * ), * @OA\Parameter( * in="query", * name="action", * @OA\Schema( * type="string", * enum={"getTopologyByPage"}, * default="getTopologyByPage" * ), * description="the name of the action in the API class", * required=true * ), * @OA\Parameter( * in="query", * name="topology_page", * @OA\Schema( * type="string" * ), * description="Page ID for topology", * required=false * ), * ) * @throws \RestBadRequestException * @return array */ public function getGetTopologyByPage(): array { if (! isset($_GET['topology_page']) || ! $_GET['topology_page']) { throw new \RestBadRequestException('You need to send \'topology_page\' in the request.'); } $topologyID = (int) $_GET['topology_page']; $statement = $this->pearDB->prepare('SELECT * FROM `topology` WHERE `topology_page` = :id'); $statement->execute([':id' => $topologyID]); $result = $statement->fetch(); if (! $result) { throw new \RestBadRequestException('No topology found.'); } return $result; } /** * @OA\Get( * path="/internal.php?object=centreon_topology&action=navigationList", * description="Get list of menu items by acl", * tags={"centreon_topology"}, * @OA\Parameter( * in="query", * name="object", * @OA\Schema( * type="string", * enum={"centreon_topology"}, * default="centreon_topology" * ), * description="the name of the API object class", * required=true * ), * @OA\Parameter( * in="query", * name="action", * @OA\Schema( * type="string", * enum={"navigationList"}, * default="navigationList" * ), * description="the name of the action in the API class", * required=true * ), * @OA\Parameter( * in="query", * name="reactOnly", * @OA\Schema( * type="integer" * ), * description="fetch react only list(value 1) or full list", * required=false * ), * @OA\Parameter( * in="query", * name="forActive", * @OA\Schema( * type="integer" * ), * description="represent values for active check", * required=false * ) * ) * @throws \RestBadRequestException */ public function getNavigationList() { $user = $this->getDi()[ServiceProvider::CENTREON_USER]; if (empty($user)) { throw new \RestBadRequestException('User not found in session. Please relog.'); } /** @var TopologyRepository $repoTopology */ $repoTopology = $this->getDi()[ServiceProvider::CENTREON_DB_MANAGER] ->getRepository(TopologyRepository::class); $dbResult = $repoTopology->getTopologyList($user); if ($this->isPollerWizardAccessible($user)) { $dbResult[] = $this->createPollerWizardTopology(); } /** @var array<array{name: string, color: string, icon: string}> $navConfig */ $navConfig = $this->getDi()[ServiceProvider::YML_CONFIG]['navigation']; $enabledFeatureFlags = $this->featureFlags?->getEnabled() ?? []; $result = new NavigationList($dbResult, $navConfig, $enabledFeatureFlags); return new Response($result, true); } /** * @param \CentreonUser $user * @return bool */ private function isPollerWizardAccessible(\CentreonUser $user): bool { $userTopologyAccess = $user->access->getTopology(); return isset($userTopologyAccess[self::POLLER_PAGE]) && (int) $userTopologyAccess[self::POLLER_PAGE] === \CentreonACL::ACL_ACCESS_READ_WRITE; } /** * @return Topology */ private function createPollerWizardTopology(): Topology { $topology = new Topology(); $topology->setTopologyUrl('/poller-wizard/1'); $topology->setTopologyPage('60959'); $topology->setTopologyParent(self::POLLER_PAGE); $topology->setTopologyName('Poller Wizard Page'); $topology->setTopologyShow('0'); $topology->setIsReact('1'); return $topology; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Application/Webservice/AclGroupWebservice.php
centreon/src/Centreon/Application/Webservice/AclGroupWebservice.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ namespace Centreon\Application\Webservice; use Centreon\Application\DataRepresenter; use Centreon\Application\Serializer; use Centreon\Domain\Repository\AclGroupRepository; use Centreon\Infrastructure\Webservice; use Centreon\ServiceProvider; /** * @OA\Tag(name="centreon_acl_group", description="Web Service for ACL Groups") */ class AclGroupWebservice extends Webservice\WebServiceAbstract implements Webservice\WebserviceAutorizeRestApiInterface { use Webservice\DependenciesTrait; /** * {@inheritDoc} */ public static function getName(): string { return 'centreon_acl_group'; } /** * {@inheritDoc} * @return array<int,string> */ public static function dependencies(): array { return [ ServiceProvider::CENTREON_PAGINATION, ]; } /** * @OA\Get( * path="/internal.php?object=centreon_acl_group&action=list", * description="Get a list of ACL groups", * tags={"centreon_acl_group"}, * security={{"Session": {}}}, * @OA\Parameter( * in="query", * name="object", * @OA\Schema( * type="string", * enum={"centreon_acl_group"}, * default="centreon_acl_group" * ), * description="the name of the API object class", * required=true * ), * @OA\Parameter( * in="query", * name="action", * @OA\Schema( * type="string", * enum={"list"}, * default="list" * ), * description="the name of the action in the API class", * required=true * ), * @OA\Parameter( * in="query", * name="name", * @OA\Schema( * type="string" * ), * description="filter the list by name", * required=false * ), * @OA\Parameter( * in="query", * name="id", * @OA\Schema( * type="string" * ), * description="filter the list by id", * required=false * ), * @OA\Parameter( * in="query", * name="offset", * @OA\Schema( * type="integer" * ), * description="offset", * required=false * ), * @OA\Parameter( * in="query", * name="limit", * @OA\Schema( * type="integer" * ), * description="limit", * required=false * ), * @OA\Response( * response="200", * description="OK", * @OA\JsonContent( * @OA\Property( * property="entities", * type="array", * @OA\Items(ref="#/components/schemas/AclGroupEntity") * ), * @OA\Property( * property="pagination", * ref="#/components/schemas/Pagination" * ) * ) * ) * ) * * Get a list of ACL groups * * @throws \RestBadRequestException * @return DataRepresenter\Response */ public function getList(): DataRepresenter\Response { // process request $request = $this->query(); $limit = isset($request['limit']) ? (int) $request['limit'] : null; $offset = isset($request['offset']) ? (int) $request['offset'] : null; $filters = []; if (isset($request['search']) && $request['search']) { $filters['search'] = $request['search']; } if (isset($request['searchByIds']) && $request['searchByIds']) { $filters['ids'] = explode(',', $request['searchByIds']); } $pagination = $this->services->get(ServiceProvider::CENTREON_PAGINATION); $pagination->setRepository(AclGroupRepository::class); $pagination->setContext(Serializer\AclGroup\ListContext::context()); $pagination->setFilters($filters); $pagination->setLimit($limit); $pagination->setOffset($offset); return $pagination->getResponse(); } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Application/Webservice/CentreonI18n.php
centreon/src/Centreon/Application/Webservice/CentreonI18n.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ namespace Centreon\Application\Webservice; use Centreon\Infrastructure\Webservice; use Centreon\ServiceProvider; use Pimple\Container; use Pimple\Psr11\ServiceLocator; /** * Webservice that allow to retrieve all translations in one json file. * If the file doesn't exist it will be created at the first reading. */ class CentreonI18n extends Webservice\WebServiceAbstract implements Webservice\WebserviceAutorizePublicInterface { private ?ServiceLocator $services = null; /** * Name of web service object * * @return string */ public static function getName(): string { return 'centreon_i18n'; } /** * Return a table containing all the translations for a language. * * @throws \Exception * @return array */ public function getTranslation(): array { try { $translation = $this->services ->get(ServiceProvider::CENTREON_I18N_SERVICE) ->getTranslation(); } catch (\Exception) { throw new \Exception('Translation files does not exists'); } return $translation; } /** * Return a table containing all the translations from all languages. * * @throws \Exception * @return array */ public function getAllTranslations(): array { try { $translation = $this->services ->get(ServiceProvider::CENTREON_I18N_SERVICE) ->getAllTranslations(); } catch (\Exception) { throw new \Exception('Translation files does not exists'); } return $translation; } /** * Extract services that are in use only * * @param Container $di */ public function setDi(Container $di): void { $this->services = new ServiceLocator($di, [ ServiceProvider::CENTREON_I18N_SERVICE, ]); } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Application/Webservice/CentreonFrontendComponent.php
centreon/src/Centreon/Application/Webservice/CentreonFrontendComponent.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ namespace Centreon\Application\Webservice; use Centreon\Infrastructure\Webservice; use Centreon\Infrastructure\Webservice\WebserviceAutorizePublicInterface; use Centreon\ServiceProvider; use Pimple\Container; use Pimple\Psr11\ServiceLocator; class CentreonFrontendComponent extends Webservice\WebServiceAbstract implements WebserviceAutorizePublicInterface { /** @var \Psr\Container\ContainerInterface */ protected $services; /** * Name of web service object * * @return string */ public static function getName(): string { return 'centreon_frontend_component'; } /** * @SWG\Get( * path="/centreon/api/internal.php", * operationId="getComponents", * @SWG\Parameter( * in="query", * name="object", * type="string", * description="the name of the API object class", * required=true, * enum="centreon_configuration_remote", * ), * @SWG\Parameter( * in="query", * name="action", * type="string", * description="the name of the action in the API class", * required=true, * enum="components", * ), * @SWG\Response( * response=200, * description="JSON with the external react components (pages, hooks)" * ) * ) * * Get list with remote components * * @return array * @example [ * ['pages' => [ * '/my/module/route' => [ * 'js' => '<my_module_path>/static/pages/my/module/route/index.js', * 'css' => '<my_module_path>/static/pages/my/module/route/index.css' * ] * ]], * ['hooks' => [ * '/header/topCounter' => [ * [ * 'js' => '<my_module_path>/static/hooks/header/topCounter/index.js', * 'css' => '<my_module_path>/static/hooks/header/topCounter/index.css' * ] * ] * ]] * ] */ public function getComponents(): array { $service = $this->services->get(ServiceProvider::CENTREON_FRONTEND_COMPONENT_SERVICE); return [ 'pages' => $service->getPages(), 'hooks' => $service->getHooks(), ]; } /** * Extract services that are in use only * * @param Container $di */ public function setDi(Container $di): void { $this->services = new ServiceLocator($di, [ ServiceProvider::CENTREON_FRONTEND_COMPONENT_SERVICE, ]); } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Application/Serializer/SerializerContextInterface.php
centreon/src/Centreon/Application/Serializer/SerializerContextInterface.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ namespace Centreon\Application\Serializer; /** * Context interface for serializes and deserializes data. */ interface SerializerContextInterface { public const GROUPS = 'groups'; /** * Options that normalizers/encoders have access to * * @see https://symfony.com/doc/current/components/serializer.html * @return array<string,string[]> */ public static function context(): array; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Application/Serializer/AclGroup/ListContext.php
centreon/src/Centreon/Application/Serializer/AclGroup/ListContext.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ namespace Centreon\Application\Serializer\AclGroup; use Centreon\Application\Serializer\SerializerContextInterface; use Centreon\Domain\Entity\AclGroup; /** * @OA\Schema( * schema="AclGroupEntity", * @OA\Property(property="id", type="integer"), * @OA\Property(property="name", type="string"), * @OA\Property(property="alias", type="string"), * @OA\Property(property="changed", type="integer"), * @OA\Property(property="activate", type="string", enum={"0","1","2"}) * ) * * Serialize AclGroup entity for list */ class ListContext implements SerializerContextInterface { /** * {@inheritDoc} */ public static function context(): array { return [ static::GROUPS => [ AclGroup::SERIALIZER_GROUP_LIST, ], ]; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Application/Serializer/ContactGroup/ListContext.php
centreon/src/Centreon/Application/Serializer/ContactGroup/ListContext.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ namespace Centreon\Application\Serializer\ContactGroup; use Centreon\Application\Serializer\SerializerContextInterface; use Centreon\Domain\Entity\ContactGroup; /** * @OA\Schema( * schema="ContactGroup", * @OA\Property(property="id", type="integer"), * @OA\Property(property="name", type="string"), * @OA\Property(property="activate", type="integer") * ) * * Serialize ContactGroup entity for list */ class ListContext implements SerializerContextInterface { /** * {@inheritDoc} */ public static function context(): array { return [ static::GROUPS => [ ContactGroup::SERIALIZER_GROUP_LIST, ], ]; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Application/Serializer/Image/ListContext.php
centreon/src/Centreon/Application/Serializer/Image/ListContext.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ namespace Centreon\Application\Serializer\Image; use Centreon\Application\Serializer\SerializerContextInterface; use Centreon\Domain\Entity\Image; /** * @OA\Schema( * schema="ImageEntity", * @OA\Property(property="id", type="integer"), * @OA\Property(property="name", type="string"), * @OA\Property(property="preview", type="string"), * ) * * Serialize Image entity for list */ class ListContext implements SerializerContextInterface { /** * {@inheritDoc} */ public static function context(): array { return [ static::GROUPS => [ Image::SERIALIZER_GROUP_LIST, ], ]; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Application/Validation/CentreonValidatorTranslator.php
centreon/src/Centreon/Application/Validation/CentreonValidatorTranslator.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ namespace Centreon\Application\Validation; use Symfony\Contracts\Translation\TranslatorInterface; class CentreonValidatorTranslator implements TranslatorInterface { public function __construct(readonly private \CentreonUser $contact) { } /** * {@inheritDoc} */ public function trans($id, array $parameters = [], $domain = null, $locale = null): string { $message = gettext($id); foreach ($parameters as $key => $val) { $message = str_replace($key, $val, $message); } return $message; } /** * @codeCoverageIgnore * {@inheritDoc} */ public function getLocale(): string { return $this->contact->get_lang(); } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Application/Validation/CentreonValidatorFactory.php
centreon/src/Centreon/Application/Validation/CentreonValidatorFactory.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ namespace Centreon\Application\Validation; use Centreon\Application\Validation\Validator\Interfaces\CentreonValidatorInterface; use Pimple\Container; use Pimple\Psr11\ServiceLocator; use ReflectionClass; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidatorFactoryInterface; use Symfony\Component\Validator\ConstraintValidatorInterface; class CentreonValidatorFactory implements ConstraintValidatorFactoryInterface { /** @var Container */ protected $container; /** @var array */ protected $validators = []; /** * Construct * * @param Container $container */ public function __construct(Container $container) { $this->container = $container; } /** * {@inheritDoc} */ public function getInstance(Constraint $constraint): ConstraintValidatorInterface { $className = $constraint->validatedBy(); if (! isset($this->validators[$className])) { if (class_exists($className)) { // validator as a class with dependencies from centreon $reflection = (new ReflectionClass($className)); if ($reflection->implementsInterface(CentreonValidatorInterface::class)) { $this->validators[$className] = new $className(new ServiceLocator( $this->container, $reflection->hasMethod('dependencies') ? $className::dependencies() : [] )); } else { // validator as a class with empty property accessor $this->validators[$className] = new $className(); } } elseif (in_array($className, $this->container->keys())) { // validator as a service $this->validators[$className] = $this->container[$className]; } else { throw new \RuntimeException(sprintf(_('The validator "%s" is not found'), $className)); } } return $this->validators[$className]; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Application/Validation/Constraints/RepositoryCallback.php
centreon/src/Centreon/Application/Validation/Constraints/RepositoryCallback.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ namespace Centreon\Application\Validation\Constraints; use Centreon\Application\Validation\Validator\RepositoryCallbackValidator; use Symfony\Component\Validator\Constraint; class RepositoryCallback extends Constraint { public const NOT_VALID_REPO_CALLBACK = '13bd9dbf-6b9b-41cd-a99e-4844bcf3077z'; /** * @var array<string,string> */ protected const ERROR_NAMES = [ self::NOT_VALID_REPO_CALLBACK => 'NOT_VALID_REPO_CALLBACK', ]; /** @var string|null */ public $fieldAccessor = null; /** @var string|null */ public $repoMethod = null; /** @var string|null */ public $repository = null; /** @var string */ public $fields = ''; /** @var string */ public $message = 'Does not satisfy validation callback. Check Repository.'; /** * {@inheritDoc} */ public function validatedBy(): string { return RepositoryCallbackValidator::class; } /** * {@inheritDoc} */ public function getTargets(): string|array { return self::CLASS_CONSTRAINT; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Application/Validation/Constraints/UniqueEntity.php
centreon/src/Centreon/Application/Validation/Constraints/UniqueEntity.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ namespace Centreon\Application\Validation\Constraints; use Centreon\Application\Validation\Validator\UniqueEntityValidator; use Symfony\Component\Validator\Constraint; class UniqueEntity extends Constraint { public const NOT_UNIQUE_ERROR = '23bd9dbf-6b9b-41cd-a99e-4844bcf3077c'; /** * @var array<string, string> */ protected const ERROR_NAMES = [ self::NOT_UNIQUE_ERROR => 'NOT_UNIQUE_ERROR', ]; /** @var string */ public string $validatorClass = UniqueEntityValidator::class; /** @var string */ public $message = 'This value is already used.'; /** @var string */ public $entityIdentificatorMethod = 'getId'; /** @var string */ public $entityIdentificatorColumn = 'id'; /** @var mixed */ public $repository = null; /** @var string */ public $repositoryMethod = 'findOneBy'; /** @var array<mixed> */ public $fields = []; /** @var string|null */ public $errorPath = null; /** @var bool */ public $ignoreNull = true; /** * {@inheritDoc} */ public function getTargets(): string|array { return self::CLASS_CONSTRAINT; } /** * @return string */ public function getDefaultOption(): string { return 'fields'; } /** * The validator class name. * * @return string */ public function validatedBy(): string { return $this->validatorClass; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Application/Validation/Validator/UniqueEntityValidator.php
centreon/src/Centreon/Application/Validation/Validator/UniqueEntityValidator.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ namespace Centreon\Application\Validation\Validator; use App\Kernel; use Centreon\Application\Validation\Constraints\UniqueEntity; use Centreon\Application\Validation\Validator\Interfaces\CentreonValidatorInterface; use Centreon\ServiceProvider; use LogicException; use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException; use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; use Symfony\Component\Validator\Exception\ConstraintDefinitionException; use Symfony\Component\Validator\Exception\UnexpectedTypeException; use function is_array; use function is_string; class UniqueEntityValidator extends ConstraintValidator implements CentreonValidatorInterface { /** * @param $entity * @param Constraint $constraint * * @throws ConstraintDefinitionException * @throws UnexpectedTypeException * @throws LogicException * @throws ServiceCircularReferenceException * @throws ServiceNotFoundException * @return void|null */ public function validate($entity, Constraint $constraint) { if (! $constraint instanceof UniqueEntity) { throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\UniqueEntity'); } if (! is_array($constraint->fields) && ! is_string($constraint->fields)) { throw new UnexpectedTypeException($constraint->fields, 'array'); } if ($constraint->errorPath !== null && ! is_string($constraint->errorPath)) { throw new UnexpectedTypeException($constraint->errorPath, 'string or null'); } // define fields to check $fields = (array) $constraint->fields; $methodRepository = $constraint->repositoryMethod; $methodIdGetter = $constraint->entityIdentificatorMethod; if ($fields === []) { throw new ConstraintDefinitionException('At least one field has to be specified.'); } if ($entity === null) { return null; } foreach ($fields as $field) { $methodValueGetter = 'get' . ucfirst($field); $value = $entity->{$methodValueGetter}(); $repository = (Kernel::createForWeb()) ->getContainer() ->get($constraint->repository); $result = $repository->{$methodRepository}([$field => $value]); if ($result && $result->{$methodIdGetter}() !== $entity->{$methodIdGetter}()) { $this->context->buildViolation($constraint->message) ->atPath($field) ->setInvalidValue($value) ->setCode(UniqueEntity::NOT_UNIQUE_ERROR) ->setCause($result) ->addViolation(); } } } /** * List of required services * * @return array */ public static function dependencies(): array { return [ ServiceProvider::CENTREON_DB_MANAGER, ]; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Application/Validation/Validator/RepositoryCallbackValidator.php
centreon/src/Centreon/Application/Validation/Validator/RepositoryCallbackValidator.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ namespace Centreon\Application\Validation\Validator; use App\Kernel; use Centreon\Application\Validation\Constraints\RepositoryCallback; use Centreon\Application\Validation\Validator\Interfaces\CentreonValidatorInterface; use Centreon\ServiceProvider; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\Constraints\CallbackValidator; use Symfony\Component\Validator\Exception\ConstraintDefinitionException; use Symfony\Component\Validator\Exception\UnexpectedTypeException; class RepositoryCallbackValidator extends CallbackValidator implements CentreonValidatorInterface { /** * {@inheritDoc} * @return void */ public function validate($object, Constraint $constraint): void { if (! $constraint instanceof RepositoryCallback) { throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\RepositoryCallback'); } $method = $constraint->repoMethod; $repository = (Kernel::createForWeb()) ->getContainer() ->get($constraint->repository); $fieldAccessor = $constraint->fieldAccessor; $value = $object->{$fieldAccessor}(); $field = $constraint->fields; if (! method_exists($constraint->repository, $method)) { throw new ConstraintDefinitionException(sprintf( '%s targeted by Callback constraint is not a valid callable in the repository', json_encode($method) )); } if ($object !== null && ! $repository->{$method}($object)) { $this->context->buildViolation($constraint->message) ->atPath($field) ->setInvalidValue($value) ->setCode(RepositoryCallback::NOT_VALID_REPO_CALLBACK) ->setCause('Not Satisfying method:' . $method) ->addViolation(); } } /** * List of required services * * @return string[] */ public static function dependencies(): array { return [ ServiceProvider::CENTREON_DB_MANAGER, ]; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Application/Validation/Validator/Interfaces/CentreonValidatorInterface.php
centreon/src/Centreon/Application/Validation/Validator/Interfaces/CentreonValidatorInterface.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ namespace Centreon\Application\Validation\Validator\Interfaces; /** * Purpose of this is to identify custom Centreon Validators, which may need additional dependencies * Interface CentreonValidatorInterface */ interface CentreonValidatorInterface { }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/VersionHelper.php
centreon/src/Centreon/Domain/VersionHelper.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain; /** * This class can be used to compare and harmonized two version numbers * * @package Centreon\Domain */ class VersionHelper { public const EQUAL = '=='; public const LT = '<'; public const GT = '>'; public const LE = '<='; public const GE = '>='; /** * Compare two version numbers. * Before comparison the depth between version numbers will be harmonized. * * @uses VersionHelper::regularizeDepthVersion() to harmonize the version numbers * @uses version_compare after version numbers harmonization * * @param string $version1 First version to compare * @param string $version2 Second version to compare * @param string $operator Comparison operator (default: VersionHelper::EQUAL) * @return bool Returns the comparison result */ public static function compare(string $version1, string $version2, string $operator = self::EQUAL): bool { $floatSeparationSymbol = '.'; if ((substr_count($version1, ',') + substr_count($version2, ',')) > 0) { $floatSeparationSymbol = ','; } $depthVersion1 = substr_count($version1, $floatSeparationSymbol); $depthVersion2 = substr_count($version2, $floatSeparationSymbol); if ($depthVersion1 > $depthVersion2) { $version2 = self::regularizeDepthVersion($version2, $depthVersion1, $floatSeparationSymbol); } if ($depthVersion2 > $depthVersion1) { $version1 = self::regularizeDepthVersion($version1, $depthVersion2, $floatSeparationSymbol); } return version_compare($version1, $version2, $operator); } /** * Updates the depth of the version number. * * @param string $version Version number to update * @param int $depth Depth destination * @param string $glue * @return string Returns the updated version number with the destination depth */ public static function regularizeDepthVersion(string $version, int $depth = 2, string $glue = '.'): string { $actualDepth = substr_count($version, $glue); if ($actualDepth == $depth) { return $version; } if ($actualDepth > $depth) { $parts = array_slice(explode($glue, $version), 0, ($depth + 1)); return implode($glue, $parts); } for ($loop = $actualDepth; $loop < $depth; $loop++) { $version .= $glue . '0'; } return $version; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Annotation/EntityDescriptor.php
centreon/src/Centreon/Domain/Annotation/EntityDescriptor.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Annotation; /** * Entity description used to define the setter method for a specific column. * * @Annotation * @Target({"PROPERTY"}) */ class EntityDescriptor { /** @var string Name of the column */ public $column; /** @var string Name of the setter method */ public $modifier; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/ActionLog/ActionLogException.php
centreon/src/Centreon/Domain/ActionLog/ActionLogException.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\ActionLog; class ActionLogException extends \Exception { }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/ActionLog/ActionLog.php
centreon/src/Centreon/Domain/ActionLog/ActionLog.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\ActionLog; class ActionLog { public const ACTION_TYPE_ADD = 'a'; public const ACTION_TYPE_DELETE = 'd'; public const ACTION_TYPE_ENABLE = 'enable'; public const ACTION_TYPE_DISABLE = 'disable'; /** @var int|null */ private $id; /** @var \DateTime|null */ private $creationDate; /** @var string */ private $objectType; /** @var int */ private $objectId; /** @var string */ private $objectName; /** @var string */ private $actionType; /** @var int Id of the contact who added this action log */ private $contactId; /** * ActionLog constructor. * * @param string $objectType Object type (ex: host, service) * @param int $objectId Object id * @param string $objectName Object name (ex: localhost, localhost/ping) * @param string $actionType Action type (see ActionLog::ACTION_TYPE_ADD, etc...) * @param int $contactId Id of the contact who added this action log * @param \DateTime|null $creationDate if null, the creation date will be the same as the entity's creation date * * @see ActionLog::ACTION_TYPE_ADD * @see ActionLog::ACTION_TYPE_DELETE * @see ActionLog::ACTION_TYPE_ENABLE * @see ActionLog::ACTION_TYPE_DISABLE */ public function __construct( string $objectType, int $objectId, string $objectName, string $actionType, int $contactId, ?\DateTime $creationDate = null, ) { $this->objectType = $objectType; $this->objectId = $objectId; $this->objectName = $objectName; $this->actionType = $actionType; $this->contactId = $contactId; if ($creationDate === null) { $this->creationDate = new \DateTime(); } } /** * @return int|null */ public function getId(): ?int { return $this->id; } /** * @param int|null $id * @return ActionLog */ public function setId(?int $id): ActionLog { $this->id = $id; return $this; } /** * @return \DateTime|null */ public function getCreationDate(): ?\DateTime { return $this->creationDate; } /** * @param \DateTime|null $creationDate * @return ActionLog */ public function setCreationDate(?\DateTime $creationDate): ActionLog { $this->creationDate = $creationDate; return $this; } /** * @return string */ public function getObjectType(): string { return $this->objectType; } /** * @param string $objectType * @return ActionLog */ public function setObjectType(string $objectType): ActionLog { $this->objectType = $objectType; return $this; } /** * @return int */ public function getObjectId(): int { return $this->objectId; } /** * @param int $objectId * @return ActionLog */ public function setObjectId(int $objectId): ActionLog { $this->objectId = $objectId; return $this; } /** * @return string */ public function getObjectName(): string { return $this->objectName; } /** * @param string $objectName * @return ActionLog */ public function setObjectName(string $objectName): ActionLog { $this->objectName = $objectName; return $this; } /** * @return string */ public function getActionType(): string { return $this->actionType; } /** * @param string $actionType * @return ActionLog */ public function setActionType(string $actionType): ActionLog { $allowedActionTypes = [ self::ACTION_TYPE_ADD, self::ACTION_TYPE_DELETE, self::ACTION_TYPE_ENABLE, self::ACTION_TYPE_DISABLE, ]; if (! in_array($actionType, $allowedActionTypes)) { throw new \InvalidArgumentException(_('Type of action not recognized')); } $this->actionType = $actionType; return $this; } /** * @return int */ public function getContactId(): int { return $this->contactId; } /** * @param int $contactId * @return ActionLog */ public function setContactId(int $contactId): ActionLog { $this->contactId = $contactId; return $this; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/ActionLog/ActionLogService.php
centreon/src/Centreon/Domain/ActionLog/ActionLogService.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\ActionLog; use Centreon\Domain\ActionLog\Interfaces\ActionLogRepositoryInterface; use Centreon\Domain\ActionLog\Interfaces\ActionLogServiceInterface; /** * This class is designed to manage action log. * * @package Centreon\Domain\ActionLog */ class ActionLogService implements ActionLogServiceInterface { /** @var ActionLogRepositoryInterface */ private $actionLogRepository; /** * ActionLogService constructor. * * @param ActionLogRepositoryInterface $actionLogRepository */ public function __construct(ActionLogRepositoryInterface $actionLogRepository) { $this->actionLogRepository = $actionLogRepository; } /** * @inheritDoc */ public function addAction(ActionLog $actionLog, array $details = []): int { try { $actionId = $this->actionLogRepository->addAction($actionLog); if ($details !== []) { $actionLog->setId($actionId); $this->addDetailsOfAction($actionLog, $details); } return $actionId; } catch (\Throwable $ex) { throw new ActionLogException(_('Error when adding an entry in the action log'), 0, $ex); } } /** * Add details for the given action log. * * @param ActionLog $actionLog Action log for which you want to add details * @param array<string, string|int|bool> $details Details of action * @throws ActionLogException */ private function addDetailsOfAction(ActionLog $actionLog, array $details): void { try { if ($actionLog->getId() === null) { throw new ActionLogException(_('Action log id cannot be null')); } $this->actionLogRepository->addDetailsOfAction($actionLog, $details); } catch (\Throwable $ex) { throw new ActionLogException( sprintf(_('Error when adding details for the action log %d'), $actionLog->getId()), 0, $ex ); } } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/ActionLog/Interfaces/ActionLogServiceInterface.php
centreon/src/Centreon/Domain/ActionLog/Interfaces/ActionLogServiceInterface.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\ActionLog\Interfaces; use Centreon\Domain\ActionLog\ActionLog; use Centreon\Domain\ActionLog\ActionLogException; interface ActionLogServiceInterface { /** * Add action log. * * @param ActionLog $actionLog Action log to be added * @param array<string, string|int|bool> $details Details of action * @throws ActionLogException * @return int Return the id of the last added action */ public function addAction(ActionLog $actionLog, array $details = []): int; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/ActionLog/Interfaces/ActionLogRepositoryInterface.php
centreon/src/Centreon/Domain/ActionLog/Interfaces/ActionLogRepositoryInterface.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\ActionLog\Interfaces; use Centreon\Domain\ActionLog\ActionLog; use Centreon\Domain\Repository\RepositoryException; interface ActionLogRepositoryInterface { /** * Add action log. * * @param ActionLog $actionLog Action log to be added * @throws \Exception * @return int Return id of the last added action */ public function addAction(ActionLog $actionLog): int; /** * Add details for the given action log. * * @param ActionLog $actionLog Action log for which you want to add details * @param array<string, string|int|bool> $details Details of action * @throws RepositoryException * @throws \Exception */ public function addDetailsOfAction(ActionLog $actionLog, array $details): void; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Acknowledgement/Acknowledgement.php
centreon/src/Centreon/Domain/Acknowledgement/Acknowledgement.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Acknowledgement; use Centreon\Domain\Service\EntityDescriptorMetadataInterface; class Acknowledgement implements EntityDescriptorMetadataInterface { // Groups for serialization public const SERIALIZER_GROUPS_HOST = ['Default', 'ack_host']; public const SERIALIZER_GROUPS_SERVICE = ['Default', 'ack_service']; public const SERIALIZER_GROUP_FULL = 'ack_full'; // Types public const TYPE_HOST_ACKNOWLEDGEMENT = 0; public const TYPE_SERVICE_ACKNOWLEDGEMENT = 1; // Groups for validation public const VALIDATION_GROUP_ACK_RESOURCE = ['ack_resource']; /** @var int */ private $id; /** @var int */ private $pollerId; /** @var int */ private $hostId; /** @var int */ private $serviceId; /** @var int|null */ private $authorId; /** @var string|null */ private $authorName; /** @var string|null */ private $comment; /** @var \DateTime|null */ private $deletionTime; /** @var \DateTime|null */ private $entryTime; /** @var int Resource id */ private $resourceId; /** @var int|null Parent resource id */ private $parentResourceId; /** @var bool Indicates if the contacts must to be notify */ private $isNotifyContacts = true; /** @var bool Indicates this acknowledgement will be maintained in the case of a restart of the scheduler */ private $isPersistentComment = true; /** @var bool */ private $isSticky = true; /** @var int State of this acknowledgement */ private $state; /** @var int Type of this acknowledgement */ private $type; /** @var bool Indicates if this downtime should be applied to linked services */ private $withServices = false; /** @var bool Indicates if after acknowledgement action the resource should be force checked */ private $forceActiveChecks = true; /** * {@inheritDoc} */ public static function loadEntityDescriptorMetadata(): array { return [ 'author' => 'setAuthorName', 'acknowledgement_id' => 'setId', 'comment_data' => 'setComment', 'instance_id' => 'setPollerId', 'notify_contacts' => 'setNotifyContacts', 'persistent_comment' => 'setPersistentComment', 'sticky' => 'setSticky', ]; } /** * @return int|null */ public function getId(): ?int { return $this->id; } /** * @param int $id * @return Acknowledgement */ public function setId(int $id): Acknowledgement { $this->id = $id; return $this; } /** * @return int */ public function getPollerId(): ?int { return $this->pollerId; } /** * @param int $pollerId * @return Acknowledgement */ public function setPollerId(int $pollerId): Acknowledgement { $this->pollerId = $pollerId; return $this; } /** * @return int */ public function getHostId(): ?int { return $this->hostId; } /** * @param int $hostId * @return Acknowledgement */ public function setHostId(int $hostId): Acknowledgement { $this->hostId = $hostId; return $this; } /** * @return int */ public function getServiceId(): ?int { return $this->serviceId; } /** * @param int $serviceId * @return Acknowledgement */ public function setServiceId(int $serviceId): Acknowledgement { $this->serviceId = $serviceId; return $this; } /** * @return int|null */ public function getAuthorId(): ?int { return $this->authorId; } /** * @param int|null $authorId * @return Acknowledgement */ public function setAuthorId(?int $authorId): Acknowledgement { $this->authorId = $authorId; return $this; } /** * @return string|null */ public function getAuthorName(): ?string { return $this->authorName; } /** * @param string|null $authorName */ public function setAuthorName(?string $authorName): void { $this->authorName = $authorName; } /** * @return string|null */ public function getComment(): ?string { return $this->comment; } /** * @param string|null $comment * @return Acknowledgement */ public function setComment(?string $comment): Acknowledgement { $this->comment = $comment; return $this; } /** * @return \DateTime|null */ public function getDeletionTime(): ?\DateTime { return $this->deletionTime; } /** * @param \DateTime|null $deletionTime * @return Acknowledgement */ public function setDeletionTime(?\DateTime $deletionTime): Acknowledgement { $this->deletionTime = $deletionTime; return $this; } /** * @return \DateTime|null */ public function getEntryTime(): ?\DateTime { return $this->entryTime; } /** * @param \DateTime|null $entryTime * @return Acknowledgement */ public function setEntryTime(?\DateTime $entryTime): Acknowledgement { $this->entryTime = $entryTime; return $this; } /** * @return int */ public function getResourceId(): int { return $this->resourceId; } /** * @param int $resourceId * @return Acknowledgement */ public function setResourceId(int $resourceId): Acknowledgement { $this->resourceId = $resourceId; return $this; } /** * @return int */ public function getParentResourceId(): ?int { return $this->parentResourceId; } /** * @param int|null $parentResourceId * @return Acknowledgement */ public function setParentResourceId(?int $parentResourceId): Acknowledgement { $this->parentResourceId = $parentResourceId; return $this; } /** * @return bool */ public function isNotifyContacts(): bool { return $this->isNotifyContacts; } /** * @param bool $isNotifyContacts * @return Acknowledgement */ public function setNotifyContacts(bool $isNotifyContacts): Acknowledgement { $this->isNotifyContacts = $isNotifyContacts; return $this; } /** * @return bool */ public function isPersistentComment(): bool { return $this->isPersistentComment; } /** * @param bool $isPersistentComment * @return Acknowledgement */ public function setPersistentComment(bool $isPersistentComment): Acknowledgement { $this->isPersistentComment = $isPersistentComment; return $this; } /** * @return bool */ public function isSticky(): bool { return $this->isSticky; } /** * @param bool $isSticky * @return Acknowledgement */ public function setSticky(bool $isSticky): Acknowledgement { $this->isSticky = $isSticky; return $this; } /** * @return int */ public function getState(): int { return $this->state; } /** * @param int $state * @return Acknowledgement */ public function setState(int $state): Acknowledgement { $this->state = $state; return $this; } /** * @return int */ public function getType(): int { return $this->type; } /** * @param int $type * @return Acknowledgement */ public function setType(int $type): Acknowledgement { $this->type = $type; return $this; } /** * @return bool */ public function isWithServices(): bool { return $this->withServices; } /** * @param bool $withServices */ public function setWithServices(bool $withServices): void { $this->withServices = $withServices; } /** * @param bool $forceActiveChecks */ public function setForceActiveChecks(bool $forceActiveChecks): void { $this->forceActiveChecks = $forceActiveChecks; } /** * @return bool */ public function doesForceActiveChecks(): bool { return $this->forceActiveChecks; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Acknowledgement/AcknowledgementException.php
centreon/src/Centreon/Domain/Acknowledgement/AcknowledgementException.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Acknowledgement; class AcknowledgementException extends \RuntimeException { public function __construct($message = '', $code = 0, ?\Throwable $previous = null) { parent::__construct($message, $code, $previous); } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Acknowledgement/AcknowledgementService.php
centreon/src/Centreon/Domain/Acknowledgement/AcknowledgementService.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Acknowledgement; use Centreon\Domain\Acknowledgement\Interfaces\AcknowledgementRepositoryInterface; use Centreon\Domain\Acknowledgement\Interfaces\AcknowledgementServiceInterface; use Centreon\Domain\Contact\Contact; use Centreon\Domain\Engine\Interfaces\EngineServiceInterface; use Centreon\Domain\Entity\EntityValidator; use Centreon\Domain\Exception\EntityNotFoundException; use Centreon\Domain\Monitoring\Exception\ResourceException; use Centreon\Domain\Monitoring\Interfaces\MonitoringRepositoryInterface; use Centreon\Domain\Monitoring\Resource as ResourceEntity; use Centreon\Domain\Monitoring\ResourceService; use Centreon\Domain\Service\AbstractCentreonService; use Core\Security\AccessGroup\Application\Repository\ReadAccessGroupRepositoryInterface; use JMS\Serializer\Exception\ValidationFailedException; class AcknowledgementService extends AbstractCentreonService implements AcknowledgementServiceInterface { // validation groups public const VALIDATION_GROUPS_ADD_HOST_ACKS = ['Default', 'add_host_acks']; public const VALIDATION_GROUPS_ADD_SERVICE_ACKS = ['Default', 'add_service_acks']; public const VALIDATION_GROUPS_ADD_HOST_ACK = ['Default', 'add_host_ack']; public const VALIDATION_GROUPS_ADD_SERVICE_ACK = ['Default']; /** @var AcknowledgementRepositoryInterface */ private $acknowledgementRepository; /** @var EngineServiceInterface all acknowledgement requests except reading use Engine */ private $engineService; /** @var EntityValidator */ private $validator; /** @var MonitoringRepositoryInterface */ private $monitoringRepository; /** @var ReadAccessGroupRepositoryInterface */ private $accessGroupRepository; /** * AcknowledgementService constructor. * * @param AcknowledgementRepositoryInterface $acknowledgementRepository * @param ReadAccessGroupRepositoryInterface $accessGroupRepository * @param MonitoringRepositoryInterface $monitoringRepository * @param EngineServiceInterface $engineService * @param EntityValidator $validator */ public function __construct( AcknowledgementRepositoryInterface $acknowledgementRepository, ReadAccessGroupRepositoryInterface $accessGroupRepository, MonitoringRepositoryInterface $monitoringRepository, EngineServiceInterface $engineService, EntityValidator $validator, ) { $this->accessGroupRepository = $accessGroupRepository; $this->acknowledgementRepository = $acknowledgementRepository; $this->monitoringRepository = $monitoringRepository; $this->engineService = $engineService; $this->validator = $validator; } /** * {@inheritDoc} * @param Contact $contact * @return self */ public function filterByContact($contact): self { parent::filterByContact($contact); $this->engineService->filterByContact($contact); $accessGroups = $this->accessGroupRepository->findByContact($contact); $this->monitoringRepository ->setContact($this->contact) ->filterByAccessGroups($accessGroups); $this->acknowledgementRepository ->setContact($this->contact) ->filterByAccessGroups($accessGroups); return $this; } /** * @inheritDoc */ public function findOneAcknowledgement(int $acknowledgementId): ?Acknowledgement { if ($this->contact->isAdmin()) { return $this->acknowledgementRepository->findOneAcknowledgementForAdminUser($acknowledgementId); } return $this->acknowledgementRepository ->findOneAcknowledgementForNonAdminUser($acknowledgementId); } /** * @inheritDoc */ public function findAcknowledgements(): array { if ($this->contact->isAdmin()) { return $this->acknowledgementRepository->findAcknowledgementsForAdminUser(); } return $this->acknowledgementRepository ->findAcknowledgementsForNonAdminUser(); } /** * @inheritDoc */ public function addHostAcknowledgement(Acknowledgement $acknowledgement): void { // We validate the acknowledgement instance $errors = $this->validator->validate( $acknowledgement, null, AcknowledgementService::VALIDATION_GROUPS_ADD_HOST_ACK ); if ($errors->count() > 0) { throw new ValidationFailedException($errors); } $host = $this->monitoringRepository->findOneHost($acknowledgement->getResourceId()); if (is_null($host)) { throw new EntityNotFoundException(_('Host not found')); } $this->engineService->addHostAcknowledgement($acknowledgement, $host); if ($acknowledgement->isWithServices()) { $services = $this->monitoringRepository->findServicesByHostWithoutRequestParameters($host->getId()); foreach ($services as $service) { $service->setHost($host); $this->engineService->addServiceAcknowledgement($acknowledgement, $service); } } } /** * @inheritDoc */ public function addServiceAcknowledgement(Acknowledgement $acknowledgement): void { // We validate the acknowledgement instance $errors = $this->validator->validate( $acknowledgement, null, AcknowledgementService::VALIDATION_GROUPS_ADD_SERVICE_ACK ); if ($errors->count() > 0) { throw new ValidationFailedException($errors); } $service = $this->monitoringRepository->findOneService( $acknowledgement->getParentResourceId(), $acknowledgement->getResourceId() ); if (is_null($service)) { throw new EntityNotFoundException(_('Service not found')); } $host = $this->monitoringRepository->findOneHost($acknowledgement->getParentResourceId()); if (is_null($host)) { throw new EntityNotFoundException(_('Host not found')); } $service->setHost($host); $this->engineService->addServiceAcknowledgement($acknowledgement, $service); } /** * @inheritDoc */ public function addMetaServiceAcknowledgement(Acknowledgement $acknowledgement): void { // We validate the acknowledgement instance $errors = $this->validator->validate( $acknowledgement, null, AcknowledgementService::VALIDATION_GROUPS_ADD_SERVICE_ACK ); if ($errors->count() > 0) { throw new ValidationFailedException($errors); } $service = $this->monitoringRepository->findOneServiceByDescription( 'meta_' . $acknowledgement->getResourceId() ); if (is_null($service)) { throw new EntityNotFoundException(_('Service not found')); } $host = $this->monitoringRepository->findOneHost($service->getId()); if (is_null($host)) { throw new EntityNotFoundException(_('Host not found')); } $service->setHost($host); $this->engineService->addServiceAcknowledgement($acknowledgement, $service); } /** * @inheritDoc */ public function findHostsAcknowledgements(): array { return $this->acknowledgementRepository->findHostsAcknowledgements(); } /** * @inheritDoc */ public function findServicesAcknowledgements(): array { return $this->acknowledgementRepository->findServicesAcknowledgements(); } /** * @inheritDoc */ public function findAcknowledgementsByHost(int $hostId): array { return $this->acknowledgementRepository->findAcknowledgementsByHost($hostId); } /** * @inheritDoc */ public function findAcknowledgementsByService(int $hostId, int $serviceId): array { return $this->acknowledgementRepository->findAcknowledgementsByService($hostId, $serviceId); } /** * @inheritDoc */ public function findAcknowledgementsByMetaService(int $metaId): array { $service = $this->monitoringRepository->findOneServiceByDescription('meta_' . $metaId); if (is_null($service)) { throw new EntityNotFoundException(_('Service not found')); } return $this->acknowledgementRepository->findAcknowledgementsByService( $service->getHost()->getId(), $service->getId() ); } /** * @inheritDoc */ public function disacknowledgeHost(int $hostId): void { $host = $this->monitoringRepository->findOneHost($hostId); if (is_null($host)) { throw new EntityNotFoundException(_('Host not found')); } $acknowledgement = $this->acknowledgementRepository->findLatestHostAcknowledgement($hostId); if (is_null($acknowledgement)) { throw new AcknowledgementException(_('No acknowledgement found for this host')); } if (! is_null($acknowledgement->getDeletionTime())) { throw new AcknowledgementException(_('Acknowledgement already cancelled for this host')); } $this->engineService->disacknowledgeHost($host); } /** * @inheritDoc */ public function disacknowledgeMetaService(int $metaId): void { $service = $this->monitoringRepository->findOneServiceByDescription('meta_' . $metaId); if (is_null($service)) { throw new EntityNotFoundException(_('Meta service not found')); } $acknowledgement = $this->acknowledgementRepository->findLatestServiceAcknowledgement( $service->getHost()->getId(), $service->getId() ); if (is_null($acknowledgement)) { throw new AcknowledgementException(_('No acknowledgement found for this meta service')); } if (! is_null($acknowledgement->getDeletionTime())) { throw new AcknowledgementException(_('Acknowledgement already cancelled for this meta service')); } $this->engineService->disacknowledgeService($service); } /** * @inheritDoc */ public function disacknowledgeService(int $hostId, int $serviceId): void { $service = $this->monitoringRepository->findOneService($hostId, $serviceId); if (is_null($service)) { throw new EntityNotFoundException(_('Service not found')); } $service->setHost( $this->monitoringRepository->findOneHost($hostId) ); $acknowledgement = $this->acknowledgementRepository->findLatestServiceAcknowledgement( $hostId, $serviceId ); if (is_null($acknowledgement)) { throw new AcknowledgementException(_('No acknowledgement found for this service')); } if (! is_null($acknowledgement->getDeletionTime())) { throw new AcknowledgementException(_('Acknowledgement already cancelled for this service')); } $this->engineService->disacknowledgeService($service); } /** * @inheritDoc */ public function disacknowledgeResource(ResourceEntity $resource, Acknowledgement $ack): void { switch ($resource->getType()) { case ResourceEntity::TYPE_HOST: $host = $this->monitoringRepository->findOneHost(ResourceService::generateHostIdByResource($resource)); if (is_null($host)) { throw new EntityNotFoundException(_('Host not found')); } $this->engineService->disacknowledgeHost($host); if ($ack->isWithServices()) { $services = $this->monitoringRepository->findServicesByHostWithoutRequestParameters($host->getId()); foreach ($services as $service) { $service->setHost($host); $this->engineService->disacknowledgeService($service); } } break; case ResourceEntity::TYPE_SERVICE: $host = $this->monitoringRepository->findOneHost(ResourceService::generateHostIdByResource($resource)); if (is_null($host)) { throw new EntityNotFoundException(_('Host not found')); } $service = $this->monitoringRepository->findOneService( (int) $resource->getParent()->getId(), (int) $resource->getId() ); if (is_null($service)) { throw new EntityNotFoundException( sprintf( _('Service %d (parent: %d) not found'), $resource->getId(), $resource->getParent()->getId() ) ); } $service->setHost($host); $this->engineService->disacknowledgeService($service); break; case ResourceEntity::TYPE_META: $service = $this->monitoringRepository->findOneServiceByDescription('meta_' . $resource->getId()); if (is_null($service)) { throw new EntityNotFoundException( sprintf( _('Meta Service %d not found'), $resource->getId() ) ); } $host = $this->monitoringRepository->findOneHost($service->getHost()->getId()); if (is_null($host)) { throw new EntityNotFoundException(_('Host not found')); } $service->setHost($host); $this->engineService->disacknowledgeService($service); break; default: throw new ResourceException(sprintf(_('Incorrect Resource type: %s'), $resource->getType())); } } /** * @inheritDoc */ public function acknowledgeResource(ResourceEntity $resource, Acknowledgement $ack): void { switch ($resource->getType()) { case ResourceEntity::TYPE_HOST: $host = $this->monitoringRepository->findOneHost(ResourceService::generateHostIdByResource($resource)); if (is_null($host)) { throw new EntityNotFoundException(_('Host not found')); } $this->engineService->addHostAcknowledgement($ack, $host); if ($ack->doesForceActiveChecks()) { $this->engineService->scheduleForcedHostCheck($host); } if ($ack->isWithServices()) { $services = $this->monitoringRepository->findServicesByHostWithoutRequestParameters($host->getId()); foreach ($services as $service) { $service->setHost($host); $this->engineService->addServiceAcknowledgement($ack, $service); if ($ack->doesForceActiveChecks()) { $this->engineService->scheduleImmediateForcedServiceCheck($service); } } } break; case ResourceEntity::TYPE_SERVICE: $host = $this->monitoringRepository->findOneHost(ResourceService::generateHostIdByResource($resource)); if (is_null($host)) { throw new EntityNotFoundException(_('Host not found')); } $service = $this->monitoringRepository->findOneService( (int) $resource->getParent()->getId(), (int) $resource->getId() ); if (is_null($service)) { throw new EntityNotFoundException( sprintf( _('Service %d (parent: %d) not found'), $resource->getId(), $resource->getParent()->getId() ) ); } $service->setHost($host); $this->engineService->addServiceAcknowledgement($ack, $service); if ($ack->doesForceActiveChecks()) { $this->engineService->scheduleImmediateForcedServiceCheck($service); } break; case ResourceEntity::TYPE_META: $service = $this->monitoringRepository->findOneServiceByDescription('meta_' . $resource->getId()); if (is_null($service)) { throw new EntityNotFoundException( sprintf( _('Meta Service %d not found'), $resource->getId(), $resource->getParent()->getId() ) ); } $host = $this->monitoringRepository->findOneHost($service->getHost()->getId()); if (is_null($host)) { throw new EntityNotFoundException(_('Host not found')); } $service->setHost($host); $this->engineService->addServiceAcknowledgement($ack, $service); if ($ack->doesForceActiveChecks()) { $this->engineService->scheduleImmediateForcedServiceCheck($service); } break; default: throw new ResourceException(sprintf(_('Incorrect Resource type: %s'), $resource->getType())); } } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Acknowledgement/Interfaces/AcknowledgementServiceInterface.php
centreon/src/Centreon/Domain/Acknowledgement/Interfaces/AcknowledgementServiceInterface.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Acknowledgement\Interfaces; use Centreon\Domain\Acknowledgement\Acknowledgement; use Centreon\Domain\Acknowledgement\AcknowledgementException; use Centreon\Domain\Contact\Interfaces\ContactFilterInterface; use Centreon\Domain\Engine\EngineException; use Centreon\Domain\Exception\EntityNotFoundException; use Centreon\Domain\Monitoring\Resource as ResourceEntity; use Centreon\Infrastructure\RequestParameters\RequestParametersTranslatorException; use JMS\Serializer\Exception\ValidationFailedException; interface AcknowledgementServiceInterface extends ContactFilterInterface { /** * Find one acknowledgement. * * @param int $acknowledgementId Acknowledgement id * @throws \Exception * @return Acknowledgement|null Return NULL if the acknowledgement has not been found */ public function findOneAcknowledgement(int $acknowledgementId): ?Acknowledgement; /** * Find all acknowledgements. * * @throws \Exception * @return Acknowledgement[] */ public function findAcknowledgements(): array; /** * Find all acknowledgements of all hosts. * * @throws RequestParametersTranslatorException * @throws \Exception * @return Acknowledgement[] */ public function findHostsAcknowledgements(): array; /** * Find all acknowledgements of all services. * * @throws RequestParametersTranslatorException * @throws \Exception * @return Acknowledgement[] */ public function findServicesAcknowledgements(): array; /** * Find all acknowledgements by host id. * * @param int $hostId * @throws RequestParametersTranslatorException * @throws \Exception * @return Acknowledgement[] */ public function findAcknowledgementsByHost(int $hostId): array; /** * Find all acknowledgements by host id and service id. * * @param int $hostId * @param int $serviceId * @throws RequestParametersTranslatorException * @throws \Exception * @return Acknowledgement[] */ public function findAcknowledgementsByService(int $hostId, int $serviceId): array; /** * Find all acknowledgements by metaservice id. * * @param int $metaId * @throws RequestParametersTranslatorException * @throws \Exception * @return Acknowledgement[] */ public function findAcknowledgementsByMetaService(int $metaId): array; /** * Adds a host acknowledgement. * * @param Acknowledgement $acknowledgement Host acknowledgement to add * @throws AcknowledgementException * @throws EngineException * @throws EntityNotFoundException * @throws \Exception * @throws ValidationFailedException */ public function addHostAcknowledgement(Acknowledgement $acknowledgement): void; /** * Adds a service acknowledgement. * * @param Acknowledgement $acknowledgement Host acknowledgement to add * @throws AcknowledgementException * @throws EngineException * @throws EntityNotFoundException * @throws \Exception * @throws ValidationFailedException */ public function addServiceAcknowledgement(Acknowledgement $acknowledgement): void; /** * Adds a Meta service acknowledgement. * * @param Acknowledgement $acknowledgement Meta service acknowledgement to add * @throws AcknowledgementException * @throws EngineException * @throws EntityNotFoundException * @throws \Exception * @throws ValidationFailedException */ public function addMetaServiceAcknowledgement(Acknowledgement $acknowledgement): void; /** * Disacknowledge a host. * * @param int $hostId Host id of acknowledgement to be cancelled * @throws EngineException * @throws EntityNotFoundException * @throws \Exception */ public function disacknowledgeHost(int $hostId): void; /** * Disacknowledge a service. * * @param int $hostId Host id linked to the service * @param int $serviceId Service id of acknowledgement to be cancelled * @throws EngineException * @throws EntityNotFoundException * @throws \Exception */ public function disacknowledgeService(int $hostId, int $serviceId): void; /** * Disacknowledge a metaservice. * * @param int $metaId ID of the metaservice * @throws EngineException * @throws EntityNotFoundException * @throws \Exception */ public function disacknowledgeMetaService(int $metaId): void; /** * Acknowledge resource and its services if needed. * * @param ResourceEntity $resource Resource to be acknowledged * @param Acknowledgement $ack * @throws EntityNotFoundException * @throws \Exception */ public function acknowledgeResource(ResourceEntity $resource, Acknowledgement $ack): void; /** * Discknowledge resource and its services if needed. * * @param ResourceEntity $resource Resource to be acknowledged * @param Acknowledgement $ack * @throws EntityNotFoundException * @throws \Exception */ public function disacknowledgeResource(ResourceEntity $resource, Acknowledgement $ack): void; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Acknowledgement/Interfaces/AcknowledgementRepositoryInterface.php
centreon/src/Centreon/Domain/Acknowledgement/Interfaces/AcknowledgementRepositoryInterface.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Acknowledgement\Interfaces; use Centreon\Domain\Acknowledgement\Acknowledgement; use Centreon\Domain\Contact\Interfaces\ContactInterface; use Centreon\Infrastructure\RequestParameters\RequestParametersTranslatorException; use Core\Security\AccessGroup\Domain\Model\AccessGroup; interface AcknowledgementRepositoryInterface { /** * Sets the access groups that will be used to filter acknowledgements. * * @param AccessGroup[]|null $accessGroups * @return self */ public function filterByAccessGroups(?array $accessGroups): self; /** * Find the latest service acknowledgement. * * @param int $hostId Host id linked to the service * @param int $serviceId Service id for which we want the latest acknowledgement * @throws \Exception * @return Acknowledgement|null */ public function findLatestServiceAcknowledgement(int $hostId, int $serviceId): ?Acknowledgement; /** * Find the latest host acknowledgement. * * @param int $hostId Host id for which we want to find the lastest acknowledgement * @throws \Exception * @return Acknowledgement|null */ public function findLatestHostAcknowledgement(int $hostId): ?Acknowledgement; /** * Find one acknowledgement **without taking into account** the ACLs of user. * * @param int $acknowledgementId Acknowledgement id * @throws \Exception * @return Acknowledgement|null Return NULL if the acknowledgement has not been found */ public function findOneAcknowledgementForAdminUser(int $acknowledgementId): ?Acknowledgement; /** * Find one acknowledgement **taking into account** the ACLs of user. * * @param int $acknowledgementId Acknowledgement id * @throws \Exception * @return Acknowledgement|null Return NULL if the acknowledgement has not been found */ public function findOneAcknowledgementForNonAdminUser(int $acknowledgementId): ?Acknowledgement; /** * Find all acknowledgements **without taking into account** the ACLs of user. * * @throws \Exception * @return Acknowledgement[] Return the acknowledgements found */ public function findAcknowledgementsForAdminUser(): array; /** * Find all acknowledgements **taking into account** the ACLs of user. * * @throws \Exception * @return Acknowledgement[] Return the acknowledgements found */ public function findAcknowledgementsForNonAdminUser(): array; /** * Find acknowledgements of all hosts. * * @throws \Exception * @throws RequestParametersTranslatorException * @return Acknowledgement[] */ public function findHostsAcknowledgements(); /** * Find acknowledgements of all services. * * @throws \Exception * @throws RequestParametersTranslatorException * @return Acknowledgement[] */ public function findServicesAcknowledgements(); /** * Find host acknowledgements. * * @param int $hostId Host id for which we want to find the acknowledgements * @throws \Exception * @return Acknowledgement[] */ public function findAcknowledgementsByHost(int $hostId): array; /** * Find service acknowledgements. * * @param int $hostId Host id linked to the service * @param int $serviceId Service id for which we want the acknowledgements * @throws \Exception * @return Acknowledgement[] */ public function findAcknowledgementsByService(int $hostId, int $serviceId): array; /** * Indicates whether the contact is an admin or not. * * @param bool $isAdmin Set TRUE if the contact is an admin * @return self */ public function setAdmin(bool $isAdmin): self; /** * @param ContactInterface $contact * @return AcknowledgementRepositoryInterface */ public function setContact(ContactInterface $contact): self; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/PlatformTopology/PlatformTopologyService.php
centreon/src/Centreon/Domain/PlatformTopology/PlatformTopologyService.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\PlatformTopology; use Centreon\Domain\Broker\Interfaces\BrokerRepositoryInterface; use Centreon\Domain\Contact\Interfaces\ContactInterface; use Centreon\Domain\Engine\EngineException; use Centreon\Domain\Engine\Interfaces\EngineConfigurationServiceInterface; use Centreon\Domain\Exception\EntityNotFoundException; use Centreon\Domain\MonitoringServer\Exception\MonitoringServerException; use Centreon\Domain\MonitoringServer\Interfaces\MonitoringServerServiceInterface; use Centreon\Domain\PlatformInformation\Exception\PlatformInformationException; use Centreon\Domain\PlatformInformation\Interfaces\PlatformInformationServiceInterface; use Centreon\Domain\PlatformInformation\Model\PlatformInformation; use Centreon\Domain\PlatformTopology\Exception\PlatformTopologyException; use Centreon\Domain\PlatformTopology\Interfaces\PlatformInterface; use Centreon\Domain\PlatformTopology\Interfaces\PlatformTopologyRegisterRepositoryInterface; use Centreon\Domain\PlatformTopology\Interfaces\PlatformTopologyRepositoryExceptionInterface; use Centreon\Domain\PlatformTopology\Interfaces\PlatformTopologyRepositoryInterface; use Centreon\Domain\PlatformTopology\Interfaces\PlatformTopologyServiceInterface; use Centreon\Domain\PlatformTopology\Model\PlatformPending; use Centreon\Domain\PlatformTopology\Model\PlatformRelation; use Centreon\Domain\Proxy\Interfaces\ProxyServiceInterface; use Centreon\Domain\RemoteServer\Interfaces\RemoteServerRepositoryInterface; use Core\Security\AccessGroup\Application\Repository\ReadAccessGroupRepositoryInterface; use Core\Security\AccessGroup\Domain\Model\AccessGroup; /** * Service intended to register a new server to the platform topology * * @package Centreon\Domain\PlatformTopology */ class PlatformTopologyService implements PlatformTopologyServiceInterface { /** * Broker Retention Parameter */ public const BROKER_PEER_RETENTION = 'one_peer_retention_mode'; /** * PlatformTopologyService constructor. */ public function __construct( private PlatformTopologyRepositoryInterface $platformTopologyRepository, private PlatformInformationServiceInterface $platformInformationService, private ProxyServiceInterface $proxyService, private EngineConfigurationServiceInterface $engineConfigurationService, private MonitoringServerServiceInterface $monitoringServerService, private BrokerRepositoryInterface $brokerRepository, private PlatformTopologyRegisterRepositoryInterface $platformTopologyRegisterRepository, private RemoteServerRepositoryInterface $remoteServerRepository, private ReadAccessGroupRepositoryInterface $readAccessGroupRepository, ) { } /** * @inheritDoc */ public function addPendingPlatformToTopology(PlatformInterface $platformPending): void { // check entity consistency $this->checkEntityConsistency($platformPending); /** * Search for already registered central or remote top level server on this platform * As only top level platform do not need parent_address and only one should be registered */ $this->checkForAlreadyRegisteredSameNameOrAddress($platformPending); switch ($platformPending->getType()) { case PlatformPending::TYPE_CENTRAL: // New unique Central top level platform case $this->searchAlreadyRegisteredTopLevelPlatformByType(PlatformPending::TYPE_CENTRAL); $this->searchAlreadyRegisteredTopLevelPlatformByType(PlatformPending::TYPE_REMOTE); $this->setMonitoringServerId($platformPending); break; case PlatformPending::TYPE_REMOTE: // Cannot add a Remote behind another Remote $this->searchAlreadyRegisteredTopLevelPlatformByType(PlatformPending::TYPE_REMOTE); if ($platformPending->getParentAddress() === null) { // New unique Remote top level platform case $this->searchAlreadyRegisteredTopLevelPlatformByType(PlatformPending::TYPE_CENTRAL); $this->setMonitoringServerId($platformPending); } break; } /** * @var PlatformInterface|null $registeredParentInTopology */ $registeredParentInTopology = $this->findParentPlatform($platformPending); /** * The top level platform is defined as a Remote : * Getting data and calling the register request on the Central if the remote is already registered on it */ if ( $registeredParentInTopology !== null && $registeredParentInTopology->isLinkedToAnotherServer() === true ) { $this->registerPlatformToParent($platformPending); } // Insert the platform into 'platform_topology' table try { // add the new platform $this->platformTopologyRepository->addPlatformToTopology($platformPending); } catch (\Exception $ex) { throw PlatformTopologyException::errorWhenAddingThePlatform( $platformPending->getName(), $platformPending->getAddress() ); } } /** * @inheritDoc */ public function getPlatformTopology(): array { $platformTopology = $this->platformTopologyRepository->getPlatformTopology(); if ($platformTopology === []) { throw new EntityNotFoundException(_('No Platform Topology found.')); } foreach ($platformTopology as $platform) { // Set the parent address if the platform is not the top level if ($platform->getParentId() !== null) { $platformParent = $this->platformTopologyRepository->findPlatform( $platform->getParentId() ); if ($platformParent !== null) { $platform->setParentAddress($platformParent->getAddress()); $platform->setParentId($platformParent->getId()); } } // Set the broker relation type if the platform is completely registered if ($platform->getServerId() !== null) { $brokerConfigurations = $this->brokerRepository->findByMonitoringServerAndParameterName( $platform->getServerId(), self::BROKER_PEER_RETENTION ); $platform->setRelation(PlatformRelation::NORMAL_RELATION); foreach ($brokerConfigurations as $brokerConfiguration) { if ($brokerConfiguration->getConfigurationValue() === 'yes') { $platform->setRelation(PlatformRelation::PEER_RETENTION_RELATION); break; } } } else { $platform->setRelation(PlatformRelation::NORMAL_RELATION); } } return $platformTopology; } /** * @inheritDoc */ public function getPlatformTopologyForUser(ContactInterface $user): array { $accessGroupIds = array_map( fn (AccessGroup $accessGroup) => $accessGroup->getId(), $this->readAccessGroupRepository->findByContact($user) ); $platformTopology = $this->platformTopologyRepository->getPlatformTopologyByAccessGroupIds($accessGroupIds); if ($platformTopology === []) { throw new EntityNotFoundException(_('No Platform Topology found.')); } foreach ($platformTopology as $platform) { // Set the parent address if the platform is not the top level if ($platform->getParentId() !== null) { $platformParent = $this->platformTopologyRepository->findPlatform( $platform->getParentId() ); if ($platformParent !== null) { $platform->setParentAddress($platformParent->getAddress()); $platform->setParentId($platformParent->getId()); } } // Set the broker relation type if the platform is completely registered if ($platform->getServerId() !== null) { $brokerConfigurations = $this->brokerRepository->findByMonitoringServerAndParameterName( $platform->getServerId(), self::BROKER_PEER_RETENTION ); $platform->setRelation(PlatformRelation::NORMAL_RELATION); foreach ($brokerConfigurations as $brokerConfiguration) { if ($brokerConfiguration->getConfigurationValue() === 'yes') { $platform->setRelation(PlatformRelation::PEER_RETENTION_RELATION); break; } } } else { $platform->setRelation(PlatformRelation::NORMAL_RELATION); } } return $platformTopology; } /** * @inheritDoc */ public function deletePlatformAndReallocateChildren(int $serverId): void { try { if (($deletedPlatform = $this->platformTopologyRepository->findPlatform($serverId)) === null) { throw new EntityNotFoundException(_('Platform not found')); } $childPlatforms = $this->platformTopologyRepository->findChildrenPlatformsByParentId($serverId); if ($childPlatforms !== []) { /** * If at least one children platform was found, * find the Top Parent platform and link children platform(s) to it. */ $topLevelPlatform = $this->findTopLevelPlatform(); if ($topLevelPlatform === null) { throw new EntityNotFoundException(_('No top level platform found to link the child platforms')); } /** * Update children parent_id. */ foreach ($childPlatforms as $platform) { $platform->setParentId($topLevelPlatform->getId()); $this->updatePlatformParameters($platform); } } /** * Delete the monitoring server and the topology. */ if ($deletedPlatform->getServerId() !== null) { if ($deletedPlatform->getType() === PlatformPending::TYPE_REMOTE) { $this->remoteServerRepository->deleteRemoteServerByServerId($deletedPlatform->getServerId()); $this->remoteServerRepository->deleteAdditionalRemoteServer($deletedPlatform->getServerId()); } $this->monitoringServerService->deleteServer($deletedPlatform->getServerId()); } else { $this->platformTopologyRepository->deletePlatform($deletedPlatform->getId()); } } catch (EntityNotFoundException|PlatformTopologyException $ex) { throw $ex; } catch (\Exception $ex) { throw new PlatformTopologyException(_('An error occurred while deleting the platform'), 0, $ex); } } /** * @inheritDoc */ public function updatePlatformParameters(PlatformInterface $platform): void { try { $this->platformTopologyRepository->updatePlatformParameters($platform); } catch (\Exception $ex) { throw new PlatformTopologyException(_('An error occurred while updating the platform'), 0, $ex); } } /** * @inheritDoc */ public function findTopLevelPlatform(): ?PlatformInterface { return $this->platformTopologyRepository->findTopLevelPlatform(); } /** * @inheritDoc */ public function isValidPlatform(ContactInterface $user, int $platformId): bool { if (! ($platform = $this->platformTopologyRepository->findPlatform($platformId))) { return false; } if ($user->isAdmin()) { return true; } $accessGroupIds = array_map( fn (AccessGroup $accessGroup) => $accessGroup->getId(), $this->readAccessGroupRepository->findByContact($user) ); return (bool) ( ( $platform->getServerId() !== null && $this->platformTopologyRepository->hasAccessToPlatform($accessGroupIds, $platform->getServerId()) ) || ! $this->platformTopologyRepository->hasRestrictedAccessToPlatforms($accessGroupIds) ); } /** * @param PlatformInterface $platformPending * @throws PlatformTopologyException * @throws PlatformInformationException */ private function registerPlatformToParent(PlatformInterface $platformPending): void { /** * Getting platform information's data * @var PlatformInformation|null $foundPlatformInformation */ $foundPlatformInformation = $this->platformInformationService->getInformation(); if ($foundPlatformInformation === null) { throw PlatformTopologyException::missingMandatoryData( $platformPending->getName(), $platformPending->getAddress() ); } if ($foundPlatformInformation->isRemote() === false) { throw PlatformTopologyException::notTypeRemote( $platformPending->getName(), $platformPending->getAddress() ); } if ($foundPlatformInformation->getCentralServerAddress() === null) { throw PlatformTopologyException::platformNotLinkedToTheCentral( $platformPending->getName(), $platformPending->getAddress() ); } if ( $foundPlatformInformation->getApiUsername() === null || $foundPlatformInformation->getApiCredentials() === null ) { throw PlatformTopologyException::missingCentralCredentials( $platformPending->getName(), $platformPending->getAddress() ); } if ($foundPlatformInformation->getApiScheme() === null) { throw PlatformTopologyException::missingCentralScheme( $platformPending->getName(), $platformPending->getAddress() ); } if ($foundPlatformInformation->getApiPort() === null) { throw PlatformTopologyException::missingCentralPort( $platformPending->getName(), $platformPending->getAddress() ); } if ($foundPlatformInformation->getApiPath() === null) { throw PlatformTopologyException::missingCentralPath( $platformPending->getName(), $platformPending->getAddress() ); } /** * Register this platform to its Parent */ try { $this->platformTopologyRegisterRepository->registerPlatformToParent( $platformPending, $foundPlatformInformation, $this->proxyService->getProxy() ); } catch (PlatformTopologyException $ex) { throw $ex; } catch (PlatformTopologyRepositoryExceptionInterface $ex) { throw new PlatformTopologyException($ex->getMessage(), $ex->getCode(), $ex); } catch (\Exception $ex) { throw new PlatformTopologyException(_("Error from Central's register API"), 0, $ex); } } /** * Get engine configuration's illegal characters and check for illegal characters in hostname * @param string|null $stringToCheck * @throws EngineException * @throws PlatformTopologyException * @throws MonitoringServerException */ private function checkName(?string $stringToCheck): void { if ($stringToCheck === null) { return; } $monitoringServerName = $this->monitoringServerService->findLocalServer(); if ($monitoringServerName === null || $monitoringServerName->getName() === null) { throw PlatformTopologyException::unableToFindMonitoringServerName(); } $engineConfiguration = $this->engineConfigurationService->findEngineConfigurationByName( $monitoringServerName->getName() ); if ($engineConfiguration === null) { throw PlatformTopologyException::unableToFindEngineConfiguration(); } $foundIllegalCharacters = $engineConfiguration->hasIllegalCharacters($stringToCheck); if ($foundIllegalCharacters === true) { throw PlatformTopologyException::illegalCharacterFound( $engineConfiguration->getIllegalObjectNameCharacters(), $stringToCheck ); } } /** * Check for RFC 1123 & 1178 rules * More details are available in man hostname * @param string|null $stringToCheck * @return bool */ private function isHostnameValid(?string $stringToCheck): bool { if ($stringToCheck === null) { // empty hostname is allowed and should not be blocked or throw an exception return true; } return preg_match("/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*$/i", $stringToCheck) && preg_match('/^.{1,253}$/', $stringToCheck) // max 253 characters by hostname && preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*$/", $stringToCheck); // max 63 characters by domain } /** * Check hostname consistency * @param string|null $stringToCheck * @throws PlatformTopologyException */ private function checkHostname(?string $stringToCheck): void { if ($stringToCheck === null) { return; } if ($this->isHostnameValid($stringToCheck) === false) { throw PlatformTopologyException::illegalRfcCharacterFound($stringToCheck); } } /** * Check consistency of each mandatory and optional parameters * @param PlatformInterface $platform * @throws EngineException * @throws EntityNotFoundException * @throws MonitoringServerException * @throws PlatformTopologyException */ private function checkEntityConsistency(PlatformInterface $platform): void { // Check non RFC compliant characters in name and hostname if ($platform->getName() === null) { throw new EntityNotFoundException(_('Missing mandatory platform name')); } $this->checkName($platform->getName()); $this->checkHostname($platform->getHostname()); // Check empty platform's address if ($platform->getAddress() === null) { throw new EntityNotFoundException( sprintf( _("Missing mandatory platform address of: '%s'"), $platform->getName() ) ); } // Check empty parent address vs type consistency if ( $platform->getParentAddress() === null && ! in_array( $platform->getType(), [PlatformPending::TYPE_CENTRAL, PlatformPending::TYPE_REMOTE], false ) ) { throw new EntityNotFoundException( sprintf( _("Missing mandatory parent address, to link the platform : '%s'@'%s'"), $platform->getName(), $platform->getAddress() ) ); } // or Check for similar parent_address and address if ($platform->getParentAddress() === $platform->getAddress()) { throw PlatformTopologyException::addressConflict( $platform->getName(), $platform->getAddress() ); } } /** * Used when parent_address is null, to check if this type of platform is already registered * * @param string $type platform type to find * @throws PlatformTopologyException * @throws \Exception */ private function searchAlreadyRegisteredTopLevelPlatformByType(string $type): void { $foundAlreadyRegisteredTopLevelPlatform = $this->platformTopologyRepository->findTopLevelPlatformByType($type); if ($foundAlreadyRegisteredTopLevelPlatform !== null) { throw PlatformTopologyException::platformAlreadySaved( $type, $foundAlreadyRegisteredTopLevelPlatform->getName(), $foundAlreadyRegisteredTopLevelPlatform->getAddress() ); } } /** * Search for platforms monitoring ID and set it as serverId * * @param PlatformInterface $platform * @throws PlatformTopologyException * @throws \Exception */ private function setMonitoringServerId(PlatformInterface $platform): void { $foundServerInNagiosTable = null; if ($platform->getName() !== null) { $foundServerInNagiosTable = $this->platformTopologyRepository->findLocalMonitoringIdFromName( $platform->getName() ); } if ($foundServerInNagiosTable === null) { throw PlatformTopologyException::platformDoesNotMatchTheSavedOne( $platform->getType(), $platform->getName(), $platform->getAddress() ); } $platform->setServerId($foundServerInNagiosTable->getId()); } /** * Search for already registered platforms using same name or address * * @param PlatformInterface $platform * @throws PlatformTopologyException * @throws EntityNotFoundException * @throws \Exception */ private function checkForAlreadyRegisteredSameNameOrAddress(PlatformInterface $platform): void { // Two next checks are required for phpStan lvl8. But already done in the checkEntityConsistency method if ($platform->getName() === null) { throw new EntityNotFoundException(_('Missing mandatory platform name')); } if ($platform->getAddress() === null) { throw new EntityNotFoundException( sprintf( _("Missing mandatory platform address of: '%s'"), $platform->getName() ) ); } $addressAlreadyRegistered = $this->platformTopologyRepository->findPlatformByAddress($platform->getAddress()); $nameAlreadyRegistered = $this->platformTopologyRepository->findPlatformByName($platform->getName()); if ($nameAlreadyRegistered !== null || $addressAlreadyRegistered !== null) { throw PlatformTopologyException::platformNameOrAddressAlreadyExist( $platform->getName(), $platform->getAddress() ); } } /** * Search for platform's parent ID in topology * * @param PlatformInterface $platform * @throws EntityNotFoundException * @throws PlatformTopologyException * @throws \Exception * @return PlatformInterface|null */ private function findParentPlatform(PlatformInterface $platform): ?PlatformInterface { if ($platform->getParentAddress() === null) { return null; } if ($platform->getType() === PlatformPending::TYPE_REMOTE) { $registeredParentInTopology = $this->platformTopologyRepository->findTopLevelPlatform(); } else { $registeredParentInTopology = $this->platformTopologyRepository->findPlatformByAddress( $platform->getParentAddress() ); } if ($registeredParentInTopology === null) { throw new EntityNotFoundException( sprintf( _("No parent platform was found for : '%s'@'%s'"), $platform->getName(), $platform->getAddress() ) ); } // Avoid to link a remote to another remote if ( $platform->getType() === PlatformPending::TYPE_REMOTE && $registeredParentInTopology->getType() === PlatformPending::TYPE_REMOTE ) { throw PlatformTopologyException::unableToLinkARemoteToAnotherRemote( $registeredParentInTopology->getName(), $registeredParentInTopology->getAddress() ); } // Check parent consistency, as the platform can only be linked to a remote or central type if ( ! in_array( $registeredParentInTopology->getType(), [PlatformPending::TYPE_REMOTE, PlatformPending::TYPE_CENTRAL], false ) ) { throw PlatformTopologyException::inconsistentTypeToLinkThePlatformTo( $platform->getType(), $platform->getName(), $platform->getAddress(), $registeredParentInTopology->getType() ); } $platform->setParentId($registeredParentInTopology->getId()); // A platform behind a remote needs to send the data to the Central too if ( $registeredParentInTopology->getParentId() === null && $registeredParentInTopology->getType() === PlatformPending::TYPE_REMOTE ) { $registeredParentInTopology->setLinkedToAnotherServer(true); return $registeredParentInTopology; } return null; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/PlatformTopology/Model/PlatformRelation.php
centreon/src/Centreon/Domain/PlatformTopology/Model/PlatformRelation.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\PlatformTopology\Model; /** * Class designed to represent a relation between two platforms */ class PlatformRelation { /** * Broker relation types */ public const NORMAL_RELATION = 'normal'; public const PEER_RETENTION_RELATION = 'peer_retention'; /** * Available relation types */ private const AVAILABLE_RELATIONS = [ self::NORMAL_RELATION, self::PEER_RETENTION_RELATION, ]; /** * Source node in relation * * @var int */ private $source; /** * Broker relation * * @var string */ private $relation; /** * Target node in relation * * @var int */ private $target; /** * Get the value of source * * @return int */ public function getSource(): int { return $this->source; } /** * Set the value of source * * @param int $source * * @return self */ public function setSource(int $source): self { $this->source = $source; return $this; } /** * Get the value of relation * * @return string */ public function getRelation(): string { return $this->relation; } /** * Set the value of relation * * @param string|null $relation * * @return self */ public function setRelation(?string $relation): self { // Set relation to normal if invalid relation type is given to be able to compute the relation if ($relation !== null && ! in_array($relation, self::AVAILABLE_RELATIONS)) { $this->relation = self::NORMAL_RELATION; } else { $this->relation = $relation; } return $this; } /** * Get the value of target * * @return int */ public function getTarget(): int { return $this->target; } /** * Set the value of target * * @param int $target * * @return self */ public function setTarget(int $target): self { $this->target = $target; return $this; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/PlatformTopology/Model/PlatformPending.php
centreon/src/Centreon/Domain/PlatformTopology/Model/PlatformPending.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\PlatformTopology\Model; use Centreon\Domain\PlatformTopology\Interfaces\PlatformInterface; /** * Class designed to retrieve servers to be added using the wizard */ class PlatformPending implements PlatformInterface { public const TYPE_CENTRAL = 'central'; public const TYPE_POLLER = 'poller'; public const TYPE_REMOTE = 'remote'; public const TYPE_MAP = 'map'; public const TYPE_MBI = 'mbi'; /** * Available server types */ private const AVAILABLE_TYPES = [ self::TYPE_CENTRAL, self::TYPE_POLLER, self::TYPE_REMOTE, self::TYPE_MAP, self::TYPE_MBI, ]; /** @var int|null Id of server */ private $id; /** @var string|null chosen name : "virtual name" */ private $name; /** @var string|null platform's real name : "physical name" */ private $hostname; /** @var string|null Server type */ private $type; /** @var string|null Server address */ private $address; /** @var string|null Server parent address */ private $parentAddress; /** @var int|null Server parent id */ private $parentId; /** @var int|null Server nagios ID for Central only */ private $serverId; /** @var bool */ private $isLinkedToAnotherServer = false; /** @var PlatformRelation|null Communication type between topology and parent */ private $relation; /** * @var bool define if the platform is in a pending state or is already registered * By default PlatformPending entities are pending platforms */ private $isPending = true; /** * @inheritDoc */ public function getId(): ?int { return $this->id; } /** * @inheritDoc */ public function setId(?int $id): PlatformInterface { $this->id = $id; return $this; } /** * @inheritDoc */ public function getType(): ?string { return $this->type; } /** * @inheritDoc */ public function setType(?string $type): PlatformInterface { if ($type !== null) { $type = strtolower($type); // Check if the server_type is available if (! in_array($type, self::AVAILABLE_TYPES)) { throw new \InvalidArgumentException( sprintf( _("The platform type of '%s'@'%s' is not consistent"), $this->getName(), $this->getAddress() ) ); } } $this->type = $type; return $this; } /** * @inheritDoc */ public function getName(): ?string { return $this->name; } /** * @inheritDoc */ public function setName(?string $name): PlatformInterface { $this->name = $name; return $this; } /** * @inheritDoc */ public function getHostname(): ?string { return $this->hostname; } /** * @inheritDoc */ public function setHostname(?string $hostname): PlatformInterface { $this->hostname = $hostname; return $this; } /** * @inheritDoc */ public function getAddress(): ?string { return $this->address; } /** * @inheritDoc */ public function setAddress(?string $address): PlatformInterface { $this->address = $this->checkIpAddress($address); return $this; } /** * @inheritDoc */ public function getParentAddress(): ?string { return $this->parentAddress; } /** * @inheritDoc */ public function setParentAddress(?string $parentAddress): PlatformInterface { if ($parentAddress !== null && $this->getType() === static::TYPE_CENTRAL) { throw new \InvalidArgumentException(_('Cannot use parent address on a Central server type')); } $this->parentAddress = $this->checkIpAddress($parentAddress); return $this; } /** * @inheritDoc */ public function getParentId(): ?int { return $this->parentId; } /** * @inheritDoc */ public function setParentId(?int $parentId): PlatformInterface { if ($parentId !== null && $this->getType() === static::TYPE_CENTRAL) { throw new \InvalidArgumentException(_('Cannot set parent id to a central server')); } $this->parentId = $parentId; return $this; } /** * @inheritDoc */ public function getServerId(): ?int { return $this->serverId; } /** * @inheritDoc */ public function setServerId(?int $serverId): PlatformInterface { $this->serverId = $serverId; return $this; } /** * @inheritDoc */ public function isLinkedToAnotherServer(): bool { return $this->isLinkedToAnotherServer; } /** * @inheritDoc */ public function setLinkedToAnotherServer(bool $isLinked): PlatformInterface { $this->isLinkedToAnotherServer = $isLinked; return $this; } /** * @inheritDoc */ public function getRelation(): ?PlatformRelation { return $this->relation; } /** * @inheritDoc */ public function setRelation(?string $relationType): PlatformInterface { if ($this->getParentId() !== null) { $this->relation = (new PlatformRelation()) ->setSource($this->getId()) ->setRelation($relationType) ->setTarget($this->getParentId()); } return $this; } /** * @inheritDoc */ public function isPending(): bool { return $this->isPending; } /** * @inheritDoc */ public function setPending(bool $isPending): PlatformInterface { $this->isPending = $isPending; return $this; } /** * Validate address consistency * * @param string|null $address the address to be tested * @return string|null */ private function checkIpAddress(?string $address): ?string { // Check for valid IPv4 or IPv6 IP // or not sent address (in the case of Central's "parent_address") if ( $address !== null && ! filter_var($address, FILTER_VALIDATE_IP) && ! filter_var($address, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME) ) { throw new \InvalidArgumentException( sprintf( _("The address '%s' of '%s' is not valid or not resolvable"), $address, $this->getName() ) ); } return $address; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/PlatformTopology/Model/PlatformRegistered.php
centreon/src/Centreon/Domain/PlatformTopology/Model/PlatformRegistered.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\PlatformTopology\Model; use Centreon\Domain\PlatformTopology\Interfaces\PlatformInterface; /** * Class designed to retrieve servers to be added using the wizard */ class PlatformRegistered implements PlatformInterface { public const TYPE_CENTRAL = 'central'; public const TYPE_POLLER = 'poller'; public const TYPE_REMOTE = 'remote'; public const TYPE_MAP = 'map'; public const TYPE_MBI = 'mbi'; /** * Available server types */ private const AVAILABLE_TYPES = [ self::TYPE_CENTRAL, self::TYPE_POLLER, self::TYPE_REMOTE, self::TYPE_MAP, self::TYPE_MBI, ]; /** @var int|null Id of server */ private $id; /** @var string|null chosen name : "virtual name" */ private $name; /** @var string|null platform's real name : "physical name" */ private $hostname; /** @var string|null Server type */ private $type; /** @var string|null Server address */ private $address; /** @var string|null Server parent address */ private $parentAddress; /** @var int|null Server parent id */ private $parentId; /** @var int|null Server nagios ID for Central only */ private $serverId; /** @var bool */ private $isLinkedToAnotherServer = false; /** @var PlatformRelation|null Communication type between topology and parent */ private $relation; /** * @var bool define if the platform is in a pending state or is already registered * By default Platform entities are not pending platforms */ private $isPending = false; /** * @inheritDoc */ public function getId(): ?int { return $this->id; } /** * @inheritDoc */ public function setId(?int $id): PlatformInterface { $this->id = $id; return $this; } /** * @inheritDoc */ public function getType(): ?string { return $this->type; } /** * @inheritDoc */ public function setType(?string $type): PlatformInterface { if ($type !== null) { $type = strtolower($type); // Check if the server_type is available if (! in_array($type, self::AVAILABLE_TYPES)) { throw new \InvalidArgumentException( sprintf( _("The platform type of '%s'@'%s' is not consistent"), $this->getName(), $this->getAddress() ) ); } } $this->type = $type; return $this; } /** * @inheritDoc */ public function getName(): ?string { return $this->name; } /** * @inheritDoc */ public function setName(?string $name): PlatformInterface { $this->name = $name; return $this; } /** * @inheritDoc */ public function getHostname(): ?string { return $this->hostname; } /** * @inheritDoc */ public function setHostname(?string $hostname): PlatformInterface { $this->hostname = $hostname; return $this; } /** * @inheritDoc */ public function getAddress(): ?string { return $this->address; } /** * @inheritDoc */ public function setAddress(?string $address): PlatformInterface { $this->address = $this->checkIpAddress($address); return $this; } /** * @inheritDoc */ public function getParentAddress(): ?string { return $this->parentAddress; } /** * @inheritDoc */ public function setParentAddress(?string $parentAddress): PlatformInterface { if ($parentAddress !== null && $this->getType() === static::TYPE_CENTRAL) { throw new \InvalidArgumentException(_('Cannot use parent address on a Central server type')); } $this->parentAddress = $this->checkIpAddress($parentAddress); return $this; } /** * @inheritDoc */ public function getParentId(): ?int { return $this->parentId; } /** * @inheritDoc */ public function setParentId(?int $parentId): PlatformInterface { if ($parentId !== null && $this->getType() === static::TYPE_CENTRAL) { throw new \InvalidArgumentException(_('Cannot set parent id to a central server')); } $this->parentId = $parentId; return $this; } /** * @inheritDoc */ public function getServerId(): ?int { return $this->serverId; } /** * @inheritDoc */ public function setServerId(?int $serverId): PlatformInterface { $this->serverId = $serverId; return $this; } /** * @inheritDoc */ public function isLinkedToAnotherServer(): bool { return $this->isLinkedToAnotherServer; } /** * @inheritDoc */ public function setLinkedToAnotherServer(bool $isLinked): PlatformInterface { $this->isLinkedToAnotherServer = $isLinked; return $this; } /** * @inheritDoc */ public function getRelation(): ?PlatformRelation { return $this->relation; } /** * @inheritDoc */ public function setRelation(?string $relationType): PlatformInterface { if ($this->getParentId() !== null) { $this->relation = (new PlatformRelation()) ->setSource($this->getId()) ->setRelation($relationType) ->setTarget($this->getParentId()); } return $this; } /** * @inheritDoc */ public function isPending(): bool { return $this->isPending; } /** * @inheritDoc */ public function setPending(bool $isPending): PlatformInterface { $this->isPending = $isPending; return $this; } /** * Validate address consistency * * @param string|null $address the address to be tested * @return string|null */ private function checkIpAddress(?string $address): ?string { if ( $address !== null && ! filter_var($address, FILTER_VALIDATE_IP) && ! filter_var($address, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME) ) { throw new \InvalidArgumentException( sprintf( _("The address '%s' of '%s' is not valid or not resolvable"), $address, $this->getName() ) ); } return $address; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/PlatformTopology/Interfaces/PlatformTopologyRepositoryExceptionInterface.php
centreon/src/Centreon/Domain/PlatformTopology/Interfaces/PlatformTopologyRepositoryExceptionInterface.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\PlatformTopology\Interfaces; use Centreon\Domain\Repository\Interfaces\RepositoryExceptionInterface; interface PlatformTopologyRepositoryExceptionInterface extends RepositoryExceptionInterface { }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/PlatformTopology/Interfaces/PlatformTopologyReadRepositoryInterface.php
centreon/src/Centreon/Domain/PlatformTopology/Interfaces/PlatformTopologyReadRepositoryInterface.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\PlatformTopology\Interfaces; interface PlatformTopologyReadRepositoryInterface { /** * Search for already registered servers using same name or address. * * @param string $serverName * * @throws \Exception * * @return PlatformInterface|null */ public function findPlatformByName(string $serverName): ?PlatformInterface; /** * Search for platform's ID using its address. * * @param string $serverAddress * * @throws \Exception * * @return PlatformInterface|null */ public function findPlatformByAddress(string $serverAddress): ?PlatformInterface; /** * Search for platform's name and address using its type. * * @param string $serverType * * @throws \Exception * * @return PlatformInterface|null */ public function findTopLevelPlatformByType(string $serverType): ?PlatformInterface; /** * Search for local platform's monitoring Id using its name. * * @param string $serverName * * @throws \Exception * * @return PlatformInterface|null */ public function findLocalMonitoringIdFromName(string $serverName): ?PlatformInterface; /** * Search for the global topology of the platform. * * @return PlatformInterface[] */ public function getPlatformTopology(): array; /** * Search for the global topology of the platform according to a list of access groups. * * @param int[] $accessGroupIds * * @return PlatformInterface[] */ public function getPlatformTopologyByAccessGroupIds(array $accessGroupIds): array; /** * Search for the address of a topology using its Id. * * @param int $platformId * * @return PlatformInterface|null */ public function findPlatform(int $platformId): ?PlatformInterface; /** * Find the Top Level Platform. * * @return PlatformInterface|null */ public function findTopLevelPlatform(): ?PlatformInterface; /** * Find the children Platforms of another Platform. * * @param int $parentId * * @return PlatformInterface[] */ public function findChildrenPlatformsByParentId(int $parentId): array; /** * find all the type 'remote' children of a Central. * * @throws \Exception * * @return PlatformInterface[] */ public function findCentralRemoteChildren(): array; /** * Determine if the user has retricted access rights to platforms. * * @param int[] $accessGroupIds * * @throws \Throwable * * @return bool */ public function hasRestrictedAccessToPlatforms(array $accessGroupIds): bool; /** * Determine if the user has access rights to a platform. * * @param int[] $accessGroupIds * @param int $platformId * * @throws \Throwable * * @return bool */ public function hasAccessToPlatform(array $accessGroupIds, int $platformId): bool; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/PlatformTopology/Interfaces/PlatformTopologyRegisterRepositoryInterface.php
centreon/src/Centreon/Domain/PlatformTopology/Interfaces/PlatformTopologyRegisterRepositoryInterface.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\PlatformTopology\Interfaces; use Centreon\Domain\PlatformInformation\Model\PlatformInformation; use Centreon\Domain\PlatformTopology\Exception\PlatformTopologyException; use Centreon\Domain\Proxy\Proxy; interface PlatformTopologyRegisterRepositoryInterface { /** * Register the platform on its parent * * @param PlatformInterface $platform * @param PlatformInformation $platformInformation * @param Proxy|null $proxy * @throws PlatformTopologyRepositoryExceptionInterface * @throws PlatformTopologyException */ public function registerPlatformToParent( PlatformInterface $platform, PlatformInformation $platformInformation, ?Proxy $proxy = null, ): void; /** * Delete the platform on its parent * * @param PlatformInterface $platform * @param PlatformInformation $platformInformation * @param Proxy|null $proxy * @throws PlatformTopologyRepositoryExceptionInterface * @throws PlatformTopologyException */ public function deletePlatformToParent( PlatformInterface $platform, PlatformInformation $platformInformation, ?Proxy $proxy = null, ): void; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/PlatformTopology/Interfaces/PlatformTopologyWriteRepositoryInterface.php
centreon/src/Centreon/Domain/PlatformTopology/Interfaces/PlatformTopologyWriteRepositoryInterface.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\PlatformTopology\Interfaces; interface PlatformTopologyWriteRepositoryInterface { /** * Register a new platform to topology * * @param PlatformInterface $platform */ public function addPlatformToTopology(PlatformInterface $platform): void; /** * Delete a Platform. * * @param int $serverId */ public function deletePlatform(int $serverId): void; /** * Update a Platform. * * @param PlatformInterface $platform */ public function updatePlatformParameters(PlatformInterface $platform): void; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/PlatformTopology/Interfaces/PlatformTopologyRepositoryInterface.php
centreon/src/Centreon/Domain/PlatformTopology/Interfaces/PlatformTopologyRepositoryInterface.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\PlatformTopology\Interfaces; interface PlatformTopologyRepositoryInterface extends PlatformTopologyReadRepositoryInterface, PlatformTopologyWriteRepositoryInterface { }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/PlatformTopology/Interfaces/PlatformInterface.php
centreon/src/Centreon/Domain/PlatformTopology/Interfaces/PlatformInterface.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\PlatformTopology\Interfaces; use Centreon\Domain\PlatformTopology\Model\PlatformRelation; /** * Interface required to managed registered and pending platforms' entity * @package Centreon\Domain\PlatformTopology\Interfaces */ interface PlatformInterface { /** * @return int|null */ public function getId(): ?int; /** * @param int|null $id * @return self */ public function setId(?int $id): self; /** * @return string|null */ public function getType(): ?string; /** * @param string|null $type server type: central, poller, remote, map or mbi * * @return self */ public function setType(?string $type): self; /** * @return string|null */ public function getName(): ?string; /** * @param string|null $name * @return self */ public function setName(?string $name): self; /** * @return string|null */ public function getHostname(): ?string; /** * @param string|null $hostname * @return self */ public function setHostname(?string $hostname): self; /** * @return string|null */ public function getAddress(): ?string; /** * @param string|null $address * * @return self */ public function setAddress(?string $address): self; /** * @return string|null */ public function getParentAddress(): ?string; /** * @param string|null $parentAddress * * @return self */ public function setParentAddress(?string $parentAddress): self; /** * @return int|null */ public function getParentId(): ?int; /** * @param int|null $parentId * * @return self */ public function setParentId(?int $parentId): self; /** * @return int|null */ public function getServerId(): ?int; /** * @param int|null $serverId monitoring ID * @return self */ public function setServerId(?int $serverId): self; /** * @return bool */ public function isLinkedToAnotherServer(): bool; /** * @param bool $isLinked * @return self */ public function setLinkedToAnotherServer(bool $isLinked): self; /** * @return PlatformRelation */ public function getRelation(): ?PlatformRelation; /** * @param string|null $relationType * @return self */ public function setRelation(?string $relationType): self; /** * @return bool */ public function isPending(): bool; /** * @param bool $isPending * @return self */ public function setPending(bool $isPending): self; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/PlatformTopology/Interfaces/PlatformTopologyServiceInterface.php
centreon/src/Centreon/Domain/PlatformTopology/Interfaces/PlatformTopologyServiceInterface.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\PlatformTopology\Interfaces; use Centreon\Domain\Contact\Interfaces\ContactInterface; use Centreon\Domain\Engine\EngineException; use Centreon\Domain\Exception\EntityNotFoundException; use Centreon\Domain\MonitoringServer\Exception\MonitoringServerException; use Centreon\Domain\PlatformInformation\Exception\PlatformInformationException; use Centreon\Domain\PlatformTopology\Exception\PlatformTopologyException; interface PlatformTopologyServiceInterface { /** * Add new server as a pending platform. * * @param PlatformInterface $platformPending * * @throws MonitoringServerException * @throws EngineException * @throws PlatformTopologyException * @throws EntityNotFoundException * @throws PlatformInformationException * @throws PlatformTopologyRepositoryExceptionInterface */ public function addPendingPlatformToTopology(PlatformInterface $platformPending): void; /** * Get a topology with detailed nodes. * * @throws PlatformTopologyException * @throws EntityNotFoundException * * @return PlatformInterface[] */ public function getPlatformTopology(): array; /** * Get a topology with detailed nodes, according to a user's rights. * * @param ContactInterface $user * * @throws PlatformTopologyException * @throws EntityNotFoundException * * @return PlatformInterface[] */ public function getPlatformTopologyForUser(ContactInterface $user): array; /** * Delete a Platform and allocate its children to top level platform. * * @param int $serverId * * @throws PlatformTopologyException * @throws EntityNotFoundException */ public function deletePlatformAndReallocateChildren(int $serverId): void; /** * Update a platform with given parameters. * * @param PlatformInterface $platform * * @throws PlatformTopologyException */ public function updatePlatformParameters(PlatformInterface $platform): void; /** * Find the top level platform of the topology. * * @throws PlatformTopologyException * * @return PlatformInterface|null */ public function findTopLevelPlatform(): ?PlatformInterface; /** * Determine if the user has access rights to the platform. * * @param ContactInterface $user * @param int $platformId * * @throws \Throwable * * @return bool */ public function isValidPlatform(ContactInterface $user, int $platformId): bool; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/PlatformTopology/Exception/PlatformTopologyException.php
centreon/src/Centreon/Domain/PlatformTopology/Exception/PlatformTopologyException.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\PlatformTopology\Exception; /** * This class is designed to represent a business exception in the 'Platform status' context. * * @package Centreon\Domain\PlatformTopology */ class PlatformTopologyException extends \Exception { /** * @param string $name * @param string $address * @return self */ public static function errorWhenAddingThePlatform(string $name, string $address): self { return new self( sprintf( _("Error when adding in topology the platform : '%s'@'%s'"), $name, $address ) ); } /** * @param string $name * @param string $address * @return self */ public static function missingMandatoryData(string $name, string $address): self { return new self( sprintf( _("Platform : '%s'@'%s' mandatory data are missing. Please check the Remote Access form"), $name, $address ) ); } /** * @param string $name * @param string $address * @return self */ public static function platformNotLinkedToTheCentral(string $name, string $address): self { return new self( sprintf( _("The platform: '%s'@'%s' is not linked to a Central. Please use the wizard first"), $name, $address ) ); } /** * @param string $name * @param string $address * @return self */ public static function missingCentralCredentials(string $name, string $address): self { return new self( sprintf( _("Central's credentials are missing on: '%s'@'%s'. Please check the Remote Access form"), $name, $address ) ); } /** * @param string $name * @param string $address * @return self */ public static function missingCentralScheme(string $name, string $address): self { return new self( sprintf( _("Central's protocol scheme is missing on: '%s'@'%s'. Please check the Remote Access form"), $name, $address ) ); } /** * @param string $name * @param string $address * @return self */ public static function missingCentralPort(string $name, string $address): self { return new self( sprintf( _("Central's protocol port is missing on: '%s'@'%s'. Please check the Remote Access form"), $name, $address ) ); } /** * @param string $name * @param string $address * @return self */ public static function missingCentralPath(string $name, string $address): self { return new self( sprintf( _("Central's path is missing on: '%s'@'%s'. Please check the Remote Access form"), $name, $address ) ); } /** * @return self */ public static function unableToFindMonitoringServerName(): self { return new self( sprintf(_('Unable to find local monitoring server name')) ); } /** * @return self */ public static function unableToFindEngineConfiguration(): self { return new self( sprintf(_('Unable to find the Engine configuration')) ); } /** * @param string $illegalCharacters * @param string $stringToCheck * @return self */ public static function illegalCharacterFound(string $illegalCharacters, string $stringToCheck): self { return new self( sprintf( _("At least one illegal character in '%s' was found in platform's name: '%s'"), $illegalCharacters, $stringToCheck ) ); } /** * @param string $stringToCheck * @return self */ public static function illegalRfcCharacterFound(string $stringToCheck): self { return new self( sprintf( _("At least one non RFC compliant character was found in platform's hostname: '%s'"), $stringToCheck ) ); } /** * Fail to found the platform on the central type parent * @param string $name * @param string $address * @return self */ public static function notFoundOnCentral(string $name, string $address): self { return new self( sprintf( _("The platform '%s'@'%s' cannot be found on the Central"), $name, $address ) ); } /** * @param string $name * @param string $address * @return self */ public static function notTypeRemote(string $name, string $address): self { return new self( sprintf( _("The platform: '%s'@'%s' is not declared as a 'remote'"), $name, $address ) ); } /** * @param string $name * @param string $address * @return self */ public static function addressConflict(string $name, string $address): self { return new self( sprintf( _("Same address and parent_address for platform : '%s'@'%s'"), $name, $address ) ); } /** * @param string $type * @param string $name * @param string $address * @return self */ public static function platformAlreadySaved(string $type, string $name, string $address): self { return new self( sprintf( _("A '%s': '%s'@'%s' is already saved"), $type, $name, $address ) ); } /** * @param string $type * @param string $name * @param string $address * @return self */ public static function platformDoesNotMatchTheSavedOne(string $type, string $name, string $address): self { return new self( sprintf( _("The server type '%s' : '%s'@'%s' does not match the one configured in Centreon or is disabled"), $type, $name, $address ) ); } /** * @param string $name * @param string $address * @return self */ public static function platformNameOrAddressAlreadyExist(string $name, string $address): self { return new self( sprintf( _("A platform using the name : '%s' or address : '%s' already exists"), $name, $address ) ); } /** * @param string $name * @param string $address * @return self */ public static function unableToLinkARemoteToAnotherRemote(string $name, string $address): self { return new self( sprintf( _("Unable to link a 'remote': '%s'@'%s' to another remote platform"), $name, $address ) ); } /** * @param string $type * @param string $name * @param string $address * @param string $parentType * @return self */ public static function inconsistentTypeToLinkThePlatformTo( string $type, string $name, string $address, string $parentType, ): self { return new self( sprintf( _("Cannot register the '%s' platform : '%s'@'%s' behind a '%s' platform"), $type, $name, $address, $parentType ) ); } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Macro/Interfaces/MacroInterface.php
centreon/src/Centreon/Domain/Macro/Interfaces/MacroInterface.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Macro\Interfaces; interface MacroInterface { /** * @return int|null */ public function getId(): ?int; /** * @param int|null $id * @return self */ public function setId(?int $id); /** * @return string|null */ public function getName(): ?string; /** * @param string|null $name * @return self */ public function setName(?string $name); /** * @return string|null */ public function getValue(): ?string; /** * @param string|null $value * @return self */ public function setValue(?string $value); /** * @return bool */ public function isPassword(): bool; /** * @param bool $isPassword * @return self */ public function setPassword(bool $isPassword); /** * @return string|null */ public function getDescription(): ?string; /** * @param string|null $description * @return self */ public function setDescription(?string $description); /** * @return int|null */ public function getOrder(): ?int; /** * @param int|null $order * @return self */ public function setOrder(?int $order); }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Entity/Options.php
centreon/src/Centreon/Domain/Entity/Options.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ namespace Centreon\Domain\Entity; class Options { /** @var string */ private $key; /** @var string */ private $value; /** * @param string $key */ public function setKey(string $key): void { $this->key = $key; } /** * @return string */ public function getKey(): string { return $this->key; } /** * @param string $value */ public function setValue(string $value): void { $this->value = $value; } /** * @return string|null */ public function getValue(): ?string { return $this->value; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Entity/Command.php
centreon/src/Centreon/Domain/Entity/Command.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ namespace Centreon\Domain\Entity; class Command { public const COMMAND_START_IMPEX_WORKER = 'STARTWORKER:1'; public const COMMAND_TRANSFER_EXPORT_FILES = 'SENDEXPORTFILE:'; /** @var string */ private $commandLine; /** * @return string */ public function getCommandLine(): string { return $this->commandLine; } /** * @param string $commandLine */ public function setCommandLine(string $commandLine): void { $this->commandLine = $commandLine; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Entity/EntityCreator.php
centreon/src/Centreon/Domain/Entity/EntityCreator.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Entity; use Centreon\Domain\Annotation\EntityDescriptor; use Centreon\Domain\Contact\Contact; use Centreon\Domain\Service\EntityDescriptorMetadataInterface; use Doctrine\Common\Annotations\AnnotationException; use Doctrine\Common\Annotations\AnnotationReader; use ReflectionClass; use Utility\StringConverter; class EntityCreator { /** @var string Class name to create */ private $className; /** @var array<string, EntityDescriptor[]> */ private static $entityDescriptors; /** @var array<string, \ReflectionMethod[]> */ private static $publicMethods; /** @var Contact */ private static $contact; /** * EntityCreator constructor. * * @param string $className */ public function __construct(string $className) { $this->className = $className; } /** * Create a new object entity based on the given values. * Used to create a new object entity with the values found in the database. * * @param string $className Class name to create * @param array $data Data used to fill the new object entity * @param string|null $prefix The prefix is used to retrieve only certain records when the table contains data * from more than one entity * @throws \Exception * @return mixed Return an new instance of the class */ public static function createEntityByArray(string $className, array $data, ?string $prefix = null) { return (new self($className))->createByArray($data, $prefix); } /** * Set contact * * @param Contact $contact The contact */ public static function setContact(Contact $contact): void { self::$contact = $contact; } /** * Create an entity and complete it according to the data array * * @param array $data Array that contains the data that will be used to complete entity * @param string|null $prefix The prefix is used to retrieve only certain records when the table contains data * from more than one entity * @throws AnnotationException * @throws \ReflectionException * @throws \Exception * @return mixed Return an instance of class according to the class name given into constructor */ public function createByArray(array $data, ?string $prefix = null) { if (! class_exists($this->className)) { throw new \Exception( sprintf(_('The class %s does not exist'), $this->className) ); } $this->readPublicMethod(); $this->readAnnotations(); $objectToSet = (new ReflectionClass($this->className))->newInstance(); if (! empty($prefix)) { // If a prefix is defined, we keep only $data for which the keys start // with the prefix $data = array_filter($data, function ($column) use ($prefix) { return (bool) (str_starts_with($column, $prefix)); }, ARRAY_FILTER_USE_KEY); // Next, we remove the prefix $newData = []; foreach ($data as $column => $value) { $column = substr($column, strlen($prefix)); $newData[$column] = $value; } $data = $newData; } foreach ($data as $column => $value) { if (array_key_exists($column, self::$entityDescriptors[$this->className])) { $descriptor = self::$entityDescriptors[$this->className][$column]; $setterMethod = ($descriptor !== null && $descriptor->modifier !== null) ? $descriptor->modifier : $this->createSetterMethod($column); if (array_key_exists($setterMethod, self::$publicMethods[$this->className])) { $parameters = self::$publicMethods[$this->className][$setterMethod]->getParameters(); if (empty($parameters)) { throw new \Exception( sprintf(_('The public method %s::%s has no parameters'), $this->className, $setterMethod) ); } $firstParameter = $parameters[0]; if ($firstParameter->hasType()) { try { $parameterType = $firstParameter->getType(); if (! $parameterType instanceof \ReflectionNamedType) { throw new \UnexpectedValueException('Not a ReflectionNamedType'); } $value = $this->convertValueBeforeInsert( $value, $parameterType->getName(), $firstParameter->allowsNull() ); } catch (\Exception $error) { throw new \Exception( sprintf( '[%s::%s]: %s', $this->className, $setterMethod, $error->getMessage() ) ); } } call_user_func_array([$objectToSet, $setterMethod], [$value]); } else { throw new \Exception( sprintf( _('The public method %s::%s was not found'), $this->className, $setterMethod ) ); } } } return $objectToSet; } /** * Convert the value according to the type given. * * @param mixed $value Value to convert * @param string $destinationType Destination type * @param bool $allowNull Indicates whether the null value is allowed * @throws \Exception * @return mixed Return the converted value */ private function convertValueBeforeInsert( $value, $destinationType, bool $allowNull = true, ) { if (is_null($value)) { if ($allowNull) { return $value; } throw new \Exception(_('The value cannot be null')); } switch ($destinationType) { case 'double': case 'float': return (float) $value; case 'int': return (int) $value; case 'string': return (string) $value; case 'bool': return (bool) $value; case 'DateTime': if (is_numeric($value)) { $value = (new \DateTime())->setTimestamp((int) $value); if (self::$contact !== null) { $value->setTimezone(self::$contact->getTimezone()); } return $value; } throw new \Exception(_('Numeric value expected')); default: return $value; } } /** * Read the public method of the class. * * @throws \ReflectionException */ private function readPublicMethod(): void { if (isset(self::$publicMethods[$this->className])) { return; } self::$publicMethods[$this->className] = []; $reflectionClass = new ReflectionClass($this->className); foreach ($reflectionClass->getMethods() as $method) { if ($method->isPublic()) { self::$publicMethods[$this->className][$method->getName()] = $method; } } } /** * Read all specific annotations. * * @throws \ReflectionException * @throws AnnotationException */ private function readAnnotations(): void { if (isset(self::$entityDescriptors[$this->className])) { return; } self::$entityDescriptors[$this->className] = []; $reflectionClass = new ReflectionClass($this->className); $properties = $reflectionClass->getProperties(); $reader = new AnnotationReader(); foreach ($properties as $property) { /** @var EntityDescriptor $annotation */ $annotation = $reader->getPropertyAnnotation( $property, EntityDescriptor::class ); $key = ($annotation !== null && $annotation->column !== null) ? $annotation->column : StringConverter::convertCamelCaseToSnakeCase($property->getName()); self::$entityDescriptors[$this->className][$key] = $annotation; } // load entity descriptor data via static method with metadata if ($reflectionClass->isSubclassOf(EntityDescriptorMetadataInterface::class)) { foreach ($this->className::loadEntityDescriptorMetadata() as $column => $modifier) { $descriptor = new EntityDescriptor(); $descriptor->column = $column; $descriptor->modifier = $modifier; self::$entityDescriptors[$this->className][$column] = $descriptor; } } } /** * Returns the name of the setter method based on the property name. * * @param string $property Property name for which we create the setter method * @return string Returns the name of the setter method */ private function createSetterMethod(string $property): string { return 'set' . ucfirst(StringConverter::convertSnakeCaseToCamelCase($property)); } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Entity/ViewImg.php
centreon/src/Centreon/Domain/Entity/ViewImg.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ namespace Centreon\Domain\Entity; class ViewImg { public const TABLE = 'view_img'; /** @var int */ private $imgId; /** @var string */ private $imgName; /** @var string */ private $imgPath; /** @var string */ private $imgComment; public function setImgId(int $imgId): void { $this->imgId = $imgId; } public function getImgId(): int { return $this->imgId; } public function setImgName(string $imgName): void { $this->imgName = $imgName; } public function getImgName(): ?string { return $this->imgName; } public function setImgPath(string $imgPath): void { $this->imgPath = $imgPath; } public function getImgPath(): ?string { return $this->imgPath; } public function setImgComment(string $imgComment): void { $this->imgComment = $imgComment; } public function getImgComment(): ?string { return $this->imgComment; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Entity/CfgCentreonBrokerInfo.php
centreon/src/Centreon/Domain/Entity/CfgCentreonBrokerInfo.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ namespace Centreon\Domain\Entity; /** * Entity to manage broker configuration table : cfg_centreonbroker_info */ class CfgCentreonBrokerInfo { public const TABLE = 'cfg_centreonbroker_info'; /** @var int the linked config id */ private $configId; /** @var string the config group (input, output, log...) */ private $configGroup; /** @var int the config group id (its order in flows listing) */ private $configGroupId; /** @var int the config group level (eg: categories) */ private $configGroupLevel; /** @var string the name of the linked field */ private $configKey; /** @var string the value of the linked field */ private $configValue; public function __construct(string $configKey, string $configValue) { $this->configKey = $configKey; $this->configValue = $configValue; } public function setConfigId(int $configId): void { $this->configId = $configId; } public function getConfigId(): int { return $this->configId; } public function setConfigGroup(string $configGroup): void { $this->configGroup = $configGroup; } public function getConfigGroup(): string { return $this->configGroup; } public function setConfigGroupId(int $configGroupId): void { $this->configGroupId = $configGroupId; } public function getConfigGroupId(): int { return $this->configGroupId; } public function setConfigGroupLevel(int $configGroupLevel): void { $this->configGroupLevel = $configGroupLevel; } public function getConfigGroupLevel(): int { return $this->configGroupLevel; } public function setConfigKey(string $configKey): void { $this->configKey = $configKey; } public function getConfigKey(): string { return $this->configKey; } public function setConfigValue(string $configValue): void { $this->configValue = $configValue; } public function getConfigValue(): string { return $this->configValue; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Entity/CfgResourceInstanceRelations.php
centreon/src/Centreon/Domain/Entity/CfgResourceInstanceRelations.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ namespace Centreon\Domain\Entity; class CfgResourceInstanceRelations { /** * Relation with cfg_resource.id * * @var int */ private $resourceId; /** * Relation with nagios_server.id * * @var int */ private $instanceId; public function setResourceId(int $resourceId): void { $this->resourceId = $resourceId; } public function getResourceId(): int { return $this->resourceId; } public function setInstanceId(int $instanceId): void { $this->instanceId = $instanceId; } public function getInstanceId(): int { return $this->instanceId; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Entity/EntityInterface.php
centreon/src/Centreon/Domain/Entity/EntityInterface.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ namespace Centreon\Domain\Entity; interface EntityInterface { public function toArray(): array; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Entity/Image.php
centreon/src/Centreon/Domain/Entity/Image.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ namespace Centreon\Domain\Entity; use ReflectionClass; use Symfony\Component\Serializer\Annotation as Serializer; class Image { public const TABLE = 'view_img'; public const MEDIA_DIR = 'img/media/'; public const SERIALIZER_GROUP_LIST = 'image-list'; /** @var int */ #[Serializer\SerializedName('id')] #[Serializer\Groups([Image::SERIALIZER_GROUP_LIST])] private $img_id; /** @var string */ #[Serializer\SerializedName('name')] #[Serializer\Groups([Image::SERIALIZER_GROUP_LIST])] private $img_name; /** @var string */ private $img_path; /** @var string */ private $img_comment; /** @var ImageDir */ private $imageDir; /** * Image constructor. */ public function __construct() { $this->imageDir = new ImageDir(); } /** * Load data in entity * * @param string $prop * @param string $val */ public function __set($prop, $val): void { $ref = new ReflectionClass(ImageDir::class); $props = $ref->getProperties(); $propArray = []; foreach ($props as $pro) { $propArray[] = $pro->getName(); } if (in_array($prop, $propArray)) { $this->getImageDir()->{$prop} = $val; } } /** * Alias of getImgId * * @return int|null */ public function getId(): ?int { return $this->getImgId(); } /** * @return string */ #[Serializer\Groups([Image::SERIALIZER_GROUP_LIST])] #[Serializer\SerializedName('preview')] public function getPreview(): string { return static::MEDIA_DIR . $this->getImageDir()->getDirName() . '/' . $this->getImgPath(); } /** * @return int|null */ public function getImgId(): ?int { return $this->img_id; } /** * @param int $id */ public function setImgId(int $id): void { $this->img_id = $id; } /** * @return string|null */ public function getImgName(): ?string { return $this->img_name; } /** * @param string $name */ public function setImgName(?string $name = null): void { $this->img_name = $name; } /** * @return string|null */ public function getImgPath(): ?string { return $this->img_path; } /** * @param string $path */ public function setImgPath(?string $path = null): void { $this->img_path = $path; } /** * @return string|null */ public function getImgComment(): ?string { return $this->img_comment; } /** * @param string $comment */ public function setImgComment(?string $comment = null): void { $this->img_comment = $comment; } /** * @return ImageDir */ public function getImageDir(): ImageDir { return $this->imageDir; } /** * @param ImageDir $imageDir */ public function setImageDir(?ImageDir $imageDir = null): void { $this->imageDir = $imageDir; } /** * begin setters for subclass */ /** * @param int $dirId */ public function setDirId(?int $dirId = null): void { $this->getImageDir()->setDirId($dirId); } /** * @param string $dirName */ public function setDirName(?string $dirName = null): void { $this->getImageDir()->setDirName($dirName); } /** * @param string $dirAlias */ public function setDirAlias(?string $dirAlias = null): void { $this->getImageDir()->setDirAlias($dirAlias); } /** * @param string $dirComment */ public function setDirComment(?string $dirComment = null): void { $this->getImageDir()->setDirComment($dirComment); } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Entity/ContactGroup.php
centreon/src/Centreon/Domain/Entity/ContactGroup.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ namespace Centreon\Domain\Entity; use Symfony\Component\Serializer\Annotation as Serializer; /** * ContactGroup entity * * @codeCoverageIgnore */ class ContactGroup { public const SERIALIZER_GROUP_LIST = 'contact-group-list'; public const TABLE = 'contactgroup'; public const ENTITY_IDENTIFICATOR_COLUMN = 'cg_id'; /** @var int|null */ #[Serializer\SerializedName('id')] #[Serializer\Groups([ContactGroup::SERIALIZER_GROUP_LIST])] private $cg_id; /** @var string|null */ #[Serializer\SerializedName('name')] #[Serializer\Groups([ContactGroup::SERIALIZER_GROUP_LIST])] private $cg_name; /** @var string|null */ private $cg_alias; /** @var string|null */ private $cg_comment; /** @var string|null */ private $cg_type; /** @var string|null */ private $cg_ldap_dn; /** @var int|null */ private $ar_id; /** @var string|null */ #[Serializer\SerializedName('activate')] #[Serializer\Groups([ContactGroup::SERIALIZER_GROUP_LIST])] private $cg_activate; /** * Alias of getCgId * * @return int|null */ public function getId(): ?int { return $this->getCgId(); } /** * @return int|null */ public function getCgId(): ?int { return $this->cg_id; } /** * @param int|null $cgId */ public function setCgId(?int $cgId = null): void { $this->cg_id = $cgId; } /** * @return string|null */ public function getCgName(): ?string { return $this->cg_name; } /** * @param string|null $cgName */ public function setCgName(?string $cgName = null): void { $this->cg_name = $cgName; } /** * @return string|null */ public function getCgAlias(): ?string { return $this->cg_alias; } /** * @param string|null $cgAlias */ public function setCgAlias(?string $cgAlias = null): void { $this->cg_alias = $cgAlias; } /** * @return int */ public function getCgActivate(): int { return (int) $this->cg_activate; } /** * @param string|null $cgActivate */ public function setCgActivate(?string $cgActivate = null): void { $this->cg_activate = $cgActivate; } /** * @return string */ public function getCgComment(): ?string { return $this->cg_comment; } /** * @param string|null $cgComment */ public function setCgComment(?string $cgComment = null): void { $this->cg_comment = $cgComment; } /** * @return string|null */ public function getCgType(): ?string { return $this->cg_type; } /** * @param string|null $cgType */ public function setCgType(?string $cgType = null): void { $this->cg_type = $cgType; } /** * @return string|null */ public function getCgLdapDn(): ?string { return $this->cg_ldap_dn; } /** * @param string|null $cgLdapDn */ public function setCgLdapDn(?string $cgLdapDn = null): void { $this->cg_ldap_dn = $cgLdapDn; } /** * @return int|null */ public function getArId(): ?int { return $this->ar_id; } /** * @param int|null $arId */ public function setArId(?int $arId = null): void { $this->ar_id = $arId; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Entity/CfgResource.php
centreon/src/Centreon/Domain/Entity/CfgResource.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ namespace Centreon\Domain\Entity; class CfgResource { /** @var int */ private $resourceId; /** @var string */ private $resourceName; /** @var string */ private $resourceLine; /** @var string */ private $resourceComment; /** @var bool */ private $resourceActivate; public function setResourceId(int $resourceId): void { $this->resourceId = $resourceId; } public function getResourceId(): int { return $this->resourceId; } public function setResourceName(string $resourceName): void { $this->resourceName = $resourceName; } public function getResourceName(): string { return $this->resourceName; } public function setResourceLine(string $resourceLine): void { $this->resourceLine = $resourceLine; } public function getResourceLine(): string { return $this->resourceLine; } public function setResourceComment(string $resourceComment): void { $this->resourceComment = $resourceComment; } public function getResourceComment(): string { return $this->resourceComment; } public function setResourceActivate(bool $resourceActivate): void { $this->resourceActivate = (bool) $resourceActivate; } public function getResourceActivate(): bool { return (bool) $this->resourceActivate; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Entity/ViewImgDir.php
centreon/src/Centreon/Domain/Entity/ViewImgDir.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ namespace Centreon\Domain\Entity; class ViewImgDir { public const TABLE = 'view_img_dir'; /** @var int */ private $dirId; /** @var string */ private $dirName; /** @var string */ private $dirAlias; /** @var string */ private $dirComment; public function setDirId(int $dirId): void { $this->dirId = $dirId; } public function getDirId(): int { return $this->dirId; } public function setDirName(string $dirName): void { $this->dirName = $dirName; } public function getDirName(): ?string { return $this->dirName; } public function setDirAlias(string $dirAlias): void { $this->dirAlias = $dirAlias; } public function getDirAlias(): ?string { return $this->dirAlias; } public function setDirComment(?string $dirComment = null): void { $this->dirComment = $dirComment; } public function getDirComment(): ?string { return $this->dirComment; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Entity/ImageDir.php
centreon/src/Centreon/Domain/Entity/ImageDir.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ namespace Centreon\Domain\Entity; /** * Subclass of Image */ class ImageDir { public const TABLE = 'view_img_dir'; public const JOIN_TABLE = 'view_img_dir_relation'; /** @var int */ public $dir_id; /** @var string */ public $dir_name; /** @var string */ public $dir_alias; /** @var string */ public $dir_comment; /** * @return int */ public function getDirId(): int { return $this->dir_id; } /** * @param int $dirId */ public function setDirId(int $dirId): void { $this->dir_id = $dirId; } /** * @return string|null */ public function getDirName(): ?string { return $this->dir_name; } /** * @param string|null $dirName */ public function setDirName(?string $dirName = null): void { $this->dir_name = $dirName; } /** * @return string|null */ public function getDirAlias(): ?string { return $this->dir_alias; } /** * @param string|null $dirAlias */ public function setDirAlias(?string $dirAlias = null): void { $this->dir_alias = $dirAlias; } /** * @return string|null */ public function getDirComment(): ?string { return $this->dir_comment; } /** * @param string|null $dirComment */ public function setDirComment(?string $dirComment = null): void { $this->dir_comment = $dirComment; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Entity/Informations.php
centreon/src/Centreon/Domain/Entity/Informations.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ namespace Centreon\Domain\Entity; class Informations { /** @var string */ private $key; /** @var string */ private $value; /** * @return string */ public function getKey(): string { return $this->key; } /** * @param string $key */ public function setKey(string $key): void { $this->key = $key; } /** * @return string */ public function getValue(): string { return $this->value; } /** * @param string $value */ public function setValue(string $value): void { $this->value = $value; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Entity/AclGroup.php
centreon/src/Centreon/Domain/Entity/AclGroup.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ namespace Centreon\Domain\Entity; use Centreon\Infrastructure\CentreonLegacyDB\Mapping; use PDO; use Symfony\Component\Serializer\Annotation as Serializer; /** * ACL group entity * * @codeCoverageIgnore */ class AclGroup implements Mapping\MetadataInterface { public const SERIALIZER_GROUP_LIST = 'acl-group-list'; public const ENTITY_IDENTIFICATOR_COLUMN = 'acl_group_id'; public const TABLE = 'acl_groups'; /** @var int an identification of entity */ #[Serializer\Groups([AclGroup::SERIALIZER_GROUP_LIST])] private $id; /** @var string */ #[Serializer\Groups([AclGroup::SERIALIZER_GROUP_LIST])] private $name; /** @var string */ #[Serializer\Groups([AclGroup::SERIALIZER_GROUP_LIST])] private $alias; /** @var bool */ #[Serializer\Groups([AclGroup::SERIALIZER_GROUP_LIST])] private $changed; /** @var bool */ #[Serializer\Groups([AclGroup::SERIALIZER_GROUP_LIST])] private $activate; /** * {@inheritDoc} */ public static function loadMetadata(Mapping\ClassMetadata $metadata): void { $metadata->setTableName(static::TABLE) ->add('id', 'acl_group_id', PDO::PARAM_INT, null, true) ->add('name', 'acl_group_name', PDO::PARAM_STR) ->add('alias', 'acl_group_alias', PDO::PARAM_STR) ->add('changed', 'acl_group_changed', PDO::PARAM_INT) ->add('activate', 'acl_group_activate', PDO::PARAM_STR); // enum } /** * @param string|int $id * @return void */ public function setId($id): void { $this->id = $id; } /** * @return int|null */ public function getId(): ?int { return $this->id; } /** * @return string */ public function getName(): ?string { return $this->name; } /** * @param string $name */ public function setName($name): void { $this->name = $name; } /** * @return string */ public function getAlias(): ?string { return $this->alias; } /** * @param string $alias */ public function setAlias($alias = null): void { $this->alias = $alias; } /** * @return bool */ public function getChanged(): ?bool { return $this->changed; } /** * @param bool $changed */ public function setChanged($changed = null): void { $this->changed = $changed; } /** * @return bool */ public function getActivate(): ?bool { return $this->activate; } /** * @param bool $activate */ public function setActivate($activate = null): void { $this->activate = $activate; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Entity/NagiosServer.php
centreon/src/Centreon/Domain/Entity/NagiosServer.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ namespace Centreon\Domain\Entity; use Centreon\Infrastructure\CentreonLegacyDB\Mapping; use PDO; use Symfony\Component\Serializer\Annotation as Serializer; class NagiosServer implements Mapping\MetadataInterface { public const TABLE = 'nagios_server'; public const ENTITY_IDENTIFICATOR_COLUMN = 'id'; public const SERIALIZER_GROUP_REMOTE_LIST = 'nagios-server-remote-list'; public const SERIALIZER_GROUP_LIST = 'nagios-server-list'; /** @var int */ #[Serializer\Groups([NagiosServer::SERIALIZER_GROUP_REMOTE_LIST, NagiosServer::SERIALIZER_GROUP_LIST])] private $id; /** @var string */ #[Serializer\Groups([NagiosServer::SERIALIZER_GROUP_REMOTE_LIST, NagiosServer::SERIALIZER_GROUP_LIST])] private $name; /** @var string */ #[Serializer\Groups([NagiosServer::SERIALIZER_GROUP_LIST])] private $localhost; /** @var int */ #[Serializer\SerializedName('default')] #[Serializer\Groups([NagiosServer::SERIALIZER_GROUP_LIST])] private $isDefault; /** @var int */ private $lastRestart; /** @var string */ #[Serializer\SerializedName('ip')] #[Serializer\Groups([NagiosServer::SERIALIZER_GROUP_REMOTE_LIST])] private $nsIpAddress; /** @var string */ #[Serializer\SerializedName('activate')] #[Serializer\Groups([NagiosServer::SERIALIZER_GROUP_LIST])] private $nsActivate; /** @var string */ private $engineStartCommand; /** @var string */ private $engineStopCommand; /** @var string */ private $engineRestartCommand; /** @var string */ private $engineReloadCommand; /** @var string */ private $nagiosBin; /** @var string */ private $nagiostatsBin; /** @var string */ private $nagiosPerfdata; /** @var string */ private $brokerReloadCommand; /** @var string */ private $centreonbrokerCfgPath; /** @var string */ private $centreonbrokerModulePath; /** @var string */ private $centreonconnectorPath; /** @var int */ private $gorgoneCommunicationType; /** @var int */ private $sshPort; /** @var int */ private $gorgonePort; /** @var string */ private $initScriptCentreontrapd; /** @var string */ private $snmpTrapdPathConf; /** @var string */ private $engineName; /** @var string */ private $engineVersion; /** @var string */ private $centreonbrokerLogsPath; /** @var int */ private $remoteId; /** @var string */ private $remoteServerUseAsProxy; /** * {@inheritDoc} */ public static function loadMetadata(Mapping\ClassMetadata $metadata): void { $metadata->setTableName('nagios_server') ->add('id', 'id', PDO::PARAM_INT, null, true) ->add('name', 'name') ->add('localhost', 'localhost') ->add('isDefault', 'is_default', PDO::PARAM_INT) ->add('lastRestart', 'last_restart', PDO::PARAM_INT) ->add('nsIpAddress', 'ns_ip_address') ->add('nsActivate', 'ns_activate') ->add('engineStartCommand', 'engine_start_command') ->add('engineStopCommand', 'engine_stop_command') ->add('engineRestartCommand', 'engine_restart_command') ->add('engineReloadCommand', 'engine_reload_command') ->add('nagiosBin', 'nagios_bin') ->add('nagiostatsBin', 'nagiostats_bin') ->add('nagiosPerfdata', 'nagios_perfdata') ->add('brokerReloadCommand', 'broker_reload_command') ->add('centreonbrokerCfgPath', 'centreonbroker_cfg_path') ->add('centreonbrokerModulePath', 'centreonbroker_module_path') ->add('centreonconnectorPath', 'centreonconnector_path') ->add('sshPort', 'ssh_port', PDO::PARAM_INT) ->add('gorgoneCommunicationType', 'gorgone_communication_type', PDO::PARAM_INT) ->add('gorgonePort', 'gorgone_port', PDO::PARAM_INT) ->add('initScriptCentreontrapd', 'init_script_centreontrapd') ->add('snmpTrapdPathConf', 'snmp_trapd_path_conf') ->add('engineName', 'engine_name') ->add('engineVersion', 'engine_version') ->add('centreonbrokerLogsPath', 'centreonbroker_logs_path') ->add('remoteId', 'remote_id', PDO::PARAM_INT) ->add('remoteServerUseAsProxy', 'remote_server_use_as_proxy'); } /** * @return int|null */ public function getId(): ?int { return $this->id; } /** * @param string|int $id * @return void */ public function setId($id = null): void { $this->id = (int) $id; } /** * @return string|null */ public function getName(): ?string { return $this->name; } /** * @param string $name * @return void */ public function setName(?string $name = null): void { $this->name = $name; } /** * @return string|null */ public function getLocalhost(): ?string { return $this->localhost; } /** * @return int|null */ public function getIsDefault(): ?int { return $this->isDefault; } /** * @return int|null */ public function getLastRestart(): ?int { return $this->lastRestart; } /** * @return string|null */ public function getNsIpAddress(): ?string { return $this->nsIpAddress; } /** * @return string|null */ public function getNsActivate(): ?string { return $this->nsActivate; } /** * @return string|null */ public function getEngineStartCommand(): ?string { return $this->engineStartCommand; } /** * @return string|null */ public function getEngineStopCommand(): ?string { return $this->engineStopCommand; } /** * @return string|null */ public function getEngineRestartCommand(): ?string { return $this->engineRestartCommand; } /** * @return string|null */ public function getEngineReloadCommand(): ?string { return $this->engineReloadCommand; } /** * @return string|null */ public function getNagiosBin(): ?string { return $this->nagiosBin; } /** * @return string|null */ public function getNagiostatsBin(): ?string { return $this->nagiostatsBin; } /** * @return string|null */ public function getNagiosPerfdata(): ?string { return $this->nagiosPerfdata; } /** * @return string|null */ public function getBrokerReloadCommand(): ?string { return $this->brokerReloadCommand; } /** * @return string|null */ public function getCentreonbrokerCfgPath(): ?string { return $this->centreonbrokerCfgPath; } /** * @return string|null */ public function getCentreonbrokerModulePath(): ?string { return $this->centreonbrokerModulePath; } /** * @return string|null */ public function getCentreonconnectorPath(): ?string { return $this->centreonconnectorPath; } /** * @return int|null */ public function getSshPort(): ?int { return $this->sshPort; } /** * @return int|null */ public function getGorgoneCommunicationType(): ?int { return $this->gorgoneCommunicationType; } /** * @return int|null */ public function getGorgonePort(): ?int { return $this->gorgonePort; } /** * @return string|null */ public function getInitScriptCentreontrapd(): ?string { return $this->initScriptCentreontrapd; } /** * @return string|null */ public function getSnmpTrapdPathConf(): ?string { return $this->snmpTrapdPathConf; } /** * @return string|null */ public function getEngineName(): ?string { return $this->engineName; } /** * @return string|null */ public function getEngineVersion(): ?string { return $this->engineVersion; } /** * @return string|null */ public function getCentreonbrokerLogsPath(): ?string { return $this->centreonbrokerLogsPath; } /** * @return int|null */ public function getRemoteId(): ?int { return $this->remoteId; } /** * @return string|null */ public function getRemoteServerUseAsProxy(): ?string { return $this->remoteServerUseAsProxy; } /** * @param string $localhost * @return void */ public function setLocalhost(?string $localhost = null): void { $this->localhost = $localhost; } /** * @param string|int $isDefault * @return void */ public function setIsDefault($isDefault = null): void { $this->isDefault = (int) $isDefault; } /** * @param string|int $lastRestart * @return void */ public function setLastRestart($lastRestart = null): void { $this->lastRestart = (int) $lastRestart; } /** * @param string $nsIpAddress * @return void */ public function setNsIpAddress(?string $nsIpAddress = null): void { $this->nsIpAddress = $nsIpAddress; } /** * @param string $nsActivate * @return void */ public function setNsActivate(?string $nsActivate = null): void { $this->nsActivate = $nsActivate; } /** * @param string $engineStartCommand * @return void */ public function setEngineStartCommand(?string $engineStartCommand = null): void { $this->engineStartCommand = $engineStartCommand; } /** * @param string $engineStopCommand * @return void */ public function setEngineStopCommand(?string $engineStopCommand = null): void { $this->engineStopCommand = $engineStopCommand; } /** * @param string $engineRestartCommand * @return void */ public function setEngineRestartCommand(?string $engineRestartCommand = null): void { $this->engineRestartCommand = $engineRestartCommand; } /** * @param string $engineReloadCommand * @return void */ public function setEngineReloadCommand(?string $engineReloadCommand = null): void { $this->engineReloadCommand = $engineReloadCommand; } /** * @param string $nagiosBin * @return void */ public function setNagiosBin(?string $nagiosBin = null): void { $this->nagiosBin = $nagiosBin; } /** * @param string $nagiostatsBin * @return void */ public function setNagiostatsBin(?string $nagiostatsBin = null): void { $this->nagiostatsBin = $nagiostatsBin; } /** * @param string $nagiosPerfdata * @return void */ public function setNagiosPerfdata(?string $nagiosPerfdata = null): void { $this->nagiosPerfdata = $nagiosPerfdata; } /** * @param string $brokerReloadCommand * @return void */ public function setBrokerReloadCommand(?string $brokerReloadCommand = null): void { $this->brokerReloadCommand = $brokerReloadCommand; } /** * @param string $centreonbrokerCfgPath * @return void */ public function setCentreonbrokerCfgPath(?string $centreonbrokerCfgPath = null): void { $this->centreonbrokerCfgPath = $centreonbrokerCfgPath; } /** * @param string $centreonbrokerModulePath * @return void */ public function setCentreonbrokerModulePath(?string $centreonbrokerModulePath = null): void { $this->centreonbrokerModulePath = $centreonbrokerModulePath; } /** * @param string $centreonconnectorPath * @return void */ public function setCentreonconnectorPath(?string $centreonconnectorPath = null): void { $this->centreonconnectorPath = $centreonconnectorPath; } /** * @param string|int $sshPort * @return void */ public function setSshPort($sshPort = null): void { $this->sshPort = (int) $sshPort; } /** * @param string|int $gorgoneCommunicationType * @return void */ public function setGorgoneCommunicationType($gorgoneCommunicationType = null): void { $this->gorgoneCommunicationType = (int) $gorgoneCommunicationType; } /** * @param string|int $gorgonePort * @return void */ public function setGorgonePort($gorgonePort = null): void { $this->gorgonePort = (int) $gorgonePort; } /** * @param string $initScriptCentreontrapd * @return void */ public function setInitScriptCentreontrapd(?string $initScriptCentreontrapd = null): void { $this->initScriptCentreontrapd = $initScriptCentreontrapd; } /** * @param string $snmpTrapdPathConf * @return void */ public function setSnmpTrapdPathConf(?string $snmpTrapdPathConf = null): void { $this->snmpTrapdPathConf = $snmpTrapdPathConf; } /** * @param string $engineName * @return void */ public function setEngineName(?string $engineName = null): void { $this->engineName = $engineName; } /** * @param string $engineVersion * @return void */ public function setEngineVersion(?string $engineVersion = null): void { $this->engineVersion = $engineVersion; } /** * @param string $centreonbrokerLogsPath * @return void */ public function setCentreonbrokerLogsPath(?string $centreonbrokerLogsPath = null): void { $this->centreonbrokerLogsPath = $centreonbrokerLogsPath; } /** * @param string|int $remoteId * @return void */ public function setRemoteId($remoteId = null): void { $this->remoteId = (int) $remoteId; } /** * @param string $remoteServerUseAsProxy * @return void */ public function setRemoteServerUseAsProxy(?string $remoteServerUseAsProxy = null): void { $this->remoteServerUseAsProxy = $remoteServerUseAsProxy; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Entity/EntityValidator.php
centreon/src/Centreon/Domain/Entity/EntityValidator.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Entity; use Symfony\Component\Finder\Finder; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\Constraints\All; use Symfony\Component\Validator\Constraints\Collection; use Symfony\Component\Validator\Constraints\Composite; use Symfony\Component\Validator\Constraints\GroupSequence; use Symfony\Component\Validator\Constraints\Type; use Symfony\Component\Validator\ConstraintViolationInterface; use Symfony\Component\Validator\ConstraintViolationList; use Symfony\Component\Validator\ConstraintViolationListInterface; use Symfony\Component\Validator\Mapping\CascadingStrategy; use Symfony\Component\Validator\Mapping\Loader\YamlFileLoader; use Symfony\Component\Validator\Mapping\Loader\YamlFilesLoader; use Symfony\Component\Validator\Validation; use Symfony\Component\Validator\Validator\ValidatorInterface; class EntityValidator { /** @var ValidatorInterface */ private $validator; /** @var bool */ private $allowExtraFields; /** @var bool */ private $allowMissingFields; /** * EntityValidator constructor. * * @param string $validationFilePath Path of the validator configuration file */ public function __construct(string $validationFilePath) { $validation = Validation::createValidatorBuilder(); if (is_file($validationFilePath)) { $validation->addLoader( new YamlFileLoader($validationFilePath) ); } elseif (is_dir($validationFilePath)) { $finder = (new Finder()) ->in($validationFilePath) ->filter(function (\SplFileInfo $file) { return $file->getExtension() == 'yaml'; }) ->files(); if ($finder->hasResults()) { $paths = []; foreach ($finder as $yamlConfigurationFiles) { /** @var \SplFileInfo $yamlConfigurationFiles */ $paths[] = $yamlConfigurationFiles->getRealPath(); } $validation->addLoader( new YamlFilesLoader($paths) ); } } $this->validator = $validation->getValidator(); } /** * Indicates whether validation rules exist for the name of the given entity. * * @param string $entityName Entity name * @return bool */ public function hasValidatorFor(string $entityName): bool { return $this->validator->hasMetadataFor($entityName); } /** * We validate a list of parameters according to the path of the given entity. * The purpose is to translate the configuration of the validator entity so * that it can be used with a list of parameters. * * @param string $entityName Entity name * @param array $dataToValidate Data to validate * @param array $groups Rule groups * @param bool $allowExtraFields If TRUE, errors will show on not expected fields (by default) * @param bool $allowMissingFields If FALSE, errors will show on missing fields (by default) * @return ConstraintViolationListInterface */ public function validateEntity( string $entityName, array $dataToValidate, array $groups = ['Default'], bool $allowExtraFields = true, bool $allowMissingFields = false, ): ConstraintViolationListInterface { if ($groups === []) { $groups[] = Constraint::DEFAULT_GROUP; } $this->allowExtraFields = $allowExtraFields; $this->allowMissingFields = $allowMissingFields; $violations = new ConstraintViolationList(); if ($this->hasValidatorFor($entityName)) { $assertCollection = $this->getConstraints($entityName, $groups, true); $violations->addAll( $this->validator->validate( $dataToValidate, $assertCollection, $groups ) ); } return $this->removeDuplicatedViolation($violations); } /** * @param $object * @param Constraint|Constraint[] $constraints * @param string|GroupSequence|(string|GroupSequence)[]|null $groups * @return ConstraintViolationListInterface */ public function validate($object, $constraints = null, $groups = null): ConstraintViolationListInterface { return $this->validator->validate($object, $constraints, $groups); } /** * @return ValidatorInterface */ public function getValidator(): ValidatorInterface { return $this->validator; } /** * Formats errors to be more readable. * * @param ConstraintViolationListInterface $violations * @param bool $showPropertiesInSnakeCase Set TRUE to convert the properties name into snake case * @return string List of error messages */ public static function formatErrors( ConstraintViolationListInterface $violations, bool $showPropertiesInSnakeCase = false, ): string { $errorMessages = ''; /** @var array<ConstraintViolationInterface> $violations */ foreach ($violations as $violation) { if (! empty($errorMessages)) { $errorMessages .= "\n"; } $propertyName = $violation->getPropertyPath(); if ($propertyName[0] == '[' && $propertyName[strlen($propertyName) - 1] == ']') { $propertyName = str_replace('][', '.', $propertyName); $propertyName = substr($propertyName, 1, -1); } $errorMessages .= sprintf( 'Error on \'%s\': %s', (($showPropertiesInSnakeCase) ? self::convertCamelCaseToSnakeCase($propertyName) : $violation->getPropertyPath()), $violation->getMessage() ); } return $errorMessages; } /** * Gets constraints found in the validation rules. * * @param string $entityName Entity name for which we want to get constraints * @param array $groups NRule groups * @param bool $firstCall * @return Collection Returns a constraints collection object */ private function getConstraints(string $entityName, array $groups, bool $firstCall = false): Composite { /** @var \Symfony\Component\Validator\Mapping\ClassMetadata $metadata */ $metadata = $this->validator->getMetadataFor($entityName); $constraints = []; foreach ($metadata->getConstrainedProperties() as $id) { $propertyMetadatas = $metadata->getPropertyMetadata($id); // We need to convert camel case to snake case because the data sent // are in snake case format whereas the validation definition file // use the real name of properties (camel case) $id = self::convertCamelCaseToSnakeCase($id); if (! empty($propertyMetadatas)) { $propertyMetadata = $propertyMetadatas[0]; if ($propertyMetadata->getCascadingStrategy() == CascadingStrategy::CASCADE) { foreach ($propertyMetadata->getConstraints() as $constraint) { if ($constraint instanceof Type) { $constraints[$id] = $this->getConstraints($constraint->type, $groups); } elseif ($constraint instanceof All) { $type = $this->findTypeConstraint($constraint->constraints); if ($type !== null) { $constraints[$id] = new All($this->getConstraints($type, $groups)); } } } } else { foreach ($groups as $group) { $currentConstraint = $propertyMetadata->findConstraints($group); if (empty($currentConstraint)) { continue; } if (array_key_exists($id, $constraints)) { $constraints[$id] = array_merge( $constraints[$id], $propertyMetadata->findConstraints($group) ); } else { $constraints[$id] = $propertyMetadata->findConstraints($group); } } } } } if ($firstCall) { return new Collection([ 'fields' => $constraints, 'allowExtraFields' => $this->allowExtraFields, 'allowMissingFields' => $this->allowMissingFields, ]); } return new Collection($constraints); } /** * @param ConstraintViolationListInterface $violations * @return ConstraintViolationListInterface */ private function removeDuplicatedViolation( ConstraintViolationListInterface $violations, ): ConstraintViolationListInterface { /** @var array<int, ConstraintViolationInterface> $violationCodes */ $violationCodes = []; foreach ($violations as $index => $violation) { if (! array_key_exists($violation->getPropertyPath(), $violationCodes) || ! in_array($violation->getCode(), $violationCodes[$violation->getPropertyPath()]) ) { $violationCodes[$violation->getPropertyPath()][] = $violation->getCode(); } else { $violations->remove($index); } } return $violations; } /** * Find the 'Type' constraint from the constraints list. * * @param Constraint[] $constraints Constraints list for which we want to find the 'Type' constraint * @return string|null */ private function findTypeConstraint(array $constraints): ?string { foreach ($constraints as $constraint) { if ($constraint instanceof Type) { return $constraint->type; } } return null; } /** * Convert a string from camel case to snake case. * * @param string $stringToConvert String to convert * @return string */ private static function convertCamelCaseToSnakeCase(string $stringToConvert): string { return strtolower(preg_replace('/[A-Z]/', '_\\0', lcfirst($stringToConvert))); } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Entity/Listener.php
centreon/src/Centreon/Domain/Entity/Listener.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ namespace Centreon\Domain\Entity; class Listener { /** @var int */ private $event; /** @var callable */ private $action; public function __construct(int $event, callable $action) { $this->event = $event; $this->action = $action; } /** * @return int */ public function getEvent(): int { return $this->event; } /** * @param int $event */ public function setEvent(int $event): void { $this->event = $event; } /** * @return callable */ public function getAction(): callable { return $this->action; } /** * @param callable $action */ public function setAction(callable $action): void { $this->action = $action; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Entity/Topology.php
centreon/src/Centreon/Domain/Entity/Topology.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Entity; class Topology { public const ENTITY_IDENTIFICATOR_COLUMN = 'topology_id'; public const TABLE = 'topology'; protected int $topology_id; protected ?string $topology_name = null; protected ?int $topology_parent = null; protected ?string $topology_page = null; protected ?int $topology_order = null; protected ?int $topology_group = null; protected ?string $topology_url = null; protected ?string $topology_url_opt = null; /** @var ?string enum('0','1') */ protected ?string $topology_popup = null; /** @var ?string enum('0','1') */ protected ?string $topology_modules = null; /** @var string enum('0','1') */ protected ?string $topology_show = null; protected bool $is_deprecated = false; protected ?string $topology_style_class = null; protected ?string $topology_style_id = null; protected ?string $topology_OnClick = null; protected ?string $topology_feature_flag = null; /** @var string enum('0','1') */ protected string $readonly; /** @var string enum('0','1') */ protected string $is_react; public function getTopologyId(): ?int { return $this->topology_id; } public function setTopologyId(int $topology_id): void { $this->topology_id = $topology_id; } public function getTopologyName(): ?string { // get translated menu entry return _($this->topology_name); } public function setTopologyName(?string $topology_name): void { $this->topology_name = $topology_name; } public function getTopologyParent(): ?int { return $this->topology_parent; } public function setTopologyParent(?int $topology_parent): void { $this->topology_parent = $topology_parent; } public function getTopologyPage(): ?string { return $this->topology_page; } public function setTopologyPage(?string $topology_page): void { $this->topology_page = $topology_page; } public function getTopologyOrder(): ?int { return $this->topology_order; } public function setTopologyOrder(?int $topology_order): void { $this->topology_order = $topology_order; } public function getTopologyGroup(): ?int { return $this->topology_group; } public function setTopologyGroup(?int $topology_group): void { $this->topology_group = $topology_group; } public function getTopologyUrl(): ?string { return $this->topology_url; } public function setTopologyUrl(?string $topology_url): void { $this->topology_url = $topology_url; } public function getTopologyUrlOpt(): ?string { return $this->topology_url_opt; } public function setTopologyUrlOpt(?string $topology_url_opt): void { $this->topology_url_opt = $topology_url_opt; } public function getTopologyPopup(): ?string { return $this->topology_popup; } /** * @phpstan-param '0'|'1'|null $topology_popup * * @param string|null $topology_popup */ public function setTopologyPopup(?string $topology_popup): void { $this->topology_popup = $topology_popup; } public function getTopologyModules(): ?string { return $this->topology_modules; } /** * @phpstan-param '0'|'1'|null $topology_modules * * @param string|null $topology_modules */ public function setTopologyModules(?string $topology_modules): void { $this->topology_modules = $topology_modules; } public function getTopologyShow(): ?string { return $this->topology_show; } /** * @phpstan-param '0'|'1' $topology_show * * @param string $topology_show */ public function setTopologyShow(string $topology_show): void { $this->topology_show = $topology_show; } public function getIsDeprecated(): bool { return $this->is_deprecated; } public function setIsDeprecated(string $isDeprecated): void { if (in_array($isDeprecated, ['0', '1'], true)) { throw new \InvalidArgumentException('deprecated parameter must be "0" or "1"'); } $this->is_deprecated = (bool) $isDeprecated; } public function getTopologyStyleClass(): ?string { return $this->topology_style_class; } public function setTopologyStyleClass(?string $topology_style_class): void { $this->topology_style_class = $topology_style_class; } public function getTopologyStyleId(): ?string { return $this->topology_style_id; } public function setTopologyStyleId(?string $topology_style_id): void { $this->topology_style_id = $topology_style_id; } public function getReadonly(): ?string { return $this->readonly; } /** * @phpstan-param '0'|'1' $readonly * * @param string $readonly */ public function setReadonly(string $readonly): void { $this->readonly = $readonly; } public function getIsReact(): ?string { return $this->is_react; } /** * @phpstan-param '0'|'1' $is_react * * @param string $is_react */ public function setIsReact(string $is_react): void { $this->is_react = $is_react; } public function getTopologyOnClick(): ?string { return $this->topology_OnClick; } public function setTopologyOnClick(?string $topology_OnClick): void { $this->topology_OnClick = $topology_OnClick; } public function getTopologyFeatureFlag(): ?string { return $this->topology_feature_flag; } public function setTopologyFeatureFlag(?string $topology_feature_flag): void { $this->topology_feature_flag = $topology_feature_flag; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Entity/Task.php
centreon/src/Centreon/Domain/Entity/Task.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ namespace Centreon\Domain\Entity; use ReflectionClass; class Task implements EntityInterface { /** * Task types */ public const TYPE_EXPORT = 'export'; public const TYPE_IMPORT = 'import'; public const TYPE_VERIFY = 'verify'; /** * Task states */ public const STATE_PENDING = 'pending'; public const STATE_PROGRESS = 'inprogress'; public const STATE_COMPLETED = 'completed'; public const STATE_FAILED = 'failed'; /** * Task type * @var string */ private $type; /** * Autoincrement ID * @var int */ private $id; /** * Task status * @var string */ private $status; /** @var \DateTime */ private $createdAt; /** @var int */ private $parent_id; /** @var \DateTime */ private $completedAt; /** * Parameters to be serialized into DB that define task options * @var string */ private $params; public function __construct() { $this->createdAt = new \DateTime(); } /** * @return int */ public function getId(): int { return $this->id; } /** * @param int $id */ public function setId(int $id): void { $this->id = $id; } /** * @return string */ public function getType(): string { return $this->type; } /** * @param string $type */ public function setType(string $type): void { $this->type = $type; } /** * @return string */ public function getStatus(): string { return $this->status; } /** * @param string $status */ public function setStatus(string $status): void { $this->status = $status; } /** * @return \DateTime */ public function getCreatedAt(): \DateTime { return $this->createdAt; } /** * @param \DateTime $createdAt */ public function setCreatedAt(\DateTime $createdAt): void { $this->createdAt = $createdAt; } /** * @return \DateTime */ public function getCompletedAt(): \DateTime { return $this->completedAt; } /** * @param \DateTime $completedAt */ public function setCompletedAt(\DateTime $completedAt): void { $this->completedAt = $completedAt; } /** * @return string */ public function getParams(): string { return $this->params; } /** * @param string $params */ public function setParams(string $params): void { $this->params = $params; } /** * @return int */ public function getParentId(): ?int { return $this->parent_id; } /** * @param int $parent_id */ public function setParentId(?int $parent_id): void { $this->parent_id = $parent_id; } /** * convert parameters to array * @return array<string,string|int> */ public function toArray(): array { return [ 'params' => $this->getParams(), 'status' => $this->getStatus(), 'type' => $this->getType(), 'parent_id' => $this->getParentId(), 'created_at' => $this->getCreatedAt()->format('Y-m-d H:i:s'), ]; } /** * return all statuses * @return array<mixed> */ public function getStatuses() { $ref = new ReflectionClass(self::class); $constants = $ref->getConstants(); $statusConstants = $this->arrayFilterKey($constants, function ($key) { return str_starts_with($key, 'STATE_'); }); $statuses = []; foreach ($statusConstants as $stKey => $stConstant) { $statuses[] = $ref->getConstant($stKey); } return $statuses; } /** * Filters array keys * @param array<mixed> $input * @param mixed $callback * @return array<mixed>|null */ private function arrayFilterKey($input, $callback) { if (! is_array($input)) { trigger_error('arrayFilterKey() expects parameter 1 to be array, ' . gettype($input) . ' given', E_USER_WARNING); return null; } if ($input === []) { return $input; } $filteredKeys = array_filter(array_keys($input), $callback); if ($filteredKeys === []) { return []; } return array_intersect_key(array_flip($filteredKeys), $input); } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/ConfigurationLoader/YamlConfigurationLoader.php
centreon/src/Centreon/Domain/ConfigurationLoader/YamlConfigurationLoader.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\ConfigurationLoader; use Symfony\Component\Yaml\Tag\TaggedValue; use Symfony\Component\Yaml\Yaml; /** * This class is designed to load a Yaml configuration file taking into account a custom tag to load other files. * * @package Centreon\Domain\Gorgone */ class YamlConfigurationLoader { private const INCLUDE_TOKEN = 'include'; /** @var string Root configuration file */ private $configurationFile; /** * YamlConfigurationLoader constructor. * * @param string $configurationFile */ public function __construct(string $configurationFile) { $this->configurationFile = $configurationFile; } /** * Loads the configuration file defined in the constructor and returns its equivalent in the form of an array. * * @return array Configuration data */ public function load(): array { $configuration = $this->loadFile($this->configurationFile); return $this->iterateConfiguration( $configuration, realpath(dirname($this->configurationFile)), realpath($this->configurationFile) ); } /** * Iterate each key and value to detect the request to load another configuration file. * * @param array $configuration Configuration data to analyse * @param string $currentDirectory Directory of the currently analyzed configuration file * @param string $historyLoadedFile History of analyzed configuration files * * @return array Returns the configuration data including other configuration data from the include files */ private function iterateConfiguration( array $configuration, string $currentDirectory, string $historyLoadedFile, ): array { foreach ($configuration as $key => $value) { if (is_array($value)) { $configuration[$key] = $this->iterateConfiguration($value, $currentDirectory, $historyLoadedFile); } elseif ($value instanceof TaggedValue && $value->getTag() === self::INCLUDE_TOKEN) { $fileToLoad = $value->getValue(); if ($fileToLoad[0] !== DIRECTORY_SEPARATOR) { $fileToLoad = $currentDirectory . DIRECTORY_SEPARATOR . $fileToLoad; } $dataToIterate = $this->loadFile($fileToLoad); if (! $this->isLoopDetected($fileToLoad, $historyLoadedFile)) { $configuration[$key] = $this->iterateConfiguration( $dataToIterate, realpath(dirname($fileToLoad)), $historyLoadedFile . '::' . realpath($fileToLoad) ); } else { $loadedFile = explode('::', $historyLoadedFile); throw new \Exception('Loop detected in file ' . array_pop($loadedFile)); } } } return $configuration; } /** * Indicates if a loop is detected. * * @param string $fileToLoad File to load * @param string $historyLoadedFile File load History * * @return bool Returns TRUE if a loop is detected */ private function isLoopDetected(string $fileToLoad, string $historyLoadedFile): bool { $fileToLoad = realpath($fileToLoad); $loadedFile = explode('::', $historyLoadedFile); return in_array($fileToLoad, $loadedFile); } /** * Load and parse a Yaml configuration file. * * @param string $yamlFile Yaml configuration file to load * * @return array Returns the configuration data in the form of an array */ private function loadFile(string $yamlFile): array { if (! file_exists($yamlFile)) { throw new \Exception('The configuration file \'' . $yamlFile . '\' does not exists'); } return (array) Yaml::parseFile($yamlFile, Yaml::PARSE_CUSTOM_TAGS); } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Filter/FilterService.php
centreon/src/Centreon/Domain/Filter/FilterService.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Filter; use Centreon\Domain\Contact\Contact; use Centreon\Domain\Filter\Interfaces\FilterRepositoryInterface; use Centreon\Domain\Filter\Interfaces\FilterServiceInterface; use Centreon\Domain\Monitoring\HostGroup\Interfaces\HostGroupServiceInterface; use Centreon\Domain\Monitoring\ServiceGroup\Interfaces\ServiceGroupServiceInterface; use Centreon\Domain\Service\AbstractCentreonService; /** * This class is designed to manage monitoring servers and their associated resources. * * @package Centreon\Domain\Filter */ class FilterService extends AbstractCentreonService implements FilterServiceInterface { /** @var HostGroupServiceInterface */ private $hostGroupService; /** @var ServiceGroupServiceInterface */ private $serviceGroupService; /** @var FilterRepositoryInterface */ private $filterRepository; /** * FilterService constructor. * * @param HostGroupServiceInterface $hostGroupService * @param ServiceGroupServiceInterface $serviceGroupService * @param FilterRepositoryInterface $filterRepository */ public function __construct( HostGroupServiceInterface $hostGroupService, ServiceGroupServiceInterface $serviceGroupService, FilterRepositoryInterface $filterRepository, ) { $this->hostGroupService = $hostGroupService; $this->serviceGroupService = $serviceGroupService; $this->filterRepository = $filterRepository; } /** * {@inheritDoc} * @param Contact|null $contact * @return FilterServiceInterface */ public function filterByContact($contact): FilterServiceInterface { parent::filterByContact($contact); $this->hostGroupService->filterByContact($contact); return $this; } /** * @inheritDoc */ public function addFilter(Filter $filter): int { $foundFilter = $this->filterRepository->findFilterByUserIdAndName( $filter->getUserId(), $filter->getPageName(), $filter->getName() ); if ($foundFilter !== null) { throw new FilterException(_('Filter already exists')); } try { return $this->filterRepository->addFilter($filter); } catch (\Exception $ex) { throw new FilterException( sprintf(_('Error when adding filter %s'), $filter->getName()), 0, $ex ); } } /** * @inheritDoc */ public function updateFilter(Filter $filter): void { $foundFilter = $this->filterRepository->findFilterByUserIdAndName( $filter->getUserId(), $filter->getPageName(), $filter->getName() ); if ($foundFilter !== null && $filter->getId() !== $foundFilter->getId()) { throw new FilterException(_('Filter name already used')); } try { $this->checkCriterias($filter->getCriterias()); $this->filterRepository->updateFilter($filter); } catch (\Exception $ex) { throw new FilterException( sprintf(_('Error when updating filter %s'), $filter->getName()), 0, $ex ); } } /** * @inheritDoc */ public function checkCriterias(array $criterias): void { foreach ($criterias as $criteria) { if ($criteria->getType() === 'multi_select' && is_array($criteria->getValue())) { switch ($criteria->getObjectType()) { case 'host_groups': $hostGroupNames = array_column($criteria->getValue(), 'name'); $hostGroups = $this->hostGroupService ->filterByContact($this->contact) ->findHostGroupsByNames($hostGroupNames); $criteria->setValue(array_map( function ($hostGroup) { return [ 'id' => $hostGroup->getId(), 'name' => $hostGroup->getName(), ]; }, $hostGroups )); break; case 'service_groups': $serviceGroupNames = array_column($criteria->getValue(), 'name'); $serviceGroups = $this->serviceGroupService ->filterByContact($this->contact) ->findServiceGroupsByNames($serviceGroupNames); $criteria->setValue(array_map( function ($serviceGroup) { return [ 'id' => $serviceGroup->getId(), 'name' => $serviceGroup->getName(), ]; }, $serviceGroups )); break; } } } } /** * @inheritDoc */ public function deleteFilter(Filter $filter): void { try { $this->filterRepository->deleteFilter($filter); } catch (\Exception $ex) { throw new FilterException( sprintf(_('Error when deleting filter %s'), $filter->getName()), 0, $ex ); } } /** * @inheritDoc */ public function findFiltersByUserId(int $userId, string $pageName): array { try { return $this->filterRepository->findFiltersByUserIdWithRequestParameters($userId, $pageName); } catch (\Exception $ex) { throw new FilterException(_('Error when searching filters'), 0, $ex); } } /** * @inheritDoc */ public function findFilterByUserId(int $userId, string $pageName, int $filterId): ?Filter { try { return $this->filterRepository->findFilterByUserIdAndId($userId, $pageName, $filterId); } catch (\Exception $ex) { throw new FilterException( sprintf(_('Error when searching filter id %d'), $filterId), 0, $ex ); } } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Filter/FilterCriteria.php
centreon/src/Centreon/Domain/Filter/FilterCriteria.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Filter; /** * This class is designed to represent a filter criteria entity. * * @package Centreon\Domain\Filter */ class FilterCriteria { /** @var string|null Name of the criteria */ private $name; /** @var string|null Type of the criteria */ private $type; /** @var string|array<mixed>|bool|null Value of the criteria */ private $value; /** @var string|null Object type used in the criteria */ private $objectType; /** @var array<mixed>|null Value of the searchData */ private $searchData; /** * @return string|null */ public function getName(): ?string { return $this->name; } /** * @param string|null $name * @return FilterCriteria */ public function setName(?string $name): FilterCriteria { $this->name = $name; return $this; } /** * @return string|null */ public function getType(): ?string { return $this->type; } /** * @param string|null $type * @return FilterCriteria */ public function setType(?string $type): FilterCriteria { $this->type = $type; return $this; } /** * @return string|array<mixed>|bool|null */ public function getValue() { return $this->value; } /** * @param string|array<mixed>|bool|null $value * @return FilterCriteria */ public function setValue($value): FilterCriteria { $this->value = $value; return $this; } /** * @return string|null */ public function getObjectType(): ?string { return $this->objectType; } /** * @param string|null $objectType * @return FilterCriteria */ public function setObjectType(?string $objectType): FilterCriteria { $this->objectType = $objectType; return $this; } /** * @param mixed[]|null $searchData * @return FilterCriteria */ public function setSearchData($searchData): FilterCriteria { $this->searchData = $searchData; return $this; } /** * @return mixed[]|null */ public function getSearchData() { return $this->searchData; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Filter/FilterException.php
centreon/src/Centreon/Domain/Filter/FilterException.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Filter; class FilterException extends \Exception { }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Filter/Filter.php
centreon/src/Centreon/Domain/Filter/Filter.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Filter; /** * This class is designed to represent a filter entity. * * @package Centreon\Domain\Filter */ class Filter { /** @var int|null Unique id of the filter */ private $id; /** @var string|null Name of the filter */ private $name; /** @var int|null User id */ private $userId; /** @var string|null Page name */ private $pageName; /** @var FilterCriteria[] Criterias */ private $criterias = []; /** @var int|null Order */ private $order; /** * @return int|null */ public function getId(): ?int { return $this->id; } /** * @param int|null $id * @return Filter */ public function setId(?int $id): Filter { $this->id = $id; return $this; } /** * @return string|null */ public function getName(): ?string { return $this->name; } /** * @param string|null $name * @return Filter */ public function setName(?string $name): Filter { $this->name = $name; return $this; } /** * @return int|null */ public function getUserId(): ?int { return $this->userId; } /** * @param int|null $userId * @return Filter */ public function setUserId(?int $userId): Filter { $this->userId = $userId; return $this; } /** * @return string|null */ public function getPageName(): ?string { return $this->pageName; } /** * @param string|null $pageName * @return Filter */ public function setPageName(?string $pageName): Filter { $this->pageName = $pageName; return $this; } /** * @return FilterCriteria[] */ public function getCriterias(): array { return $this->criterias; } /** * @param FilterCriteria[] $criterias * @return Filter */ public function setCriterias(array $criterias): Filter { $this->criterias = $criterias; return $this; } /** * @return int|null */ public function getOrder(): ?int { return $this->order; } /** * @param int|null $order * @return Filter */ public function setOrder(?int $order): Filter { $this->order = $order; return $this; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Filter/Interfaces/FilterRepositoryInterface.php
centreon/src/Centreon/Domain/Filter/Interfaces/FilterRepositoryInterface.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Filter\Interfaces; use Centreon\Domain\Filter\Filter; use Centreon\Domain\Filter\FilterException; interface FilterRepositoryInterface { /** * Add filter. * * @param Filter $filter * @throws FilterException * @return int created filter id */ public function addFilter(Filter $filter): int; /** * Update filter. * * @param Filter $filter * @throws FilterException * @return void */ public function updateFilter(Filter $filter): void; /** * Delete filter. * * @param Filter $filter * @throws FilterException * @return void */ public function deleteFilter(Filter $filter): void; /** * Find filters linked to a user id using request parameters. * * @param int $userId current user id * @throws \Exception * @return Filter[] */ public function findFiltersByUserIdWithRequestParameters(int $userId, string $pageName): array; /** * Find filters linked to a user id without using request parameters. * * @param int $userId current user id * @param string $pageName page name * @throws \Exception * @return Filter[] */ public function findFiltersByUserIdWithoutRequestParameters(int $userId, string $pageName): array; /** * Find filter by id * * @param int $userId * @param string $pageName * @param string $name * @return Filter|null */ public function findFilterByUserIdAndName(int $userId, string $pageName, string $name): ?Filter; /** * Find filter by user id and filter id. * * @param int $userId current user id * @param string $pageName page name * @param int $filterId Filter id to search * @throws FilterException * @return Filter */ public function findFilterByUserIdAndId(int $userId, string $pageName, int $filterId): ?Filter; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Filter/Interfaces/FilterServiceInterface.php
centreon/src/Centreon/Domain/Filter/Interfaces/FilterServiceInterface.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Filter\Interfaces; use Centreon\Domain\Filter\Filter; use Centreon\Domain\Filter\FilterCriteria; use Centreon\Domain\Filter\FilterException; interface FilterServiceInterface { /** * Used to filter requests according to a contact. * If the filter is defined, all requests will use the ACL of the contact * to fetch data. * * @param mixed $contact Contact to use as a ACL filter * @throws \Exception * @return FilterServiceInterface */ public function filterByContact($contact): FilterServiceInterface; /** * Add filter. * * @param Filter $filter * @throws FilterException * @return int created filter id */ public function addFilter(Filter $filter): int; /** * Update filter. * * @param Filter $filter * @throws FilterException * @return void */ public function updateFilter(Filter $filter): void; /** * Check filter criterias * Remove object if does not exist anymore * Rename object if has been renamed since filter creation * * @param FilterCriteria[] $criterias * @return void */ public function checkCriterias(array $criterias): void; /** * Delete filter. * * @param Filter $filter * @throws FilterException * @return void */ public function deleteFilter(Filter $filter): void; /** * Find filters. * * @param int $userId current user id * @param string $pageName page name * @throws FilterException * @return Filter[] */ public function findFiltersByUserId(int $userId, string $pageName): array; /** * Find filter by user id and filter id. * * @param int $userId current user id * @param string $pageName page name * @param int $filterId Filter id to search * @throws FilterException * @return Filter */ public function findFilterByUserId(int $userId, string $pageName, int $filterId): ?Filter; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/MetaServiceConfiguration/MetaServiceConfigurationService.php
centreon/src/Centreon/Domain/MetaServiceConfiguration/MetaServiceConfigurationService.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\MetaServiceConfiguration; use Centreon\Domain\Contact\Interfaces\ContactInterface; use Centreon\Domain\MetaServiceConfiguration\Exception\MetaServiceConfigurationException; use Centreon\Domain\MetaServiceConfiguration\Interfaces\MetaServiceConfigurationReadRepositoryInterface; use Centreon\Domain\MetaServiceConfiguration\Interfaces\MetaServiceConfigurationServiceInterface; use Centreon\Domain\MetaServiceConfiguration\Model\MetaServiceConfiguration; /** * This class is designed to manage the host categories. * * @package Centreon\Domain\MetaServiceConfiguration */ class MetaServiceConfigurationService implements MetaServiceConfigurationServiceInterface { /** @var MetaServiceConfigurationReadRepositoryInterface */ private $readRepository; /** @var ContactInterface */ private $contact; /** * @param MetaServiceConfigurationReadRepositoryInterface $readRepository * @param ContactInterface $contact */ public function __construct( MetaServiceConfigurationReadRepositoryInterface $readRepository, ContactInterface $contact, ) { $this->contact = $contact; $this->readRepository = $readRepository; } /** * @inheritDoc */ public function findWithAcl(int $metaId): ?MetaServiceConfiguration { try { return $this->readRepository->findByIdAndContact($metaId, $this->contact); } catch (\Throwable $ex) { throw MetaServiceConfigurationException::findOneMetaServiceConfiguration($ex, $metaId); } } /** * @inheritDoc */ public function findWithoutAcl(int $metaId): ?MetaServiceConfiguration { try { return $this->readRepository->findById($metaId); } catch (\Throwable $ex) { throw MetaServiceConfigurationException::findOneMetaServiceConfiguration($ex, $metaId); } } /** * @inheritDoc */ public function findAllWithAcl(): array { try { return $this->readRepository->findAllByContact($this->contact); } catch (\Throwable $ex) { throw MetaServiceConfigurationException::findMetaServicesConfigurations($ex); } } /** * @inheritDoc */ public function findAllWithoutAcl(): array { try { return $this->readRepository->findAll(); } catch (\Throwable $ex) { throw MetaServiceConfigurationException::findMetaServicesConfigurations($ex); } } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/MetaServiceConfiguration/Model/MetaServiceConfiguration.php
centreon/src/Centreon/Domain/MetaServiceConfiguration/Model/MetaServiceConfiguration.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\MetaServiceConfiguration\Model; use Centreon\Domain\Common\Assertion\Assertion; use InvalidArgumentException; /** * This class is designed to represent a meta service configuration. * * @package Centreon\Domain\MetaServiceConfiguration\Model */ class MetaServiceConfiguration { public const MAX_NAME_LENGTH = 254; public const MIN_NAME_LENGTH = 1; public const MAX_OUTPUT_LENGTH = 254; public const MAX_METRIC_LENGTH = 255; public const MAX_REGEXP_STRING_LENGTH = 254; public const MAX_WARNING_LENGTH = 254; public const MAX_CRITICAL_LENGTH = 254; public const AVAILABLE_DATA_SOURCE_TYPES = ['gauge', 'counter', 'derive', 'absolute']; public const AVAILABLE_CALCULATION_TYPES = ['average', 'minimum', 'maximum', 'sum']; public const META_SELECT_MODE_LIST = 1; public const META_SELECT_MODE_SQL_REGEXP = 2; /** @var int ID of the Meta Service */ private $id; /** @var string Name used to identity the Meta Service */ private $name; /** @var string|null Define the output displayed by the Meta Service */ private $output; /** @var string Define the function to be applied to calculate the Meta Service status */ private $calculationType; /** * @var string Define the data source type of the Meta Service * 0 - GAUGE * 1 - COUNTER * 2 - DERIVE * 3 - ABSOLUTE */ private $dataSourceType = 'gauge'; /** * @var int Selection mode for services to be considered for this meta service. * 0 - In service list mode, mark selected services in the options on meta service list. * 1 - In SQL matching mode, specify a search string to be used in an SQL query. */ private $metaSelectMode = 1; /** @var string|null Search string to be used in a SQL LIKE query for service selection */ private $regexpString; /** @var string|null select the metric to measure for meta service status */ private $metric; /** @var string|null absolute value for warning level (low threshold) */ private $warning; /** @var string|null absolute value for critical level (high threshold) */ private $critical; /** @var bool Indicates whether this Meta Service is enabled or not (TRUE by default) */ private $isActivated = true; /** * @param string $name * @param string $calculationType * @param int $metaSelectMode * @throws \Assert\AssertionFailedException */ public function __construct(string $name, string $calculationType, int $metaSelectMode) { $this->setName($name); $this->setCalculationType($calculationType); $this->setMetaSelectMode($metaSelectMode); } /** * @return int|null */ public function getId(): ?int { return $this->id; } /** * @param int $id * @return MetaServiceConfiguration */ public function setId(int $id): MetaServiceConfiguration { $this->id = $id; return $this; } /** * @return string */ public function getName(): string { return $this->name; } /** * @param string $name * @throws \Assert\AssertionFailedException * @return MetaServiceConfiguration */ public function setName(string $name): MetaServiceConfiguration { Assertion::minLength($name, self::MIN_NAME_LENGTH, 'MetaServiceConfiguration::name'); Assertion::maxLength($name, self::MAX_NAME_LENGTH, 'MetaServiceConfiguration::name'); $this->name = $name; return $this; } /** * @return bool */ public function isActivated(): bool { return $this->isActivated; } /** * @param bool $isActivated * @return MetaServiceConfiguration */ public function setActivated(bool $isActivated): MetaServiceConfiguration { $this->isActivated = $isActivated; return $this; } /** * @return string */ public function getCalculationType(): string { return $this->calculationType; } /** * @param string $calculationType * @throws InvalidArgumentException * @return MetaServiceConfiguration */ public function setCalculationType(string $calculationType): MetaServiceConfiguration { if (! in_array($calculationType, self::AVAILABLE_CALCULATION_TYPES)) { throw new InvalidArgumentException( sprintf(_('Calculation method provided not supported (%s)'), $calculationType) ); } $this->calculationType = $calculationType; return $this; } /** * @return string|null */ public function getOutput(): ?string { return $this->output; } /** * @param string|null $output * @throws \Assert\AssertionFailedException * @return MetaServiceConfiguration */ public function setOutput(?string $output): MetaServiceConfiguration { if (! is_null($output)) { Assertion::maxLength($output, self::MAX_OUTPUT_LENGTH, 'MetaServiceConfiguration::output'); } $this->output = $output; return $this; } /** * @return string */ public function getDataSourceType(): string { return $this->dataSourceType; } /** * @param string $dataSourceType * @return MetaServiceConfiguration */ public function setDataSourceType(string $dataSourceType): MetaServiceConfiguration { if (! in_array($dataSourceType, self::AVAILABLE_DATA_SOURCE_TYPES)) { throw new InvalidArgumentException( sprintf(_('Data source type provided not supported (%s)'), $dataSourceType) ); } $this->dataSourceType = $dataSourceType; return $this; } /** * @return int */ public function getMetaSelectMode(): int { return $this->metaSelectMode; } /** * @param int $metaSelectMode * @return MetaServiceConfiguration */ public function setMetaSelectMode(int $metaSelectMode): MetaServiceConfiguration { $this->metaSelectMode = $metaSelectMode; return $this; } /** * @return string|null */ public function getRegexpString(): ?string { return $this->regexpString; } /** * @param string|null $regexpString * @throws \Assert\AssertionFailedException * @return MetaServiceConfiguration */ public function setRegexpString(?string $regexpString): MetaServiceConfiguration { if (! is_null($regexpString)) { Assertion::maxLength( $regexpString, self::MAX_REGEXP_STRING_LENGTH, 'MetaServiceConfiguration::regexpString' ); } $this->regexpString = $regexpString; return $this; } /** * @return string|null */ public function getMetric(): ?string { return $this->metric; } /** * @param string|null $metric * @throws \Assert\AssertionFailedException * @return MetaServiceConfiguration */ public function setMetric(?string $metric): MetaServiceConfiguration { if (! is_null($metric)) { Assertion::maxLength($metric, self::MAX_METRIC_LENGTH, 'MetaServiceConfiguration::metric'); } $this->metric = $metric; return $this; } /** * @return string|null */ public function getWarning(): ?string { return $this->warning; } /** * @param string|null $warning * @throws \Assert\AssertionFailedException * @return MetaServiceConfiguration */ public function setWarning(?string $warning): MetaServiceConfiguration { if (! is_null($warning)) { Assertion::maxLength($warning, self::MAX_WARNING_LENGTH, 'MetaServiceConfiguration::warning'); } $this->warning = $warning; return $this; } /** * @return string|null */ public function getCritical(): ?string { return $this->critical; } /** * @param string|null $critical * @throws \Assert\AssertionFailedException * @return MetaServiceConfiguration */ public function setCritical(?string $critical): MetaServiceConfiguration { if (! is_null($critical)) { Assertion::maxLength($critical, self::MAX_CRITICAL_LENGTH, 'MetaServiceConfiguration::critical'); } $this->critical = $critical; return $this; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/MetaServiceConfiguration/UseCase/V2110/FindMetaServicesConfigurations.php
centreon/src/Centreon/Domain/MetaServiceConfiguration/UseCase/V2110/FindMetaServicesConfigurations.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\MetaServiceConfiguration\UseCase\V2110; use Centreon\Domain\Contact\Contact; use Centreon\Domain\Contact\Interfaces\ContactInterface; use Centreon\Domain\Log\LoggerTrait; use Centreon\Domain\MetaServiceConfiguration\Exception\MetaServiceConfigurationException; use Centreon\Domain\MetaServiceConfiguration\Interfaces\MetaServiceConfigurationServiceInterface; use Core\Security\AccessGroup\Application\Repository\ReadAccessGroupRepositoryInterface; use Core\Security\AccessGroup\Domain\Model\AccessGroup; use Symfony\Component\Security\Core\Exception\AccessDeniedException; /** * This class is designed to represent a use case to find all host categories. * * @package Centreon\Domain\MetaServiceConfiguration\UseCase\V2110 */ class FindMetaServicesConfigurations { use LoggerTrait; public const AUTHORIZED_ACL_GROUPS = ['customer_admin_acl']; /** * @param MetaServiceConfigurationServiceInterface $metaServiceConfigurationService * @param ContactInterface $contact * @param ReadAccessGroupRepositoryInterface $accessGroupRepository * @param bool $isCloudPlatform */ public function __construct( private readonly MetaServiceConfigurationServiceInterface $metaServiceConfigurationService, private readonly ContactInterface $contact, private readonly ReadAccessGroupRepositoryInterface $accessGroupRepository, private readonly bool $isCloudPlatform, ) { } /** * Execute the use case for which this class was designed. * * @throws AccessDeniedException|MetaServiceConfigurationException * @return FindMetaServicesConfigurationsResponse */ public function execute(): FindMetaServicesConfigurationsResponse { if ( ! $this->contact->hasTopologyRole(Contact::ROLE_CONFIGURATION_META_SERVICES_READ) && ! $this->contact->hasTopologyRole(Contact::ROLE_CONFIGURATION_META_SERVICES_WRITE) ) { $this->error('Insufficient right for user', ['user_id' => $this->contact->getId()]); throw new AccessDeniedException( 'Insufficient rights (required: ROLE_CONFIGURATION_META_SERVICES_READ or ROLE_CONFIGURATION_META_SERVICES_WRITE)' ); } $response = new FindMetaServicesConfigurationsResponse(); $metaServicesConfigurations = $this->isUserAdmin() ? $this->metaServiceConfigurationService->findAllWithoutAcl() : $this->metaServiceConfigurationService->findAllWithAcl(); $response->setMetaServicesConfigurations($metaServicesConfigurations); return $response; } /** * Indicates if the current user is admin or not (cloud + onPremise context). * * @return bool */ private function isUserAdmin(): bool { if ($this->contact->isAdmin()) { return true; } $userAccessGroupNames = array_map( static fn (AccessGroup $accessGroup): string => $accessGroup->getName(), $this->accessGroupRepository->findByContact($this->contact) ); return ! empty(array_intersect($userAccessGroupNames, self::AUTHORIZED_ACL_GROUPS)) && $this->isCloudPlatform; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/MetaServiceConfiguration/UseCase/V2110/FindOneMetaServiceConfigurationResponse.php
centreon/src/Centreon/Domain/MetaServiceConfiguration/UseCase/V2110/FindOneMetaServiceConfigurationResponse.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\MetaServiceConfiguration\UseCase\V2110; use Centreon\Domain\MetaServiceConfiguration\Model\MetaServiceConfiguration; /** * This class is a DTO for the FindMetaServicesConfigurations use case. * * @package Centreon\Domain\MetaServiceConfiguration\UseCase\V2110 */ class FindOneMetaServiceConfigurationResponse { /** @var array<string, mixed> */ private $metaServiceConfiguration; /** * @param MetaServiceConfiguration $metaServiceConfiguration */ public function setMetaServiceConfiguration(MetaServiceConfiguration $metaServiceConfiguration): void { $this->metaServiceConfiguration = [ 'id' => $metaServiceConfiguration->getId(), 'name' => $metaServiceConfiguration->getName(), 'meta_display' => $metaServiceConfiguration->getOutput(), 'meta_select_mode' => $metaServiceConfiguration->getMetaSelectMode(), 'data_source_type' => $metaServiceConfiguration->getDataSourceType(), 'calcul_type' => $metaServiceConfiguration->getCalculationType(), 'regexp_str' => $metaServiceConfiguration->getRegexpString(), 'metric' => $metaServiceConfiguration->getMetric(), 'warning' => $metaServiceConfiguration->getWarning(), 'critical' => $metaServiceConfiguration->getCritical(), 'is_activated' => $metaServiceConfiguration->isActivated(), ]; } /** * @return null|array<string, mixed> */ public function getMetaServiceConfiguration(): ?array { return $this->metaServiceConfiguration; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/MetaServiceConfiguration/UseCase/V2110/FindOneMetaServiceConfiguration.php
centreon/src/Centreon/Domain/MetaServiceConfiguration/UseCase/V2110/FindOneMetaServiceConfiguration.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\MetaServiceConfiguration\UseCase\V2110; use Centreon\Domain\Contact\Contact; use Centreon\Domain\Contact\Interfaces\ContactInterface; use Centreon\Domain\Exception\EntityNotFoundException; use Centreon\Domain\Log\LoggerTrait; use Centreon\Domain\MetaServiceConfiguration\Exception\MetaServiceConfigurationException; use Centreon\Domain\MetaServiceConfiguration\Interfaces\MetaServiceConfigurationServiceInterface; use Symfony\Component\Security\Core\Exception\AccessDeniedException; /** * This class is designed to represent a use case to find all host categories. * * @package Centreon\Domain\MetaServiceConfiguration\UseCase\V2110 */ class FindOneMetaServiceConfiguration { use LoggerTrait; /** @var MetaServiceConfigurationServiceInterface */ private $metaServiceConfigurationService; /** @var ContactInterface */ private $contact; /** * FindMetaServiceConfiguration constructor. * * @param MetaServiceConfigurationServiceInterface $metaServiceConfigurationService * @param ContactInterface $contact */ public function __construct( MetaServiceConfigurationServiceInterface $metaServiceConfigurationService, ContactInterface $contact, ) { $this->metaServiceConfigurationService = $metaServiceConfigurationService; $this->contact = $contact; } /** * Execute the use case for which this class was designed. * @param int $metaId * @throws MetaServiceConfigurationException * @return FindOneMetaServiceConfigurationResponse */ public function execute(int $metaId): FindOneMetaServiceConfigurationResponse { try { if ( ! $this->contact->hasTopologyRole(Contact::ROLE_CONFIGURATION_META_SERVICES_READ) && ! $this->contact->hasTopologyRole(Contact::ROLE_CONFIGURATION_META_SERVICES_WRITE) ) { throw new AccessDeniedException( 'Insufficient rights (required: ROLE_CONFIGURATION_META_SERVICES_READ or ROLE_CONFIGURATION_META_SERVICES_WRITE)' ); } $response = new FindOneMetaServiceConfigurationResponse(); $metaServiceConfiguration = ($this->contact->isAdmin()) ? $this->metaServiceConfigurationService->findWithoutAcl($metaId) : $this->metaServiceConfigurationService->findWithAcl($metaId); if (is_null($metaServiceConfiguration)) { throw MetaServiceConfigurationException::findOneMetaServiceConfigurationNotFound($metaId); } $response->setMetaServiceConfiguration($metaServiceConfiguration); return $response; } catch (AccessDeniedException $ex) { $this->error('Insufficient right for user', ['user_id' => $this->contact->getId()]); throw new AccessDeniedException($ex->getMessage()); } catch (MetaServiceConfigurationException $ex) { $this->error('Meta service configuration not found', ['meta_id' => $metaId]); throw new EntityNotFoundException($ex->getMessage()); } } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/MetaServiceConfiguration/UseCase/V2110/FindMetaServicesConfigurationsResponse.php
centreon/src/Centreon/Domain/MetaServiceConfiguration/UseCase/V2110/FindMetaServicesConfigurationsResponse.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\MetaServiceConfiguration\UseCase\V2110; use Centreon\Domain\MetaServiceConfiguration\Model\MetaServiceConfiguration; /** * This class is a DTO for the FindMetaServicesConfigurations use case. * * @package Centreon\Domain\MetaServiceConfiguration\UseCase\V2110 */ class FindMetaServicesConfigurationsResponse { /** @var array<int, array<string, mixed>> */ private $metaServicesConfigurations = []; /** * @param MetaServiceConfiguration[] $metaServicesConfigurations */ public function setMetaServicesConfigurations(array $metaServicesConfigurations): void { foreach ($metaServicesConfigurations as $metaServiceConfiguration) { $this->metaServicesConfigurations[] = [ 'id' => $metaServiceConfiguration->getId(), 'name' => $metaServiceConfiguration->getName(), 'meta_display' => $metaServiceConfiguration->getOutput(), 'meta_select_mode' => $metaServiceConfiguration->getMetaSelectMode(), 'data_source_type' => $metaServiceConfiguration->getDataSourceType(), 'calcul_type' => $metaServiceConfiguration->getCalculationType(), 'regexp_str' => $metaServiceConfiguration->getRegexpString(), 'metric' => $metaServiceConfiguration->getMetric(), 'warning' => $metaServiceConfiguration->getWarning(), 'critical' => $metaServiceConfiguration->getCritical(), 'is_activated' => $metaServiceConfiguration->isActivated(), ]; } } /** * @return array<int, array<string, mixed>> */ public function getMetaServicesConfigurations(): array { return $this->metaServicesConfigurations; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/MetaServiceConfiguration/Interfaces/MetaServiceConfigurationServiceInterface.php
centreon/src/Centreon/Domain/MetaServiceConfiguration/Interfaces/MetaServiceConfigurationServiceInterface.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\MetaServiceConfiguration\Interfaces; use Centreon\Domain\MetaServiceConfiguration\Exception\MetaServiceConfigurationException; use Centreon\Domain\MetaServiceConfiguration\Model\MetaServiceConfiguration; /** * @package Centreon\Domain\MetaServiceConfiguration\Interfaces */ interface MetaServiceConfigurationServiceInterface { /** * Find a meta service (for non admin user). * * @param int $metaId Id of the meta service to be found * @throws MetaServiceConfigurationException * @return MetaServiceConfiguration|null */ public function findWithAcl(int $metaId): ?MetaServiceConfiguration; /** * Find a meta service (for admin user). * * @param int $metaId Id of the meta service to be found * @throws MetaServiceConfigurationException * @return MetaServiceConfiguration|null */ public function findWithoutAcl(int $metaId): ?MetaServiceConfiguration; /** * Find all meta services configurations (for non admin user). * * @throws MetaServiceConfigurationException * @return MetaServiceConfiguration[] */ public function findAllWithAcl(): array; /** * Find all meta services configurations (for admin user). * * @throws MetaServiceConfigurationException * @return MetaServiceConfiguration[] */ public function findAllWithoutAcl(): array; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/MetaServiceConfiguration/Interfaces/MetaServiceConfigurationReadRepositoryInterface.php
centreon/src/Centreon/Domain/MetaServiceConfiguration/Interfaces/MetaServiceConfigurationReadRepositoryInterface.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\MetaServiceConfiguration\Interfaces; use Centreon\Domain\Contact\Interfaces\ContactInterface; use Centreon\Domain\MetaServiceConfiguration\Model\MetaServiceConfiguration; /** * This interface gathers all the reading operations on the meta service configuration repository. * * @package Centreon\Domain\MetaServiceConfiguration\Interfaces */ interface MetaServiceConfigurationReadRepositoryInterface { /** * Find a meta service configuration by id. * * @param int $metaId Id of the meta service configuration to be found * @throws \Throwable * @return MetaServiceConfiguration|null */ public function findById(int $metaId): ?MetaServiceConfiguration; /** * Find a meta service configuration by id and contact. * * @param int $metaId Id of the meta service configuration to be found * @param ContactInterface $contact Contact related to host category * @throws \Throwable * @return MetaServiceConfiguration|null */ public function findByIdAndContact(int $metaId, ContactInterface $contact): ?MetaServiceConfiguration; /** * Find all meta services configurations. * * @throws \Throwable * @return MetaServiceConfiguration[] */ public function findAll(): array; /** * Find all meta services configurations by contact. * * @param ContactInterface $contact contact related to meta services configurations * @throws \Throwable * @return MetaServiceConfiguration[] */ public function findAllByContact(ContactInterface $contact): array; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/MetaServiceConfiguration/Exception/MetaServiceConfigurationException.php
centreon/src/Centreon/Domain/MetaServiceConfiguration/Exception/MetaServiceConfigurationException.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\MetaServiceConfiguration\Exception; /** * This class is designed to contain all exceptions for the context of the meta service configuration. * * @package Centreon\Domain\MetaServiceConfiguration\Exception */ class MetaServiceConfigurationException extends \Exception { /** * @param \Throwable $ex * @return self */ public static function findMetaServicesConfigurations(\Throwable $ex): self { return new self( sprintf(_('Error when searching for the meta services configurations')), 0, $ex ); } /** * @param \Throwable $ex * @param int $metaId * @return self */ public static function findOneMetaServiceConfiguration(\Throwable $ex, int $metaId): self { return new self( sprintf(_('Error when searching for the meta service configuration (%s)'), $metaId), 0, $ex ); } /** * @param int $metaId * @return self */ public static function findOneMetaServiceConfigurationNotFound(int $metaId): self { return new self( sprintf(_('Meta service configuration (%s) not found'), $metaId) ); } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Configuration/Icon/Icon.php
centreon/src/Centreon/Domain/Configuration/Icon/Icon.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Configuration\Icon; /** * Class representing a record of a icon in the repository. * * @package Centreon\Domain\Configuration\Icon */ class Icon { // Groups for serializing public const SERIALIZER_GROUP_MAIN = 'icon_main'; /** @var int|null */ private $id; /** @var string|null */ private $directory; /** @var string|null */ private $name; /** @var string|null */ private $url; /** * @return int|null */ public function getId(): ?int { return $this->id; } /** * @param int|null $id * @return Icon */ public function setId(?int $id): self { $this->id = $id; return $this; } /** * @return string|null */ public function getDirectory(): ?string { return $this->directory; } /** * @param string|null $directory * @return Icon */ public function setDirectory(?string $directory): self { $this->directory = $directory; return $this; } /** * @return string|null */ public function getName(): ?string { return $this->name; } /** * @param string|null $name * @return Icon */ public function setName(?string $name): self { $this->name = $name; return $this; } /** * @return string|null */ public function getUrl(): ?string { return $this->url; } /** * @param string|null $url * @return Icon */ public function setUrl(?string $url): self { $this->url = $url; return $this; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Configuration/Icon/IconException.php
centreon/src/Centreon/Domain/Configuration/Icon/IconException.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Configuration\Icon; class IconException extends \Exception { public static function iconDoesNotExists(int $id): self { return new self(sprintf(_('Icon #%d does not exist'), $id)); } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Configuration/Icon/IconService.php
centreon/src/Centreon/Domain/Configuration/Icon/IconService.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Configuration\Icon; use Centreon\Domain\Configuration\Icon\Interfaces\IconRepositoryInterface; use Centreon\Domain\Configuration\Icon\Interfaces\IconServiceInterface; /** * This class is designed to manage icon-related actions such as configuration. * * @package Centreon\Domain\Configuration\Icon */ class IconService implements IconServiceInterface { /** @var IconRepositoryInterface */ private $iconRepository; /** * IconService constructor. * * @param IconRepositoryInterface $iconRepository */ public function __construct(IconRepositoryInterface $iconRepository) { $this->iconRepository = $iconRepository; } /** * @inheritDoc */ public function getIcons(): array { return $this->iconRepository->getIconsWithRequestParameters(); } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Configuration/Icon/Interfaces/IconServiceInterface.php
centreon/src/Centreon/Domain/Configuration/Icon/Interfaces/IconServiceInterface.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Configuration\Icon\Interfaces; use Centreon\Domain\Configuration\Icon\Icon; interface IconServiceInterface { /** * Get icons * * @return Icon[] */ public function getIcons(): array; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Configuration/Icon/Interfaces/IconRepositoryInterface.php
centreon/src/Centreon/Domain/Configuration/Icon/Interfaces/IconRepositoryInterface.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Configuration\Icon\Interfaces; use Centreon\Domain\Configuration\Icon\Icon; interface IconRepositoryInterface { /** * Retrieve icons using request parameters (search, sort, pagination) * * @return Icon[] */ public function getIconsWithRequestParameters(): array; /** * Retrieve icons without request parameters (no search, no sort, no pagination) * * @return Icon[] */ public function getIconsWithoutRequestParameters(): array; /** * Retrieve an icon based on its id * * @param int $id * @return Icon|null */ public function getIcon(int $id): ?Icon; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Authentication/UseCase/AuthenticateApi.php
centreon/src/Centreon/Domain/Authentication/UseCase/AuthenticateApi.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Authentication\UseCase; use Centreon\Domain\Authentication\Exception\AuthenticationException; use Centreon\Domain\Contact\Interfaces\ContactInterface; use Centreon\Domain\Log\LoggerTrait; use Core\Security\Authentication\Application\Provider\ProviderAuthenticationFactoryInterface; use Core\Security\Authentication\Application\Provider\ProviderAuthenticationInterface; use Core\Security\Authentication\Application\Repository\WriteTokenRepositoryInterface; use Core\Security\Authentication\Application\UseCase\Login\LoginRequest; use Core\Security\Authentication\Domain\Model\NewProviderToken; use Core\Security\ProviderConfiguration\Domain\Model\Configuration; use Core\Security\ProviderConfiguration\Domain\Model\Provider; use Security\Domain\Authentication\Exceptions\ProviderException; use Security\Domain\Authentication\Model\LocalProvider; use Security\Encryption; class AuthenticateApi { use LoggerTrait; /** * @param WriteTokenRepositoryInterface $writeTokenRepository * @param ProviderAuthenticationFactoryInterface $providerFactory */ public function __construct( private WriteTokenRepositoryInterface $writeTokenRepository, private ProviderAuthenticationFactoryInterface $providerFactory, ) { } /** * @param AuthenticateApiRequest $request * @param AuthenticateApiResponse $response * @throws AuthenticationException * @throws ProviderException */ public function execute(AuthenticateApiRequest $request, AuthenticateApiResponse $response): void { $this->info(sprintf("[AUTHENTICATE API] Beginning API authentication for contact '%s'", $request->getLogin())); $localProvider = $this->findLocalProviderOrFail(); $this->authenticateOrFail($localProvider, $request); $contact = $this->getUserFromProviderOrFail($localProvider); $token = Encryption::generateRandomString(); $this->createAPIAuthenticationTokens( $token, $localProvider->getConfiguration(), $contact, $localProvider->getProviderToken($token), null ); $response->setApiAuthentication($contact, $token); $this->debug( '[AUTHENTICATE API] Authentication success', [ 'provider_name' => LocalProvider::NAME, 'contact_id' => $contact->getId(), 'contact_alias' => $contact->getAlias(), ] ); } /** * Find the local provider or throw an Exception. * * @throws ProviderException * @return ProviderAuthenticationInterface */ private function findLocalProviderOrFail(): ProviderAuthenticationInterface { return $this->providerFactory->create(Provider::LOCAL); } /** * Authenticate the user or throw an Exception. * * @param ProviderAuthenticationInterface $localProvider * @param AuthenticateApiRequest $request */ private function authenticateOrFail( ProviderAuthenticationInterface $localProvider, AuthenticateApiRequest $request, ): void { /** * Authenticate with the legacy mechanism encapsulated into the Local Provider. */ $this->debug('[AUTHENTICATE API] Authentication using provider', ['provider_name' => Provider::LOCAL]); $request = LoginRequest::createForLocal($request->getLogin(), $request->getPassword()); $localProvider->authenticateOrFail($request); } /** * Retrieve user from provider or throw an Exception. * * @param ProviderAuthenticationInterface $localProvider * @throws AuthenticationException * @return ContactInterface */ private function getUserFromProviderOrFail(ProviderAuthenticationInterface $localProvider): ContactInterface { $this->info('[AUTHENTICATE API] Retrieving user information from provider'); $contact = $localProvider->getAuthenticatedUser(); /** * Contact shouldn't be null in this case as the LocalProvider::authenticate method check if the user exists. * But the ProviderAuthenticationInterface::getUser method could return a ContactInterface or null * so we need to do this check. */ if ($contact === null) { $this->critical( '[AUTHENTICATE API] No contact could be found from provider', ['provider_name' => LocalProvider::NAME] ); throw AuthenticationException::userNotFound(); } return $contact; } /** * @param string $token * @param Configuration $providerConfiguration * @param ContactInterface $contact * @param NewProviderToken $providerToken * @param NewProviderToken|null $providerRefreshToken * @throws AuthenticationException * @return void */ private function createAPIAuthenticationTokens( string $token, Configuration $providerConfiguration, ContactInterface $contact, NewProviderToken $providerToken, ?NewProviderToken $providerRefreshToken, ): void { $this->debug( '[AUTHENTICATE API] Creating authentication tokens for user', ['user' => $contact->getAlias()] ); try { $this->writeTokenRepository->createAuthenticationTokens( $token, $providerConfiguration->getId(), $contact->getId(), $providerToken, $providerRefreshToken ); } catch (\Exception $ex) { throw AuthenticationException::addAuthenticationToken($ex); } } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Authentication/UseCase/AuthenticateApiResponse.php
centreon/src/Centreon/Domain/Authentication/UseCase/AuthenticateApiResponse.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Authentication\UseCase; use Centreon\Domain\Contact\Interfaces\ContactInterface; class AuthenticateApiResponse { /** @var array<string,array<string,mixed>> */ private $apiAuthentication = []; /** * Return the redirection URI. * * @return array<string,array<string,mixed>> */ public function getApiAuthentication(): array { return $this->apiAuthentication; } /** * @param ContactInterface $contact * @param string $token */ public function setApiAuthentication(ContactInterface $contact, string $token): void { $this->apiAuthentication = [ 'contact' => [ 'id' => $contact->getId(), 'name' => $contact->getName(), 'alias' => $contact->getAlias(), 'email' => $contact->getEmail(), 'is_admin' => $contact->isAdmin(), ], 'security' => [ 'token' => $token, ], ]; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Authentication/UseCase/Logout.php
centreon/src/Centreon/Domain/Authentication/UseCase/Logout.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Authentication\UseCase; use Centreon\Domain\Authentication\Exception\AuthenticationException; use Centreon\Domain\Log\LoggerTrait; use Security\Domain\Authentication\Interfaces\AuthenticationRepositoryInterface; class Logout { use LoggerTrait; /** @var AuthenticationRepositoryInterface */ private $authenticationRepository; public function __construct( AuthenticationRepositoryInterface $authenticationRepository, ) { $this->authenticationRepository = $authenticationRepository; } /** * Execute the Logout Use Case. * * @param LogoutRequest $request * @throws AuthenticationException */ public function execute(LogoutRequest $request): void { $this->info('Processing api logout...'); $this->authenticationRepository->deleteSecurityToken($request->getToken()); } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Authentication/UseCase/AuthenticateApiRequest.php
centreon/src/Centreon/Domain/Authentication/UseCase/AuthenticateApiRequest.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Authentication\UseCase; class AuthenticateApiRequest { /** @var string */ private $login; /** @var string */ private $password; /** * @param string $login * @param string $password */ public function __construct(string $login, string $password) { $this->login = $login; $this->password = $password; } /** * @return string */ public function getLogin(): string { return $this->login; } /** * @return string */ public function getPassword(): string { return $this->password; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Authentication/UseCase/LogoutRequest.php
centreon/src/Centreon/Domain/Authentication/UseCase/LogoutRequest.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Authentication\UseCase; class LogoutRequest { /** * Authentication Token * * @var string */ private $token; public function __construct(string $token) { $this->token = $token; } /** * @return string */ public function getToken(): string { return $this->token; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Authentication/Exception/AuthenticationException.php
centreon/src/Centreon/Domain/Authentication/Exception/AuthenticationException.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Authentication\Exception; use Core\Security\Authentication\Domain\Exception\AuthenticationException as CoreAuthenticationException; /** * This class is designed to contain all exceptions for the context of the authentication process. * * @package Centreon\Domain\Authentication\Exception */ class AuthenticationException extends CoreAuthenticationException { /** * @return self */ public static function invalidCredentials(): self { return new self(_('Invalid Credentials')); } /** * @return self */ public static function notAllowedToReachWebApplication(): self { return new self(_('User is not allowed to reach web application')); } /** * @return self */ public static function userNotFound(): self { return new self(_('User cannot be retrieved from the provider')); } /** * @return self */ public static function userNotFoundAndCannotBeCreated(): self { return new self(_('User not found and cannot be created')); } /** * @return self */ public static function userInformationCannotBeUpdated(): self { return new self(_('User information cannot be updated')); } /** * @param \Throwable $ex * @return self */ public static function cannotLogout(\Throwable $ex): self { return new self(_('User cannot be logout'), 0, $ex); } /** * @return self */ public static function cannotRefreshToken(): self { return new self(_('Error while refresh token')); } /** * @return self */ public static function sessionExpired(): self { return new self(_('Your session has expired')); } /** * @param \Throwable $ex * @return self */ public static function deleteExpireToken(\Throwable $ex): self { return new self(_('Error while deleting expired token'), 0, $ex); } /** * @param \Throwable $ex * @return self */ public static function addAuthenticationToken(\Throwable $ex): self { return new self(_('Error while adding authentication token'), 0, $ex); } /** * @param \Throwable $ex * @return self */ public static function deleteSession(\Throwable $ex): self { return new self(_('Error while deleting session'), 0, $ex); } /** * @param \Throwable $ex * @return self */ public static function findAuthenticationToken(\Throwable $ex): self { return new self(_('Error while searching authentication tokens'), 0, $ex); } /** * @param \Throwable $ex * @return self */ public static function updateAuthenticationTokens(\Throwable $ex): self { return new self(_('Error while updating authentication tokens'), 0, $ex); } /** * @return self */ public static function authenticationTokenExpired(): self { return new self(_('Authentication token expired')); } /** * @return self */ public static function authenticationTokenNotFound(): self { return new self(_('Authentication token not found')); } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Broker/BrokerConfiguration.php
centreon/src/Centreon/Domain/Broker/BrokerConfiguration.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Broker; class BrokerConfiguration { /** * Configuration Id * @var int|null */ private $id; /** * Configuration Broker Key * * @var string|null */ private $configurationKey; /** * Configuration Broker Value * * @var string */ private $configurationValue; /** * @return int|null */ public function getId(): ?int { return $this->id; } /** * @param int|null $id * @return self */ public function setId(?int $id): self { $this->id = $id; return $this; } /** * @return string|null */ public function getConfigurationKey(): ?string { return $this->configurationKey; } /** * @param string|null $configurationKey * @return self */ public function setConfigurationKey(?string $configurationKey): self { $this->configurationKey = $configurationKey; return $this; } /** * @return string|null */ public function getConfigurationValue(): ?string { return $this->configurationValue; } /** * @param string|null $configurationValue * @return self */ public function setConfigurationValue(?string $configurationValue): self { $this->configurationValue = $configurationValue; return $this; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Broker/BrokerException.php
centreon/src/Centreon/Domain/Broker/BrokerException.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Broker; class BrokerException extends \Exception { }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Broker/Interfaces/BrokerRepositoryInterface.php
centreon/src/Centreon/Domain/Broker/Interfaces/BrokerRepositoryInterface.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Broker\Interfaces; use Centreon\Domain\Broker\BrokerConfiguration; interface BrokerRepositoryInterface { /** * @param int $monitoringServerId * @param string $configKey * @return BrokerConfiguration[] */ public function findByMonitoringServerAndParameterName( int $monitoringServerId, string $configKey, ): array; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Contact/ContactProvider.php
centreon/src/Centreon/Domain/Contact/ContactProvider.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Contact; use Centreon\Domain\Contact\Interfaces\ContactRepositoryInterface; use Symfony\Component\Security\Core\Exception\UserNotFoundException; use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\UserProviderInterface; /** * @package Centreon */ class ContactProvider implements UserProviderInterface { private ContactRepositoryInterface $contactRepository; /** * ContactProvider constructor. * * @param ContactRepositoryInterface $contactRepository */ public function __construct(ContactRepositoryInterface $contactRepository) { $this->contactRepository = $contactRepository; } /** * Loads the user for the given username. * * This method must throw UsernameNotFoundException if the user is not * found. * * @param string $username The username * * @throws UserNotFoundException if the user is not found * @throws \Exception * @return UserInterface */ public function loadUserByUsername(string $username): UserInterface { $contact = $this->contactRepository->findByName($username); if (is_null($contact)) { throw new UserNotFoundException(); } return $contact; } /** * @param string $identifier * * @throws \Exception * @return UserInterface */ public function loadUserByIdentifier(string $identifier): UserInterface { $contact = $this->contactRepository->findByName($identifier); if (is_null($contact)) { throw new UserNotFoundException(); } return $contact; } /** * Refreshes the user. * * It is up to the implementation to decide if the user data should be * totally reloaded (e.g. from the database), or if the UserInterface * object can just be merged into some internal array of users / identity * map. * * @param UserInterface $user * @return UserInterface */ public function refreshUser(UserInterface $user): UserInterface { return $user; } /** * Whether this provider supports the given user class. * * @param string $class * * @return bool */ public function supportsClass(string $class): bool { return $class === Contact::class; } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Contact/ContactService.php
centreon/src/Centreon/Domain/Contact/ContactService.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Contact; use Centreon\Domain\Contact\Exception\ContactServiceException; use Centreon\Domain\Contact\Interfaces\ContactInterface; use Centreon\Domain\Contact\Interfaces\ContactRepositoryInterface; use Centreon\Domain\Contact\Interfaces\ContactServiceInterface; class ContactService implements ContactServiceInterface { /** * @param ContactRepositoryInterface $contactRepository */ public function __construct(private ContactRepositoryInterface $contactRepository) { } /** * @inheritDoc */ public function addUser(ContactInterface $contact): void { } /** * @inheritDoc */ public function updateUser(ContactInterface $contact): void { } /** * @inheritDoc */ public function findContact(int $id): ?ContactInterface { return $this->contactRepository->findById($id); } /** * @inheritDoc */ public function exists(ContactInterface $contact): bool { $contact = $this->contactRepository->findById($contact->getId()); return $contact !== null; } /** * @inheritDoc */ public function findByName(string $name): ?ContactInterface { return $this->contactRepository->findByName($name); } /** * @inheritDoc */ public function findBySession(string $session): ?ContactInterface { return $this->contactRepository->findBySession($session); } /** * @inheritDoc */ public function findByAuthenticationToken(string $token): ?ContactInterface { try { return $this->contactRepository->findByAuthenticationToken($token); } catch (\Exception $ex) { throw ContactServiceException::errorWhileSearchingContact($ex); } } /** * @inheritDoc */ public function findByEmail(string $email): ?ContactInterface { return $this->contactRepository->findByEmail($email); } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Contact/Contact.php
centreon/src/Centreon/Domain/Contact/Contact.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Contact; use Centreon\Domain\Contact\Interfaces\ContactInterface; use Centreon\Domain\Menu\Model\Page; use Symfony\Component\Security\Core\User\UserInterface; class Contact implements UserInterface, ContactInterface { // global api roles public const ROLE_API_CONFIGURATION = 'ROLE_API_CONFIGURATION'; public const ROLE_API_REALTIME = 'ROLE_API_REALTIME'; // user action roles public const ROLE_HOST_CHECK = 'ROLE_HOST_CHECK'; public const ROLE_HOST_FORCED_CHECK = 'ROLE_HOST_FORCED_CHECK'; public const ROLE_SERVICE_CHECK = 'ROLE_SERVICE_CHECK'; public const ROLE_SERVICE_FORCED_CHECK = 'ROLE_SERVICE_FORCED_CHECK'; public const ROLE_HOST_ACKNOWLEDGEMENT = 'ROLE_HOST_ACKNOWLEDGEMENT'; public const ROLE_HOST_DISACKNOWLEDGEMENT = 'ROLE_HOST_DISACKNOWLEDGEMENT'; public const ROLE_SERVICE_ACKNOWLEDGEMENT = 'ROLE_SERVICE_ACKNOWLEDGEMENT'; public const ROLE_SERVICE_DISACKNOWLEDGEMENT = 'ROLE_SERVICE_DISACKNOWLEDGEMENT'; public const ROLE_CANCEL_HOST_DOWNTIME = 'ROLE_CANCEL_HOST_DOWNTIME'; public const ROLE_CANCEL_SERVICE_DOWNTIME = 'ROLE_CANCEL_SERVICE_DOWNTIME'; public const ROLE_ADD_HOST_DOWNTIME = 'ROLE_ADD_HOST_DOWNTIME'; public const ROLE_ADD_SERVICE_DOWNTIME = 'ROLE_ADD_SERVICE_DOWNTIME'; public const ROLE_SERVICE_SUBMIT_RESULT = 'ROLE_SERVICE_SUBMIT_RESULT'; public const ROLE_HOST_SUBMIT_RESULT = 'ROLE_HOST_SUBMIT_RESULT'; public const ROLE_HOST_ADD_COMMENT = 'ROLE_HOST_ADD_COMMENT'; public const ROLE_SERVICE_ADD_COMMENT = 'ROLE_SERVICE_ADD_COMMENT'; public const ROLE_DISPLAY_COMMAND = 'ROLE_DISPLAY_COMMAND'; public const ROLE_GENERATE_CONFIGURATION = 'ROLE_GENERATE_CONFIGURATION'; public const ROLE_MANAGE_TOKENS = 'ROLE_MANAGE_TOKENS'; public const ROLE_CREATE_EDIT_POLLER_CFG = 'CREATE_EDIT_POLLER_CFG'; public const ROLE_DELETE_POLLER_CFG = 'DELETE_POLLER_CFG'; public const ROLE_DISPLAY_TOP_COUNTER = 'DISPLAY_TOP_COUNTER'; public const ROLE_DISPLAY_TOP_COUNTER_POLLERS_STATISTICS = 'DISPLAY_TOP_COUNTER_POLLERS_STATISTICS'; // user pages access public const ROLE_HOME_DASHBOARD_VIEWER = 'ROLE_HOME_DASHBOARDS_VIEWER_RW'; public const ROLE_HOME_DASHBOARD_CREATOR = 'ROLE_HOME_DASHBOARDS_CREATOR_RW'; public const ROLE_HOME_DASHBOARD_ADMIN = 'ROLE_HOME_DASHBOARDS_ADMINISTRATOR_RW'; public const ROLE_CONFIGURATION_HOSTS_WRITE = 'ROLE_CONFIGURATION_HOSTS_HOSTS_RW'; public const ROLE_CONFIGURATION_HOSTS_READ = 'ROLE_CONFIGURATION_HOSTS_HOSTS_R'; public const ROLE_CONFIGURATION_SERVICES_WRITE = 'ROLE_CONFIGURATION_SERVICES_SERVICES_BY_HOST_RW'; public const ROLE_CONFIGURATION_SERVICES_READ = 'ROLE_CONFIGURATION_SERVICES_SERVICES_BY_HOST_R'; public const ROLE_CONFIGURATION_META_SERVICES_WRITE = 'ROLE_CONFIGURATION_SERVICES_META_SERVICES_RW'; public const ROLE_CONFIGURATION_META_SERVICES_READ = 'ROLE_CONFIGURATION_SERVICES_META_SERVICES_R'; public const ROLE_MONITORING_EVENT_LOGS = 'ROLE_MONITORING_EVENT_LOGS_EVENT_LOGS_RW'; public const ROLE_REPORTING_AVAILABILITY_HOSTS = 'ROLE_REPORTING_AVAILABILITY_HOSTS_RW'; public const ROLE_REPORTING_AVAILABILITY_SERVICES = 'ROLE_REPORTING_AVAILABILITY_SERVICES_RW'; public const ROLE_CONFIGURATION_MONITORING_SERVER_READ_WRITE = 'ROLE_CONFIGURATION_POLLERS_POLLERS_RW'; public const ROLE_CONFIGURATION_MONITORING_SERVER_READ = 'ROLE_CONFIGURATION_POLLERS_POLLERS_R'; public const ROLE_CONFIGURATION_HOSTS_HOST_GROUPS_READ_WRITE = 'ROLE_CONFIGURATION_HOSTS_HOST_GROUPS_RW'; public const ROLE_CONFIGURATION_HOSTS_HOST_GROUPS_READ = 'ROLE_CONFIGURATION_HOSTS_HOST_GROUPS_R'; public const ROLE_CONFIGURATION_SERVICES_SERVICE_GROUPS_READ_WRITE = 'ROLE_CONFIGURATION_SERVICES_SERVICE_GROUPS_RW'; public const ROLE_CONFIGURATION_SERVICES_SERVICE_GROUPS_READ = 'ROLE_CONFIGURATION_SERVICES_SERVICE_GROUPS_R'; public const ROLE_CONFIGURATION_CONTACTS_READ_WRITE = 'ROLE_CONFIGURATION_USERS_CONTACTS__USERS_RW'; public const ROLE_CONFIGURATION_CONTACTS_READ = 'ROLE_CONFIGURATION_USERS_CONTACTS__USERS_R'; public const ROLE_CONFIGURATION_USERS_CONTACT_GROUPS_READ_WRITE = 'ROLE_CONFIGURATION_USERS_CONTACT_GROUPS_RW'; public const ROLE_CONFIGURATION_CONTACT_TEMPLATES_READ = 'ROLE_CONFIGURATION_USERS_CONTACT_TEMPLATES_R'; public const ROLE_CONFIGURATION_CONTACT_TEMPLATES_READ_WRITE = 'ROLE_CONFIGURATION_USERS_CONTACT_TEMPLATES_RW'; public const ROLE_CONFIGURATION_USERS_CONTACT_GROUPS_READ = 'ROLE_CONFIGURATION_USERS_CONTACT_GROUPS_R'; public const ROLE_CONFIGURATION_TIME_PERIODS_READ_WRITE = 'ROLE_CONFIGURATION_USERS_TIME_PERIODS_RW'; public const ROLE_CONFIGURATION_TIME_PERIODS_READ = 'ROLE_CONFIGURATION_USERS_TIME_PERIODS_R'; public const ROLE_CONFIGURATION_HOSTS_CATEGORIES_READ = 'ROLE_CONFIGURATION_HOSTS_CATEGORIES_R'; public const ROLE_CONFIGURATION_HOSTS_CATEGORIES_READ_WRITE = 'ROLE_CONFIGURATION_HOSTS_CATEGORIES_RW'; public const ROLE_CONFIGURATION_SERVICES_CATEGORIES_READ_WRITE = 'ROLE_CONFIGURATION_SERVICES_CATEGORIES_RW'; public const ROLE_CONFIGURATION_SERVICES_CATEGORIES_READ = 'ROLE_CONFIGURATION_SERVICES_CATEGORIES_R'; public const ROLE_ADMINISTRATION_AUTHENTICATION_READ_WRITE = 'ROLE_ADMINISTRATION_AUTHENTICATION_RW'; public const ROLE_CONFIGURATION_NOTIFICATIONS_READ_WRITE = 'ROLE_CONFIGURATION_NOTIFICATIONS_RW'; public const ROLE_CONFIGURATION_HOSTS_TEMPLATES_READ_WRITE = 'ROLE_CONFIGURATION_HOSTS_TEMPLATES_RW'; public const ROLE_CONFIGURATION_HOSTS_TEMPLATES_READ = 'ROLE_CONFIGURATION_HOSTS_TEMPLATES_R'; public const ROLE_CONFIGURATION_SERVICES_TEMPLATES_READ_WRITE = 'ROLE_CONFIGURATION_SERVICES_TEMPLATES_RW'; public const ROLE_CONFIGURATION_SERVICES_TEMPLATES_READ = 'ROLE_CONFIGURATION_SERVICES_TEMPLATES_R'; public const ROLE_CONFIGURATION_COMMANDS_CHECKS_R = 'ROLE_CONFIGURATION_COMMANDS_CHECKS_R'; public const ROLE_CONFIGURATION_COMMANDS_CHECKS_RW = 'ROLE_CONFIGURATION_COMMANDS_CHECKS_RW'; public const ROLE_CONFIGURATION_COMMANDS_NOTIFICATIONS_R = 'ROLE_CONFIGURATION_COMMANDS_NOTIFICATIONS_R'; public const ROLE_CONFIGURATION_COMMANDS_NOTIFICATIONS_RW = 'ROLE_CONFIGURATION_COMMANDS_NOTIFICATIONS_RW'; public const ROLE_CONFIGURATION_COMMANDS_MISCELLANEOUS_R = 'ROLE_CONFIGURATION_COMMANDS_MISCELLANEOUS_R'; public const ROLE_CONFIGURATION_COMMANDS_MISCELLANEOUS_RW = 'ROLE_CONFIGURATION_COMMANDS_MISCELLANEOUS_RW'; public const ROLE_CONFIGURATION_COMMANDS_DISCOVERY_R = 'ROLE_CONFIGURATION_COMMANDS_DISCOVERY_R'; public const ROLE_CONFIGURATION_COMMANDS_DISCOVERY_RW = 'ROLE_CONFIGURATION_COMMANDS_DISCOVERY_RW'; public const ROLE_CONFIGURATION_GRAPH_TEMPLATES_R = 'ROLE_MONITORING_PERFORMANCES_TEMPLATES_R'; public const ROLE_CONFIGURATION_GRAPH_TEMPLATES_RW = 'ROLE_MONITORING_PERFORMANCES_TEMPLATES_RW'; public const ROLE_CONFIGURATION_CONNECTORS_R = 'ROLE_CONFIGURATION_COMMANDS_CONNECTORS_R'; public const ROLE_CONFIGURATION_CONNECTORS_RW = 'ROLE_CONFIGURATION_COMMANDS_CONNECTORS_RW'; public const ROLE_ADMINISTRATION_AUTHENTICATION_TOKENS_RW = 'ROLE_ADMINISTRATION_AUTHENTICATION_TOKENS_RW'; public const ROLE_ADMINISTRATION_PARAMETERS_IMAGES_RW = 'ROLE_ADMINISTRATION_PARAMETERS_IMAGES_RW'; public const ROLE_ADMINISTRATION_ACL_RESOURCE_ACCESS_MANAGEMENT_RW = 'ROLE_ADMINISTRATION_ACL_RESOURCE_ACCESS_MANAGEMENT_RW'; public const ROLE_ADMINISTRATION_PARAMETERS_MONITORING_RW = 'ROLE_ADMINISTRATION_PARAMETERS_MONITORING_RW'; public const ROLE_MONITORING_RESOURCES_STATUS_RW = 'ROLE_MONITORING_RESOURCES_STATUS_RW'; public const ROLE_CONFIGURATION_BROKER_RW = 'ROLE_CONFIGURATION_POLLERS_BROKER_CONFIGURATION_RW'; public const ROLE_MONITORING_PERFORMANCES_RW = 'ROLE_MONITORING_PERFORMANCES_RW'; public const ROLE_MONITORING_RW = 'ROLE_MONITORING_RW'; public const ROLE_CONFIGURATION_ACC_RW = 'ROLE_CONFIGURATION_CONNECTORS_ADDITIONAL_CONFIGURATIONS_RW'; public const ROLE_CONFIGURATION_POLLERS_AGENT_CONFIGURATIONS_RW = 'ROLE_CONFIGURATION_POLLERS_AGENT_CONFIGURATIONS_RW'; public const ROLE_CONFIGURATION_POLLERS_GLOBAL_MACRO_RW = 'ROLE_CONFIGURATION_POLLERS_RESOURCES_RW'; /** * @var string */ public const DEFAULT_LOCALE = 'en_US'; /** * @var string */ public const DEFAULT_CHARSET = 'UTF-8'; /** @var int Id of contact */ private $id; /** @var string Name of contact */ private $name; /** @var string Alias of contact */ private $alias; /** @var string Language of contact */ private $lang; /** @var string Email of contact */ private $email; /** @var bool Is an admin contact ? */ private $isAdmin; /** @var int|null Id of the contact template */ private $templateId; /** @var bool Indicates whether this contact is enabled or disabled */ private $isActive; /** @var bool Indicates whether this contact is allowed to reach centreon application */ private $isAllowedToReachWeb; /** @var string|null Authentication Token */ private $token; /** @var string|null Encoded password */ private $encodedPassword; /** @var bool Indicates if this user has access to the configuration section of API */ private $hasAccessToApiConfiguration; /** @var bool Indicates if this user has access to the real time section of API */ private $hasAccessToApiRealTime; /** @var string[] */ private $roles = []; /** @var string[] List of names of topology rules to which the contact can access */ private $topologyRulesNames = []; /** @var \DateTimeZone timezone of the user */ private $timezone; /** @var int */ private int $timezoneId; /** @var string|null locale of the user */ private $locale; /** @var Page|null */ private $defaultPage; /** * Indicates if user uses deprecated pages * * @var bool */ private $useDeprecatedPages; private bool $useDeprecatedCustomViews; /** @var string|null */ private $theme; /** @var string|null */ private $userInterfaceDensity; /** * @param int $timezoneId * * @return self */ public function setTimezoneId(int $timezoneId): self { $this->timezoneId = $timezoneId; return $this; } /** * @return int */ public function getTimezoneId(): int { return $this->timezoneId; } /** * @return int */ public function getId(): int { return $this->id; } /** * @param int $id * * @return self */ public function setId(int $id): self { $this->id = $id; return $this; } /** * @return string */ public function getName(): string { return $this->name; } /** * @param string $name * * @return self */ public function setName(string $name): self { $this->name = $name; return $this; } /** * @return string */ public function getAlias(): string { return $this->alias; } /** * @param string $alias * * @return self */ public function setAlias(string $alias): self { $this->alias = $alias; return $this; } /** * @return string */ public function getLang(): string { return $this->lang; } /** * @param string $lang * * @return self */ public function setLang(string $lang): self { $this->lang = $lang; return $this; } /** * @return string */ public function getEmail(): string { return $this->email; } /** * @param string $email * * @return self */ public function setEmail(string $email): self { $this->email = $email; return $this; } /** * @inheritDoc */ public function isAdmin(): bool { return $this->isAdmin; } /** * Set if the user is admin or not. * * @param bool $isAdmin * * @return self */ public function setAdmin(bool $isAdmin): self { $this->isAdmin = $isAdmin; if ($this->isAdmin) { $this->addRole(self::ROLE_API_REALTIME); $this->addRole(self::ROLE_API_CONFIGURATION); } return $this; } /** * @return int|null */ public function getTemplateId(): ?int { return $this->templateId; } /** * @param int|null $templateId * * @return self */ public function setTemplateId(?int $templateId): self { $this->templateId = $templateId; return $this; } /** * @return bool */ public function isActive(): bool { return $this->isActive; } /** * @param bool $isActive * * @return self */ public function setIsActive(bool $isActive): self { $this->isActive = $isActive; return $this; } /** * @inheritDoc */ public function isAllowedToReachWeb(): bool { return $this->isAllowedToReachWeb; } /** * @inheritDoc */ public function setAllowedToReachWeb(bool $isAllowed): static { $this->isAllowedToReachWeb = $isAllowed; return $this; } /** * @return string|null */ public function getToken(): ?string { return $this->token; } /** * @param string|null $token * * @return self */ public function setToken(?string $token): self { $this->token = $token; return $this; } /** * @return string|null */ public function getEncodedPassword(): ?string { return $this->encodedPassword; } /** * @param string|null $encodedPassword * * @return self */ public function setEncodedPassword(?string $encodedPassword): self { $this->encodedPassword = $encodedPassword; return $this; } /** * Returns the roles granted to the user. * * public function getRoles() * { * return array('ROLE_USER'); * } * * Alternatively, the roles might be stored on a ``roles`` property, * and populated in any number of different ways when the user object * is created. * * @return string[] The user roles */ public function getRoles(): array { return $this->roles; } /** * @inheritDoc */ public function setRoles(array $roles): self { $this->roles = []; foreach ($roles as $role) { $this->addRole($role); } return $this; } /** * @inheritDoc */ public function getTopologyRules(): array { return $this->topologyRulesNames; } /** * @inheritDoc */ public function setTopologyRules(array $topologyRoles): self { $this->topologyRulesNames = []; foreach ($topologyRoles as $topologyRole) { $this->addTopologyRule($topologyRole); } return $this; } /** * Returns the password used to authenticate the user. * * This should be the encoded password. On authentication, a plain-text * password will be salted, encoded, and then compared to this value. * * @return string|null The password */ public function getPassword(): ?string { return $this->token; } /** * Returns the salt that was originally used to encode the password. * * This can return null if the password was not encoded using a salt. * * @return string|null The salt */ public function getSalt() { return null; } /** * Returns the username used to authenticate the user. * * @return string The username */ public function getUsername() { return $this->name; } /** * Removes sensitive data from the user. * * This is important if, at any given point, sensitive information like * the plain-text password is stored on this object. */ public function eraseCredentials(): void { // Nothing to do. But we must to define this method } /** * @inheritDoc */ public function hasAccessToApiConfiguration(): bool { return $this->hasAccessToApiConfiguration; } /** * @inheritDoc */ public function setAccessToApiConfiguration(bool $hasAccessToApiConfiguration): static { $this->hasAccessToApiConfiguration = $hasAccessToApiConfiguration; if ($this->hasAccessToApiConfiguration) { $this->addRole(self::ROLE_API_CONFIGURATION); } else { $this->removeRole(self::ROLE_API_CONFIGURATION); } return $this; } /** * @inheritDoc */ public function hasAccessToApiRealTime(): bool { return $this->hasAccessToApiRealTime; } /** * @inheritDoc */ public function setAccessToApiRealTime(bool $hasAccessToApiRealTime): static { $this->hasAccessToApiRealTime = $hasAccessToApiRealTime; if ($this->hasAccessToApiRealTime) { $this->addRole(self::ROLE_API_REALTIME); } else { $this->removeRole(self::ROLE_API_REALTIME); } return $this; } /** * @inheritDoc */ public function hasRole(string $role): bool { return in_array($role, $this->roles); } /** * @inheritDoc */ public function hasTopologyRole(string $role): bool { return in_array($role, $this->topologyRulesNames); } /** * Add a specific role to this user. * * @param string $roleName Role name to add */ public function addRole(string $roleName): void { if (! in_array($roleName, $this->roles)) { $this->roles[] = $roleName; } } /** * Added a topology rule. * * @param string $topologyRuleName Topology rule name */ public function addTopologyRule(string $topologyRuleName): void { if (! in_array($topologyRuleName, $this->topologyRulesNames)) { $this->topologyRulesNames[] = $topologyRuleName; } } /** * timezone setter * * @param \DateTimeZone $timezone * * @return self */ public function setTimezone(\DateTimeZone $timezone): self { $this->timezone = $timezone; return $this; } /** * timezone getter * * @return \DateTimeZone */ public function getTimezone(): \DateTimeZone { return $this->timezone; } /** * locale setter * * @param string|null $locale * * @return self */ public function setLocale(?string $locale): self { $this->locale = $locale; return $this; } /** * locale getter * * @return string|null */ public function getLocale(): ?string { return $this->locale; } /** * @inheritDoc */ public function setDefaultPage(?Page $defaultPage): static { $this->defaultPage = $defaultPage; return $this; } /** * get user default page * * @return Page|null */ public function getDefaultPage(): ?Page { return $this->defaultPage; } /** * @inheritDoc */ public function isUsingDeprecatedPages(): bool { return $this->useDeprecatedPages; } /** * @inheritDoc */ public function setUseDeprecatedPages(bool $useDeprecatedPages): static { $this->useDeprecatedPages = $useDeprecatedPages; return $this; } public function isUsingDeprecatedCustomViews(): bool { return $this->useDeprecatedCustomViews; } public function setUseDeprecatedCustomViews(bool $useDeprecatedCustomViews): static { $this->useDeprecatedCustomViews = $useDeprecatedCustomViews; return $this; } /** * @inheritDoc */ public function getUserIdentifier(): string { return $this->alias; } /** * Set user current theme. * * @param string $theme user's new theme * * @return self */ public function setTheme(string $theme): self { $this->theme = $theme; return $this; } /** * Get user current theme. * * @return string|null */ public function getTheme(): ?string { return $this->theme; } /** * @param string|null $userInterfaceDensity * * @return $this */ public function setUserInterfaceDensity(?string $userInterfaceDensity): self { $this->userInterfaceDensity = $userInterfaceDensity; return $this; } /** * @return string|null */ public function getUserInterfaceDensity(): ?string { return $this->userInterfaceDensity; } /** * @return string */ public function getFormatDate(): string { $dateFormatter = new \IntlDateFormatter( $this->getLocale(), \IntlDateFormatter::SHORT, \IntlDateFormatter::SHORT, $this->getTimezone() ); $format = $dateFormatter->getPattern(); return $this->convertIntlPatternToDateTimeFormat($format); } /** * Removes an existing roles. * * @param string $roleName Role name to remove */ private function removeRole(string $roleName): void { if (($index = array_search($roleName, $this->roles)) !== false) { unset($this->roles[$index]); } } /** * IntlDateFormatter used a different format than DateTime::format. * This method converts IntlDateFormatter pattern to DateTime format. * * @param string $intlPattern * * @return string */ private function convertIntlPatternToDateTimeFormat(string $intlPattern): string { $intlToPhp = [ 'yyyy' => 'Y', 'yy' => 'y', 'MMMM' => 'F', 'MMM' => 'M', 'MM' => 'm', 'M' => 'n', 'dd' => 'd', 'd' => 'j', 'EEEE' => 'l', 'EEE' => 'D', 'HH' => 'H', 'H' => 'G', 'hh' => 'h', 'h' => 'g', 'mm' => 'i', 'ss' => 's', 'SSS' => 'u', 'a' => 'A', 'zzzz' => 'e', 'zzz' => 'T', 'zz' => 'T', 'z' => 'T', ]; return strtr($intlPattern, $intlToPhp); } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Contact/Interfaces/ContactServiceInterface.php
centreon/src/Centreon/Domain/Contact/Interfaces/ContactServiceInterface.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Contact\Interfaces; interface ContactServiceInterface { /** * Find a contact based on its name. * * @param string $name Contact name * @return ContactInterface|null */ public function findByName(string $name): ?ContactInterface; /** * Find a contact based on its email. * * @param string $email Contact email * @return ContactInterface|null */ public function findByEmail(string $email): ?ContactInterface; /** * Find a contact based on their session number. * * @param string $session Contact session number * @return ContactInterface|null */ public function findBySession(string $session): ?ContactInterface; /** * Find a contact based on its id * * @param int $id * @return ContactInterface|null */ public function findContact(int $id): ?ContactInterface; /** * Find a contact by an authentication token * @param string $token * @return ContactInterface|null */ public function findByAuthenticationToken(string $token): ?ContactInterface; /** * Indicates whether or not the contact exists. * * @param ContactInterface $contact * @return bool */ public function exists(ContactInterface $contact): bool; /** * Add the contact. * * @param ContactInterface $contact Contact to be added */ public function addUser(ContactInterface $contact): void; /** * Update the contact. * * @param ContactInterface $contact Contact to be updated */ public function updateUser(ContactInterface $contact): void; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Contact/Interfaces/ContactFilterInterface.php
centreon/src/Centreon/Domain/Contact/Interfaces/ContactFilterInterface.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Contact\Interfaces; interface ContactFilterInterface { /** * Used to filter requests according to a contact. * If the filter is defined, all requests will use the ACL of the contact * to fetch data. * * @param mixed $contact Contact to use as a ACL filter * @throws \Exception */ public function filterByContact($contact); }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Contact/Interfaces/ContactRepositoryInterface.php
centreon/src/Centreon/Domain/Contact/Interfaces/ContactRepositoryInterface.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Contact\Interfaces; use Centreon\Domain\Contact\Contact; interface ContactRepositoryInterface { /** * Find a contact by name. * * @param string $name Username * @throws \Exception * @return Contact|null */ public function findByName(string $name): ?Contact; /** * Find a contact by email. * * @param string $email email * @throws \Exception * @return Contact|null */ public function findByEmail(string $email): ?Contact; /** * Find a contact by id * * @param int $contactId Contact id * @return Contact|null */ public function findById(int $contactId): ?Contact; /** * Find a contact based on their session id * * @param string $sessionId Session id * @return Contact|null */ public function findBySession(string $sessionId): ?Contact; /** * Find a contact by an authentication token * @param string $token * @return Contact|null */ public function findByAuthenticationToken(string $token): ?Contact; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Contact/Interfaces/ContactInterface.php
centreon/src/Centreon/Domain/Contact/Interfaces/ContactInterface.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Contact\Interfaces; use Centreon\Domain\Menu\Model\Page; interface ContactInterface { /** * @return int Returns the timezone id */ public function getTimezoneId(): int; /** * @return int Returns the contact id */ public function getId(): int; /** * Indicates whether the contact is an administrator. * * @return bool */ public function isAdmin(): bool; /** * Indicates whether the contact is active. * * @return bool */ public function isActive(): bool; /** * Indicates whether the contact is allowed to reach web application. * * @return bool */ public function isAllowedToReachWeb(): bool; /** * Allow user or not to reach web application. * * @param bool $isAllowed * @return static */ public function setAllowedToReachWeb(bool $isAllowed): static; /** * Contact name. * * @return string */ public function getName(): string; /** * Contact alias. * * @return string */ public function getAlias(): string; /** * Contact lang. * * @return string */ public function getLang(): string; /** * Contact email. * * @return string */ public function getEmail(): string; /** * Contact template id. * * @return int|null */ public function getTemplateId(): ?int; /** * Contact token. * * @return string|null */ public function getToken(): ?string; /** * Contact encoded password. * * @return string|null */ public function getEncodedPassword(): ?string; /** * Returns the roles granted to the user. * * public function getRoles() * { * return array('ROLE_USER'); * } * * Alternatively, the roles might be stored on a ``roles`` property, * and populated in any number of different ways when the user object * is created. * * @return string[] The user roles */ public function getRoles(): array; /** * @param string[] $roles * @return self */ public function setRoles(array $roles): self; /** * @return string[] */ public function getTopologyRules(): array; /** * @param string[] $topologyRoles * @return self */ public function setTopologyRules(array $topologyRoles): self; /** * Indicates if this user has a role. * * @param string $role Role name to find * @return bool */ public function hasRole(string $role): bool; /** * Indicates if this user has a topology access. * * @param string $role Role name to find * @return bool */ public function hasTopologyRole(string $role): bool; /** * Contact timezone. * * @return \DateTimeZone */ public function getTimezone(): \DateTimeZone; /** * Contact locale. * * @return string|null */ public function getLocale(): ?string; /** * Contact default page. * * @return Page|null */ public function getDefaultPage(): ?Page; /** * @param Page|null $defaultPage * @return static */ public function setDefaultPage(?Page $defaultPage): static; /** * Indicates if user uses deprecated pages * * @return bool */ public function isUsingDeprecatedPages(): bool; /** * @param bool $useDeprecatedPages Indicates if user uses deprecated pages * @return static */ public function setUseDeprecatedPages(bool $useDeprecatedPages): static; public function isUsingDeprecatedCustomViews(): bool; public function setUseDeprecatedCustomViews(bool $useDeprecatedCustomViews): static; /** * @return bool */ public function hasAccessToApiConfiguration(): bool; /** * @param bool $hasAccessToApiConfiguration * @return static */ public function setAccessToApiConfiguration(bool $hasAccessToApiConfiguration): static; /** * @return bool */ public function hasAccessToApiRealTime(): bool; /** * @param bool $hasAccessToApiRealTime * @return static */ public function setAccessToApiRealTime(bool $hasAccessToApiRealTime): static; /** * @return string|null */ public function getTheme(): ?string; /** * @return string|null */ public function getUserInterfaceDensity(): ?string; /** * @return string */ public function getFormatDate(): string; }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/Contact/Exception/ContactServiceException.php
centreon/src/Centreon/Domain/Contact/Exception/ContactServiceException.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\Contact\Exception; /** * @package Centreon\Domain\Contact\Exception */ class ContactServiceException extends \Exception { /** * @param \Throwable $ex * @return self */ public static function errorWhileSearchingContact(\Throwable $ex): self { return new self(_('Error while searching contact'), 0, $ex); } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/RemoteServer/RemoteServerException.php
centreon/src/Centreon/Domain/RemoteServer/RemoteServerException.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\RemoteServer; class RemoteServerException extends \Exception { }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Centreon/Domain/RemoteServer/RemoteServerService.php
centreon/src/Centreon/Domain/RemoteServer/RemoteServerService.php
<?php /* * Copyright 2005 - 2025 Centreon (https://www.centreon.com/) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * For more information : contact@centreon.com * */ declare(strict_types=1); namespace Centreon\Domain\RemoteServer; use Centreon\Domain\Exception\EntityNotFoundException; use Centreon\Domain\Menu\Interfaces\MenuRepositoryInterface; use Centreon\Domain\Menu\MenuException; use Centreon\Domain\MonitoringServer\Interfaces\MonitoringServerServiceInterface; use Centreon\Domain\PlatformInformation\Model\PlatformInformation; use Centreon\Domain\PlatformTopology\Exception\PlatformTopologyException; use Centreon\Domain\PlatformTopology\Interfaces\PlatformTopologyRegisterRepositoryInterface; use Centreon\Domain\PlatformTopology\Interfaces\PlatformTopologyRepositoryExceptionInterface; use Centreon\Domain\PlatformTopology\Interfaces\PlatformTopologyRepositoryInterface; use Centreon\Domain\PlatformTopology\Model\PlatformRegistered; use Centreon\Domain\Proxy\Interfaces\ProxyServiceInterface; use Centreon\Domain\RemoteServer\Interfaces\RemoteServerLocalConfigurationRepositoryInterface; use Centreon\Domain\RemoteServer\Interfaces\RemoteServerServiceInterface; class RemoteServerService implements RemoteServerServiceInterface { /** @var MenuRepositoryInterface */ private $menuRepository; /** @var PlatformTopologyRepositoryInterface */ private $platformTopologyRepository; /** @var RemoteServerLocalConfigurationRepositoryInterface */ private $remoteServerRepository; /** @var PlatformTopologyRegisterRepositoryInterface */ private $platformTopologyRegisterRepository; /** @var ProxyServiceInterface */ private $proxyService; /** @var MonitoringServerServiceInterface */ private $monitoringServerService; /** * @param MenuRepositoryInterface $menuRepository * @param PlatformTopologyRepositoryInterface $platformTopologyRepository * @param RemoteServerLocalConfigurationRepositoryInterface $remoteServerRepository * @param PlatformTopologyRegisterRepositoryInterface $platformTopologyRegisterRepository * @param ProxyServiceInterface $proxyService * @param MonitoringServerServiceInterface $monitoringServerService */ public function __construct( MenuRepositoryInterface $menuRepository, PlatformTopologyRepositoryInterface $platformTopologyRepository, RemoteServerLocalConfigurationRepositoryInterface $remoteServerRepository, PlatformTopologyRegisterRepositoryInterface $platformTopologyRegisterRepository, ProxyServiceInterface $proxyService, MonitoringServerServiceInterface $monitoringServerService, ) { $this->menuRepository = $menuRepository; $this->platformTopologyRepository = $platformTopologyRepository; $this->remoteServerRepository = $remoteServerRepository; $this->platformTopologyRegisterRepository = $platformTopologyRegisterRepository; $this->proxyService = $proxyService; $this->monitoringServerService = $monitoringServerService; } /** * @inheritDoc */ public function convertCentralToRemote(PlatformInformation $platformInformation): void { /** * Stop conversion if the Central has remote children */ try { $platformChildren = $this->platformTopologyRepository->findCentralRemoteChildren(); if (! empty($platformChildren)) { throw new RemoteServerException( _("Your Central is linked to another remote(s), conversion in Remote isn't allowed") ); } } catch (RemoteServerException $ex) { throw $ex; } catch (\Exception $ex) { throw new RemoteServerException(_('An error occurred while searching any remote children'), 0, $ex); } /** * Set Remote type into Platform_Topology */ $this->updatePlatformTypeParameters(PlatformRegistered::TYPE_REMOTE); /** * Get the parent platform to register it later. */ $topLevelPlatform = $this->platformTopologyRepository->findTopLevelPlatform(); if ($topLevelPlatform === null) { throw new EntityNotFoundException(_('No top level platform found to link the child platforms')); } /** * Add the future Parent Central as Parent Address to be able to register it later. */ $topLevelPlatform->setParentAddress($platformInformation->getCentralServerAddress()); if ($platformInformation->getPlatformName() !== null) { $topLevelPlatform->setName($platformInformation->getPlatformName()); } $topLevelPlatform->setAddress($platformInformation->getAddress()); /** * Find any children platform and forward them to Central Parent. */ $platforms = $this->platformTopologyRepository->findChildrenPlatformsByParentId( $topLevelPlatform->getId() ); /** * Insert the Top Level Platform at the beginning of array, as it need to be registered first. */ array_unshift($platforms, $topLevelPlatform); /** * Register the platforms on the Parent Central */ try { foreach ($platforms as $platform) { if ($platform->getParentId() !== null) { $platform->setParentAddress($topLevelPlatform->getAddress()); } if ($platform->getServerId() !== null) { $this->platformTopologyRegisterRepository->registerPlatformToParent( $platform, $platformInformation, $this->proxyService->getProxy() ); } } $this->menuRepository->disableCentralMenus(); } catch (PlatformTopologyRepositoryExceptionInterface|PlatformTopologyException $ex) { $this->updatePlatformTypeParameters(PlatformRegistered::TYPE_CENTRAL); throw $ex; } catch (\Exception $ex) { $this->updatePlatformTypeParameters(PlatformRegistered::TYPE_CENTRAL); throw new MenuException(_('An error occurred while disabling the central menus')); } /** * Apply Remote Server mode in configuration file */ $this->remoteServerRepository->updateInstanceModeRemote(); } /** * @inheritDoc */ public function convertRemoteToCentral(PlatformInformation $platformInformation): void { /** * Delete the platform on its parent before anything else, * If this step throw an exception, don't go further and avoid decorelation betweens platforms. */ $platform = $this->platformTopologyRepository->findTopLevelPlatform(); $this->platformTopologyRegisterRepository->deletePlatformToParent( $platform, $platformInformation, $this->proxyService->getProxy() ); /** * Find any children platform and remove them, * as they are now attached to the Central and no longer to this platform. */ $childrenPlatforms = $this->platformTopologyRepository->findChildrenPlatformsByParentId( $platform->getId() ); foreach ($childrenPlatforms as $childrenPlatform) { if ($childrenPlatform->getServerId() !== null) { $this->monitoringServerService->deleteServer($childrenPlatform->getServerId()); } $this->platformTopologyRepository->deletePlatform($childrenPlatform->getId()); } /** * Set Central type into Platform_Topology */ $this->updatePlatformTypeParameters(PlatformRegistered::TYPE_CENTRAL); try { $this->menuRepository->enableCentralMenus(); } catch (\Exception $ex) { throw new MenuException(_('An error occurred while enabling the central menus')); } /** * Apply Central mode in configuration file */ $this->remoteServerRepository->updateInstanceModeCentral(); } /** * Update the platform type * @param string $type * @throws PlatformTopologyException */ private function updatePlatformTypeParameters(string $type): void { try { $platform = $this->platformTopologyRepository->findTopLevelPlatform(); $platform->setType($type); $this->platformTopologyRepository->updatePlatformParameters($platform); } catch (\Exception $ex) { throw new PlatformTopologyException(_('An error occurred while updating the platform topology')); } } }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false