vendor/pimcore/pimcore/lib/Analytics/AbstractTracker.php line 50

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * Pimcore
  5.  *
  6.  * This source file is available under two different licenses:
  7.  * - GNU General Public License version 3 (GPLv3)
  8.  * - Pimcore Enterprise License (PEL)
  9.  * Full copyright and license information is available in
  10.  * LICENSE.md which is distributed with this source code.
  11.  *
  12.  * @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  13.  * @license    http://www.pimcore.org/license     GPLv3 and PEL
  14.  */
  15. namespace Pimcore\Analytics;
  16. use Pimcore\Analytics\Code\CodeCollector;
  17. use Pimcore\Analytics\SiteId\SiteId;
  18. use Pimcore\Analytics\SiteId\SiteIdProvider;
  19. abstract class AbstractTracker implements TrackerInterface
  20. {
  21.     /**
  22.      * @var SiteIdProvider
  23.      */
  24.     private $siteIdProvider;
  25.     /**
  26.      * @var CodeCollector
  27.      */
  28.     private $codeCollector;
  29.     public function __construct(SiteIdProvider $siteIdProvider)
  30.     {
  31.         $this->siteIdProvider $siteIdProvider;
  32.     }
  33.     /**
  34.      * @inheritdoc
  35.      */
  36.     public function generateCode(SiteId $siteId null)
  37.     {
  38.         if (null === $siteId) {
  39.             $siteId $this->siteIdProvider->getForRequest();
  40.         }
  41.         return $this->buildCode($siteId);
  42.     }
  43.     /**
  44.      * Generates code for a specific site config
  45.      *
  46.      * @param SiteId $siteId
  47.      *
  48.      * @return string|null
  49.      */
  50.     abstract protected function buildCode(SiteId $siteId);
  51.     /**
  52.      * @inheritdoc
  53.      */
  54.     public function addCodePart(string $codestring $block nullbool $prepend falseSiteId $siteId null)
  55.     {
  56.         $action $prepend CodeCollector::ACTION_PREPEND CodeCollector::ACTION_APPEND;
  57.         $this->getCodeCollector()->addCodePart($code$block$action$siteId);
  58.     }
  59.     /**
  60.      * Lazy initialize the code collector
  61.      *
  62.      * @return CodeCollector
  63.      */
  64.     protected function getCodeCollector(): CodeCollector
  65.     {
  66.         if (null === $this->codeCollector) {
  67.             $this->codeCollector $this->buildCodeCollector();
  68.         }
  69.         return $this->codeCollector;
  70.     }
  71.     /**
  72.      * Builds the code collector which allows to add additional content to
  73.      * specific blocks.
  74.      *
  75.      * @return CodeCollector
  76.      */
  77.     abstract protected function buildCodeCollector(): CodeCollector;
  78. }