Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/app/code/Cnc/SerialNumber/Model/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/app/code/Cnc/SerialNumber/Model/SerialNumberRepository.php
<?php
/**
 * Copyright (c) 2020 Kaliop Digital Commerce (https://digitalcommerce.kaliop.com) All Rights Reserved.
 * https://opensource.org/licenses/OSL-3.0  Open Software License (OSL 3.0)
 * Krzysztof Majkowski <[email protected]>
 */

declare(strict_types=1);

namespace Cnc\SerialNumber\Model;

use Cnc\SerialNumber\Api\Data\SerialNumberInterface;
use Cnc\SerialNumber\Api\Data\SerialNumberSearchResultsInterface;
use Cnc\SerialNumber\Api\Data\SerialNumberSearchResultsInterfaceFactory;
use Cnc\SerialNumber\Api\SerialNumberRepositoryInterface;
use Cnc\SerialNumber\Model\ResourceModel\SerialNumber as SerialNumberResource;
use Cnc\SerialNumber\Model\ResourceModel\SerialNumber\CollectionFactory as SerialNumberCollectionFactory;
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
use Magento\Framework\Api\SearchCriteriaInterface;
use Magento\Framework\Exception\NoSuchEntityException;

class SerialNumberRepository implements SerialNumberRepositoryInterface
{
    /**
     * @var array
     */
    private $cacheInstances = [];

    /**
     * @var SerialNumberFactory
     */
    private $serialNumberFactory;

    /**
     * @var SerialNumberResource
     */
    private $serialNumberResource;

    /**
     * @var SerialNumberCollectionFactory
     */
    private $serialNumberCollectionFactory;

    /**
     * @var CollectionProcessorInterface
     */
    private $collectionProcessor;

    /**
     * @var SerialNumberSearchResultsInterfaceFactory
     */
    private $serialNumberSearchResultFactory;

    /**
     * SerialNumberRepository constructor.
     * @param SerialNumberFactory $serialNumberFactory
     * @param SerialNumberResource $serialNumberResource
     * @param SerialNumberCollectionFactory $serialNumberCollectionFactory
     * @param CollectionProcessorInterface $collectionProcessor
     * @param SerialNumberSearchResultsInterfaceFactory $serialNumberSearchResultFactory
     */
    public function __construct(
        SerialNumberFactory $serialNumberFactory,
        SerialNumberResource $serialNumberResource,
        SerialNumberCollectionFactory $serialNumberCollectionFactory,
        SerialNumberSearchResultsInterfaceFactory $serialNumberSearchResultFactory,
        CollectionProcessorInterface $collectionProcessor
    ) {
        $this->serialNumberFactory = $serialNumberFactory;
        $this->serialNumberResource = $serialNumberResource;
        $this->serialNumberCollectionFactory = $serialNumberCollectionFactory;
        $this->serialNumberSearchResultFactory = $serialNumberSearchResultFactory;
        $this->collectionProcessor = $collectionProcessor;
    }

    /**
     * {@inheritDoc}
     */
    public function getById(int $id): SerialNumberInterface
    {
        $key = $this->getKey($id);
        if (!isset($this->cacheInstances[$key])) {
            $serialNumber = $this->serialNumberFactory->create();
            $this->serialNumberResource->load($serialNumber, $id);

            if (!$serialNumber->getId()) {
                throw new NoSuchEntityException(__('The Serial Number with the "%1" ID doesn\'t exist.', $id));
            }

            $this->cacheInstances[$key] = $serialNumber;
        }

        return $this->cacheInstances[$key];
    }

    /**
     * {@inheritDoc}
     */
    public function save(SerialNumberInterface $serialNumber): SerialNumberInterface
    {
        $this->serialNumberResource->save($serialNumber);
        return $serialNumber;
    }

    /**
     * {@inheritDoc}
     */
    public function getList(SearchCriteriaInterface $searchCriteria): SerialNumberSearchResultsInterface
    {
        $collection = $this->serialNumberCollectionFactory->create();
        $this->collectionProcessor->process($searchCriteria, $collection);

        $searchResult = $this->serialNumberSearchResultFactory->create();
        $searchResult->setItems($collection->getItems());
        $searchResult->setTotalCount($collection->getSize());
        $searchResult->setSearchCriteria($searchCriteria);
        return $searchResult;
    }

    /**
     * Get cache key.
     *
     * @param int $id
     * @return string
     */
    private function getKey(int $id): string
    {
        return 'SERIAL_NUMBER_' . $id;
    }
}

Spamworldpro Mini