Ejemplo n.º 1
0
 /**
  * Test Get and Set the Domain Object
  *
  * @return void
  *
  * @covers \Rcm\Entity\Site
  */
 public function testGetAndSetDomain()
 {
     $domain = new Domain();
     $domain->setDomainId('102');
     $this->site->setDomain($domain);
     $actual = $this->site->getDomain();
     $this->assertTrue($actual instanceof Domain);
     $this->assertEquals($domain, $actual);
 }
Ejemplo n.º 2
0
 /**
  * getPrimaryRedirectUrl
  * If the IP is not a domain and is not the primary, return redirect for primary
  *
  * @param Site $site
  *
  * @return null|string
  */
 public function getPrimaryRedirectUrl(Site $site)
 {
     $currentDomain = $site->getDomain()->getDomainName();
     $ipValidator = new Ip();
     $isIp = $ipValidator->isValid($currentDomain);
     if ($isIp) {
         return null;
     }
     $primaryDomain = $site->getDomain()->getPrimary();
     if (empty($primaryDomain)) {
         return null;
     }
     if ($primaryDomain->getDomainName() == $currentDomain) {
         return null;
     }
     return $primaryDomain->getDomainName();
 }
 /**
  * get Host
  *
  * @return null|string
  */
 public function getHost()
 {
     if (empty($this->site)) {
         return null;
     }
     $domain = $this->site->getDomain();
     if (empty($domain->getDomainName())) {
         return null;
     }
     return $domain->getDomainName();
 }
Ejemplo n.º 4
0
 /**
  * Check the domain is a known domain for the CMS.  If not the primary, it will
  * redirect the user to the primary domain.  Useful for multiple domain sites.
  *
  * @param MvcEvent $event Zend MVC Event
  *
  * @return null|Response
  */
 public function checkDomain(MvcEvent $event)
 {
     /** @var \Zend\Http\PhpEnvironment\Request $request */
     $request = $event->getRequest();
     $serverParam = $request->getServer();
     $currentDomain = $serverParam->get('HTTP_HOST');
     if (empty($currentDomain)) {
         // We are on CLI
         return null;
     }
     if (!$this->currentSite->getSiteId() || $this->currentSite->getStatus() != 'A') {
         if (empty($this->config['Rcm']['defaultDomain']) || $this->config['Rcm']['defaultDomain'] == $this->currentSite->getDomain()->getDomainName()) {
             $response = new Response();
             $response->setStatusCode(404);
             $event->stopPropagation(true);
             return $response;
         }
         $response = new Response();
         $response->setStatusCode(302);
         $response->getHeaders()->addHeaderLine('Location', '//' . $this->config['Rcm']['defaultDomain']);
         $event->stopPropagation(true);
         return $response;
     }
     $primaryCheck = $this->currentSite->getDomain()->getPrimary();
     /**
      * If the IP is not a domain and is not the primary, redirect to primary
      */
     if (!$this->ipValidator->isValid($currentDomain) && !empty($primaryCheck) && $primaryCheck->getDomainName() != $currentDomain) {
         $response = new Response();
         $response->setStatusCode(302);
         $response->getHeaders()->addHeaderLine('Location', '//' . $primaryCheck->getDomainName());
         $event->stopPropagation(true);
         return $response;
     }
     return null;
 }
Ejemplo n.º 5
0
 /**
  * Test Check Domain Redirects To Primary
  *
  * @return void
  *
  * @covers \Rcm\EventListener\RouteListener
  */
 public function testCheckDomainRedirectsToPrimary()
 {
     $serverParams = new Parameters(['HTTP_HOST' => 'www.reliv.com']);
     $primary = $this->currentSite->getDomain();
     $domain = new Domain();
     $domain->setDomainId(1);
     $domain->setDomainName('www.reliv.com');
     $domain->setPrimary($primary);
     $this->currentSite->setDomain($domain);
     $request = new Request();
     $request->setServer($serverParams);
     $event = new MvcEvent();
     $event->setRequest($request);
     $actual = $this->routeListener->checkDomain($event);
     $this->assertTrue($actual instanceof Response);
     $this->assertEquals(302, $actual->getStatusCode());
     $this->assertEquals('//' . $this->currentSite->getDomain()->getPrimary()->getDomainName(), $actual->getHeaders()->get('Location')->getFieldValue());
 }
Ejemplo n.º 6
0
 /**
  * getSiteDomain
  *
  * @param Site $site
  *
  * @return null|string
  */
 public function getSiteDomain(Site $site)
 {
     $domain = $site->getDomain();
     if (empty($domain)) {
         return $this->domainService->getDefaultDomainName();
     }
     $domainName = $domain->getDomainName();
     if (empty($domainName)) {
         return $this->domainService->getDefaultDomainName();
     }
     return $domainName;
 }
Ejemplo n.º 7
0
 /**
  * Get all Page Resources
  *
  * @param Page $page Rcm Page Entity
  * @param Site $site Rcm Site Entity
  *
  * @return mixed
  */
 protected function getPageResources(Page $page, Site $site)
 {
     $primaryDomainName = $site->getDomain()->getDomainName();
     $siteId = $site->getSiteId();
     $pageName = $page->getName();
     $pageType = $page->getPageType();
     $return['sites.' . $siteId . '.pages.' . $pageType . '.' . $pageName] = ['resourceId' => 'sites.' . $siteId . '.pages.' . $pageType . '.' . $pageName, 'parentResourceId' => 'sites.' . $siteId . '.pages', 'name' => $primaryDomainName . ' - pages - ' . $pageName, 'description' => "Resource for page '{$pageName}'" . " of type '{$pageType}' on site '{$primaryDomainName}'"];
     $return['sites.' . $siteId . '.pages.' . $pageType . '.' . $pageName] = array_merge($this->resources['pages'], $return['sites.' . $siteId . '.pages.' . $pageType . '.' . $pageName]);
     return $return;
 }
Ejemplo n.º 8
0
 /**
  * prepareNewSite
  *
  * @param Site $newSite
  *
  * @return Site
  * @throws \Exception
  */
 protected function prepareNewSite(Site $newSite)
 {
     $siteId = $newSite->getSiteId();
     if (!empty($siteId)) {
         throw new \Exception("Site ID must be empty to create new site, id {$siteId} given.");
     }
     if (empty($newSite->getDomain())) {
         throw new \Exception('Domain is required to create new site.');
     }
     return $this->prepareDefaultValues($newSite);
 }