/** * @see GenericArrayObject::preSetElement * * @since 1.21 * * @param int|string $index * @param Site $site * * @return boolean */ protected function preSetElement($index, $site) { if ($this->hasSite($site->getGlobalId())) { $this->removeSite($site->getGlobalId()); } $this->byGlobalId[$site->getGlobalId()] = $index; $this->byInternalId[$site->getInternalId()] = $index; return true; }
/** * @see GenericArrayObject::preSetElement * * @since 1.21 * * @param int|string $index * @param Site $site * * @return bool */ protected function preSetElement($index, $site) { if ($this->hasSite($site->getGlobalId())) { $this->removeSite($site->getGlobalId()); } $this->byGlobalId[$site->getGlobalId()] = $index; $this->byInternalId[$site->getInternalId()] = $index; $ids = $site->getNavigationIds(); foreach ($ids as $navId) { $this->byNavigationId[$navId] = $index; } return true; }
/** * Writes a <site> tag representing the given Site object. * * @param Site $site */ private function exportSite(Site $site) { if ($site->getType() !== Site::TYPE_UNKNOWN) { $siteAttr = ['type' => $site->getType()]; } else { $siteAttr = null; } fwrite($this->sink, "\t" . Xml::openElement('site', $siteAttr) . "\n"); fwrite($this->sink, "\t\t" . Xml::element('globalid', null, $site->getGlobalId()) . "\n"); if ($site->getGroup() !== Site::GROUP_NONE) { fwrite($this->sink, "\t\t" . Xml::element('group', null, $site->getGroup()) . "\n"); } if ($site->getSource() !== Site::SOURCE_LOCAL) { fwrite($this->sink, "\t\t" . Xml::element('source', null, $site->getSource()) . "\n"); } if ($site->shouldForward()) { fwrite($this->sink, "\t\t" . Xml::element('forward', null, '') . "\n"); } foreach ($site->getAllPaths() as $type => $path) { fwrite($this->sink, "\t\t" . Xml::element('path', ['type' => $type], $path) . "\n"); } foreach ($site->getLocalIds() as $type => $ids) { foreach ($ids as $id) { fwrite($this->sink, "\t\t" . Xml::element('localid', ['type' => $type], $id) . "\n"); } } // @todo: export <data> // @todo: export <config> fwrite($this->sink, "\t" . Xml::closeElement('site') . "\n"); }
/** * Get a new ORMRow from a Site object * * @since 1.22 * * @param Site $site * * @return ORMRow */ protected function getRowFromSite(Site $site) { $fields = array('global_key' => $site->getGlobalId(), 'type' => $site->getType(), 'group' => $site->getGroup(), 'source' => $site->getSource(), 'language' => $site->getLanguageCode() === null ? '' : $site->getLanguageCode(), 'protocol' => $site->getProtocol(), 'domain' => strrev($site->getDomain()) . '.', 'data' => $site->getExtraData(), 'forward' => $site->shouldForward(), 'config' => $site->getExtraConfig()); if ($site->getInternalId() !== null) { $fields['id'] = $site->getInternalId(); } return new ORMRow($this->sitesTable, $fields); }
/** * @dataProvider instanceProvider * @param Site $site * @covers Site::setGlobalId */ public function testSetGlobalId(Site $site) { $site->setGlobalId('foobar'); $this->assertEquals('foobar', $site->getGlobalId()); }
/** * Saves the provided site. * * @since 1.25 * * @param Site $site * * @return boolean Success indicator */ public function saveSite(Site $site) { $this->sites[$site->getGlobalId()] = $site; return true; }