sentence1
stringlengths 52
3.87M
| sentence2
stringlengths 1
47.2k
| label
stringclasses 1
value |
---|---|---|
public function extract($file, $params = array(), $document = null, $mimetype = 'application/octet-stream')
{
// check if $params is an array (allow null for default empty array)
if (!is_null($params))
{
if (!is_array($params))
{
throw new Apache_Solr_InvalidArgumentException("\$params must be a valid array or null");
}
}
else
{
$params = array();
}
// if $file is an http request, defer to extractFromUrl instead
if (substr($file, 0, 7) == 'http://' || substr($file, 0, 8) == 'https://')
{
return $this->extractFromUrl($file, $params, $document, $mimetype);
}
// read the contents of the file
$contents = @file_get_contents($file);
if ($contents !== false)
{
// add the resource.name parameter if not specified
if (!isset($params['resource.name']))
{
$params['resource.name'] = basename($file);
}
// delegate the rest to extractFromString
return $this->extractFromString($contents, $params, $document, $mimetype);
}
else
{
throw new Apache_Solr_InvalidArgumentException("File '{$file}' is empty or could not be read");
}
} | Use Solr Cell to extract document contents. See {@link http://wiki.apache.org/solr/ExtractingRequestHandler} for information on how
to use Solr Cell and what parameters are available.
NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost."
as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value
pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also
pass in a document isntance with an "id" field" - the document's value(s) will take precedence).
@param string $file Path to file to extract data from
@param array $params optional array of key value pairs that will be sent with the post (see Solr Cell documentation)
@param Apache_Solr_Document $document optional document that will be used to generate post parameters (literal.* and boost.* params)
@param string $mimetype optional mimetype specification (for the file being extracted)
@return Apache_Solr_Response
@throws Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid. | entailment |
public function extractFromString($data, $params = array(), $document = null, $mimetype = 'application/octet-stream')
{
// check if $params is an array (allow null for default empty array)
if (!is_null($params))
{
if (!is_array($params))
{
throw new Apache_Solr_InvalidArgumentException("\$params must be a valid array or null");
}
}
else
{
$params = array();
}
// make sure we receive our response in JSON and have proper name list treatment
$params['wt'] = self::SOLR_WRITER;
$params['json.nl'] = $this->_namedListTreatment;
// check if $document is an Apache_Solr_Document instance
if (!is_null($document) && $document instanceof Apache_Solr_Document)
{
// iterate document, adding literal.* and boost.* fields to $params as appropriate
foreach ($document as $field => $fieldValue)
{
// check if we need to add a boost.* parameters
$fieldBoost = $document->getFieldBoost($field);
if ($fieldBoost !== false)
{
$params["boost.{$field}"] = $fieldBoost;
}
// add the literal.* parameter
$params["literal.{$field}"] = $fieldValue;
}
}
// params will be sent to SOLR in the QUERY STRING
$queryString = $this->_generateQueryString($params);
// the file contents will be sent to SOLR as the POST BODY - we use application/octect-stream as default mimetype
return $this->_sendRawPost($this->_extractUrl . $this->_queryDelimiter . $queryString, $data, false, $mimetype);
} | Use Solr Cell to extract document contents. See {@link http://wiki.apache.org/solr/ExtractingRequestHandler} for information on how
to use Solr Cell and what parameters are available.
NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost."
as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value
pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also
pass in a document isntance with an "id" field" - the document's value(s) will take precedence).
@param string $data Data that will be passed to Solr Cell
@param array $params optional array of key value pairs that will be sent with the post (see Solr Cell documentation)
@param Apache_Solr_Document $document optional document that will be used to generate post parameters (literal.* and boost.* params)
@param string $mimetype optional mimetype specification (for the file being extracted)
@return Apache_Solr_Response
@throws Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid.
@todo Should be using multipart/form-data to post parameter values, but I could not get my implementation to work. Needs revisisted. | entailment |
public function extractFromUrl($url, $params = array(), $document = null, $mimetype = 'application/octet-stream')
{
// check if $params is an array (allow null for default empty array)
if (!is_null($params))
{
if (!is_array($params))
{
throw new Apache_Solr_InvalidArgumentException("\$params must be a valid array or null");
}
}
else
{
$params = array();
}
$httpTransport = $this->getHttpTransport();
// read the contents of the URL using our configured Http Transport and default timeout
$httpResponse = $httpTransport->performGetRequest($url);
// check that its a 200 response
if ($httpResponse->getStatusCode() == 200)
{
// add the resource.name parameter if not specified
if (!isset($params['resource.name']))
{
$params['resource.name'] = $url;
}
// delegate the rest to extractFromString
return $this->extractFromString($httpResponse->getBody(), $params, $document, $mimetype);
}
else
{
throw new Apache_Solr_InvalidArgumentException("URL '{$url}' returned non 200 response code");
}
} | Use Solr Cell to extract document contents. See {@link http://wiki.apache.org/solr/ExtractingRequestHandler} for information on how
to use Solr Cell and what parameters are available.
NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost."
as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value
pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also
pass in a document isntance with an "id" field" - the document's value(s) will take precedence).
@param string $url URL
@param array $params optional array of key value pairs that will be sent with the post (see Solr Cell documentation)
@param Apache_Solr_Document $document optional document that will be used to generate post parameters (literal.* and boost.* params)
@param string $mimetype optional mimetype specification (for the file being extracted)
@return Apache_Solr_Response
@throws Apache_Solr_InvalidArgumentException if $url, $params, or $document are invalid. | entailment |
public function optimize($waitFlush = true, $waitSearcher = true, $timeout = 3600)
{
$rawPost = $this->getCompatibilityLayer()->createOptimizeXml(
$waitFlush,
$waitSearcher,
$timeout
);
return $this->_sendRawPost($this->_updateUrl, $rawPost, $timeout);
} | Send an optimize command. Will be synchronous unless both wait parameters are set
to false.
@param boolean $waitFlush
@param boolean $waitSearcher
@param float $timeout Maximum expected duration of the commit operation on the server (otherwise, will throw a communication exception)
@return Apache_Solr_Response
@throws Apache_Solr_HttpTransportException If an error occurs during the service call | entailment |
public function search($query, $offset = 0, $limit = 10, $params = array(), $method = self::METHOD_GET)
{
// ensure params is an array
if (!is_null($params))
{
if (!is_array($params))
{
// params was specified but was not an array - invalid
throw new Apache_Solr_InvalidArgumentException("\$params must be a valid array or null");
}
}
else
{
$params = array();
}
// construct our full parameters
// common parameters in this interface
$params['wt'] = self::SOLR_WRITER;
$params['json.nl'] = $this->_namedListTreatment;
$params['q'] = $query;
$params['start'] = $offset;
$params['rows'] = $limit;
$queryString = $this->_generateQueryString($params);
if ($method == self::METHOD_GET)
{
return $this->_sendRawGet($this->_searchUrl . $this->_queryDelimiter . $queryString);
}
else if ($method == self::METHOD_POST)
{
return $this->_sendRawPost($this->_searchUrl, $queryString, FALSE, 'application/x-www-form-urlencoded; charset=UTF-8');
}
else
{
throw new Apache_Solr_InvalidArgumentException("Unsupported method '$method', please use the Apache_Solr_Service::METHOD_* constants");
}
} | Simple Search interface
@param string $query The raw query string
@param int $offset The starting offset for result documents
@param int $limit The maximum number of result documents to return
@param array $params key / value pairs for other query parameters (see Solr documentation), use arrays for parameter keys used more than once (e.g. facet.field)
@param string $method The HTTP method (Apache_Solr_Service::METHOD_GET or Apache_Solr_Service::METHOD::POST)
@return Apache_Solr_Response
@throws Apache_Solr_HttpTransportException If an error occurs during the service call
@throws Apache_Solr_InvalidArgumentException If an invalid HTTP method is used | entailment |
private static function getHttpTransportAdapter($serverConfig)
{
switch ($serverConfig->getHttpTransportMethod()) {
case HttpTransportMethod::HTTP_TRANSPORT_METHOD_CURL:
$adapter = new Apache_Solr_HttpTransport_Curl();
break;
default:
$adapter = new Apache_Solr_HttpTransport_FileGetContents();
}
if ($serverConfig->isUseHttpBasicAuth()) {
$adapter->setAuthenticationCredentials(
$serverConfig->getHttpBasicAuthUsername(),
$serverConfig->getHttpBasicAuthPassword()
);
}
return $adapter;
} | Create HttpTransportAdapter based on configuration
@param $serverConfig
@return Apache_Solr_HttpTransport_Abstract | entailment |
public function parseDateTime($rawValue) {
if (null === $rawValue) return null;
try {
return DateUtils::createDateTimeFromFormat(OracleDateTimeColumn::generateFormatBuildRawValue(
OracleDateTimeColumn::FORMAT_BUILD_TYPE_PARSE, true, true), $rawValue);
} catch (\n2n\util\DateParseException $e) {
throw new \InvalidArgumentException($e->getMessage(), 0, $e);
}
} | /* (non-PHPdoc)
@see n2n\persistence\meta.OrmDialectConfig::parseDateTime() | entailment |
public function buildDateTimeRawValue(\DateTime $dateTime = null) {
if (null === $dateTime) return null;
return DateUtils::formatDateTime($dateTime, OracleDateTimeColumn::generateFormatBuildRawValue(
OracleDateTimeColumn::FORMAT_BUILD_TYPE_RAW_VALUE, true, true));
} | /* (non-PHPdoc)
@see n2n\persistence\meta.OrmDialectConfig::buildRawValue() | entailment |
public function absStartLevel(int $absStartLevelNo = null) {
if ($this->relStartLevelNo !== null) {
throw new IllegalStateException('Relative start level already defined.');
}
$this->absStartlevelNo = $absStartLevelNo;
return $this;
} | Specifies the first navigation level absolute to the root page
(e.g. <code>Nav::root()->absStartLevel(2)</code>).
@param int $absStartLevelNo
@return \page\ui\nav\NavComposer | entailment |
public function relStartLevel(int $relStartLevel = null) {
if ($this->absStartlevelNo !== null) {
throw new IllegalStateException('Absolute start level already defined.');
}
$this->relStartLevelNo = $relStartLevel;
return $this;
} | Specifies the first navigation level relative to the base page
(e.g. <code>Nav::current()->relStartLevel(-1)</code>).
@param int $relStartLevelNo
@return \page\ui\nav\NavComposer | entailment |
public function builder($navItemBuilder) {
ArgUtils::valType($navItemBuilder, array(NavItemBuilder::class, 'string'));
$this->navItemBuilder = $navItemBuilder;
return $this;
} | Specifies the {@link NavItemBuilder} for this navigation. If you want to build a custom navigation, create your
own NavItemBuilder that inherits from {@see NavItemBuilderAdapter}
@param mixed $navItemBuilder object of {@link NavItemBuilder} or its lookup id as string.
@return \page\ui\nav\NavComposer | entailment |
public function build(HtmlView $view, array $attrs = null, array $ulAttrs = null, array $liAttrs = null, array $aAttrs = null) {
$pageState = $view->lookup(PageState::class);
CastUtils::assertTrue($pageState instanceof PageState);
$navItemBuilder = null;
if ($this->navItemBuilder === null) {
$navItemBuilder = new CommonNavItemBuilder();
} else if ($this->navItemBuilder instanceof NavItemBuilder) {
$navItemBuilder = $this->navItemBuilder;
} else {
$navItemBuilder = $view->lookup($this->navItemBuilder);
if (!($navItemBuilder instanceof NavItemBuilder)) {
throw new UiException('Invalid NavItemBuilder: ' . $navItemBuilder);
}
}
$navFactory = new NavFactory($navItemBuilder, $view->getN2nLocale(), $this->numLevels, $this->numOpenLevels);
if ($pageState->hasCurrent()) {
$navFactory->setCurrentNavBranch($pageState->getCurrentNavBranch());
}
$navFactory->setNumLevels($this->numLevels);
$navFactory->setNumOpenLevels($this->numOpenLevels);
$navFactory->setRootUlAttrs((array) $attrs);
$navFactory->setUlAttrs((array) $ulAttrs);
$navFactory->setLiAttrs((array) $liAttrs);
$navFactory->setAAttrs((array) $aAttrs);
$n2nLocale = $view->getN2nLocale();
$navBranch = $this->navBranchCriteria->determine($pageState, $n2nLocale, $view->getN2nContext());
$startLevel = 1;
if ($this->absStartlevelNo !== null) {
$startLevel = $this->absStartlevelNo - $navBranch->getLevel();
} else if ($this->relStartLevelNo !== null) {
$startLevel = $this->relStartLevelNo;
}
return $navFactory->create($view, $this->dertermineBases($navBranch, $startLevel));
} | Usally invoked by {@link \page\ui\PageHtmlBuilder::navigation()} to build an UiComponent of the
described navigation.
@param HtmlView $view
@param array $attrs
@param array $ulAttrs
@param array $liAttrs
@throws UiException
@return UiComponent | entailment |
public function createBackuper(array $metaEnities = null): Backuper {
return new SqliteBackuper($this->dbh, $this->createDatabase(), $metaEnities);
} | {@inheritDoc}
@see \n2n\persistence\meta\Database::createBackuper()
@return Backuper | entailment |
protected function buildDatabase(): DatabaseAdapter {
$database = new SqliteDatabase($this->determineDbCharset(),
$this->getPersistedMetaEntities(), $this->determineDbAttrs());
foreach ($database->getMetaEntities() as $metaEntity) {
if (!$metaEntity instanceof Table) continue;
$this->metaEntityBuilder->applyIndexesForTable(
SqliteDatabase::FIXED_DATABASE_NAME, $metaEntity);
}
return $database;
} | {@inheritDoc}
@see \n2n\persistence\meta\structure\common\MetaManagerAdapter::buildDatabase()
@return DatabaseAdapter | entailment |
public function applyIdentifierGeneratorToColumn(Pdo $dbh, Column $column, string $sequenceName) {
$dbh = N2N::getPdoPool()->getPdo();
$statement = $dbh->prepare('SELECT COUNT(SEQUENCE_NAME) as NUM_SEQUENCES FROM USER_SEQUENCES WHERE SEQUENCE_NAME = :SEQUENCE_NAME');
$statement->execute(array(':SEQUENCE_NAME' => $sequenceName));
$result = $statement->fetch(Pdo::FETCH_ASSOC);
if (intval($result['NUM_SEQUENCES']) == 0) {
$dbh->exec('CREATE SEQUENCE ' . $dbh->quoteField($sequenceName));
}
} | {@inheritDoc}
@see \n2n\persistence\meta\Dialect::applyIdentifierGeneratorToColumn() | entailment |
public function createBackuper(array $metaEnities = null): Backuper {
return new OracleBackuper($this->dbh, $this->createDatabase(), $metaEnities);
} | {@inheritDoc}
@see \n2n\persistence\meta\Database::createBackuper()
@return Backuper | entailment |
public function createLeafContent(N2nContext $n2nContext, Path $cmdPath, Path $cmdContextPath): LeafContent {
$pageContent = $this->lookupPageContent($n2nContext);
$pageController = $pageContent->getPageController();
$analyzer = new PageControllerAnalyzer(new \ReflectionClass($pageController));
$leafContent = new PageLeafContent($this, $cmdPath, $cmdContextPath, $pageController);
$pageMethod = $analyzer->analyzeMethod($pageController->getMethodName());
if ($pageMethod === null) {
throw new IllegalPageStateException('Page method '
. TypeUtils::prettyMethName(get_class($pageController), $pageController->getMethodName())
. ' does not exist. Used in: ' . get_class($pageController) . '#' . $pageController->getId());
}
$leafContent->setPageMethod($pageMethod);
if (null !== ($pageContentT = $pageContent->t($this->getN2nLocale()))) {
$leafContent->setSeTitle($pageContentT->getSeTitle());
$leafContent->setSeDescription($pageContentT->getSeDescription());
$leafContent->setSeKeywords($pageContentT->getSeKeywords());
}
if (null !== ($pageControllerT = $pageController->pageControllerT($this->getN2nLocale()))) {
$leafContent->setContentItems($pageControllerT->getContentItems()->getArrayCopy());
}
return $leafContent;
} | {@inheritDoc}
@see \page\model\nav\Leaf::createLeafContent($n2nContext, $cmdPath, $cmdContextPath) | entailment |
public function getContentItemsByPanelName(string $panelName): array {
if (!$this->containsContentItemPanelName($panelName)) {
$pageController = $this->getControllerContext()->getController();
throw new UnknownContentItemPanelException('Undefined ContentItem panel \'' . $panelName . '\' for '
. TypeUtils::prettyMethName(get_class($pageController),
$pageController->getMethodName()));
}
$contentItems = array();
foreach ($this->contentItems as $contentItem) {
if ($contentItem->getPanel() === $panelName) {
$contentItems[] = $contentItem;
}
}
return $contentItems;
} | {@inheritDoc}
@see \page\model\nav\impl\CommonLeafContent::getContentItemsByPanelName() | entailment |
public function createMetaEntityFactory(): MetaEntityFactory {
if (null === $this->metaEntityFactory) {
$this->metaEntityFactory = new MysqlMetaEntityFactory($this);
}
return $this->metaEntityFactory;
} | {@inheritDoc}
@see \n2n\persistence\meta\Database::createMetaEntityFactory()
@return MetaEntityFactory | entailment |
public function toUrl(N2nContext $n2nContext, ControllerContext $controllerContext = null,
string &$suggestedLabel = null): Url {
if ($this->type == self::TYPE_EXTERNAL) {
$suggestedLabel = $this->label;
return Url::create($this->url);
}
$url = MurlPage::obj($this->linkedPage)->toUrl($n2nContext, $controllerContext, $suggestedLabel);
if ($this->label !== null) {
$suggestedLabel = $this->label;
}
return $url;
} | {@inheritDoc}
@see \n2n\web\http\nav\UrlComposer::toUrl() | entailment |
public function toUrl(N2nContext $n2nContext, ControllerContext $controllerContext = null,
string &$suggestedLabel = null): Url {
$pageState = $n2nContext->lookup(PageState::class);
CastUtils::assertTrue($pageState instanceof PageState);
$n2nLocale = $this->n2nLocale;
if ($n2nLocale === null){
$n2nLocale = $n2nContext->getN2nLocale();
}
$navBranch = null;
try {
$navBranch = $this->navBranchCriteria->determine($pageState, $n2nLocale, $n2nContext);
} catch (UnknownNavBranchException $e) {
throw new UnavailableUrlException(false, null, null, $e);
}
$navUrlBuilder = new NavUrlBuilder($n2nContext->getHttpContext());
$navUrlBuilder->setFallbackAllowed($this->fallbackAllowed);
$navUrlBuilder->setAbsolute($this->absolute);
$navUrlBuilder->setAccessiblesOnly($this->accessiblesOnly);
$navUrlBuilder->setPathExt((new Path(array()))->extEnc(...$this->pathExts));
$url = null;
$curNavBranch = null;
try {
$url = $navUrlBuilder->build($navBranch, $n2nLocale, true, $curNavBranch);
$suggestedLabel = $curNavBranch->getLeafByN2nLocale($n2nLocale)->getName();
} catch (BranchUrlBuildException $e) {
throw new UnavailableUrlException(false, 'NavBranch not available for locale: ' . $n2nLocale, 0, $e);
}
return $url->queryExt($this->queryExt)->chFragment($this->fragment);
} | {@inheritDoc}
@see \n2n\web\http\nav\UrlComposer::toUrl($n2nContext, $controllerContext) | entailment |
public function getLinkOptions(N2nLocale $n2nLocale): array {
$options = array();
$this->buildLinkOptions($this->pageState->getNavTree()->getRootNavBranches(), $options);
return $options;
} | {@inheritDoc}
@see \rocket\impl\ei\component\prop\string\cke\model\CkeLinkProvider::getLinkUrls() | entailment |
public function buildUrl(string $key, View $view, N2nLocale $n2nLocale) {
return $view->buildUrlStr(MurlPage::id($key)->locale($n2nLocale));
} | {@inheritDoc}
@see \rocket\impl\ei\component\prop\string\cke\model\CkeLinkProviderAdapter::buildUrl() | entailment |
public function createBinaryColumn(string $name, int $size): BinaryColumn {
$binaryColumn = new CommonBinaryColumn($name, $size);
$this->table->addColumn($binaryColumn);
return $binaryColumn;
} | {@inheritDoc}
@see \n2n\persistence\meta\structure\ColumnFactory::createBinaryColumn()
@return BinaryColumn | entailment |
public function createIntegerColumn(string $name, int $size, bool $signed = true): IntegerColumn {
$integerColumn = new PgsqlIntegerColumn($name, $size, $signed);
$this->table->addColumn($integerColumn);
return $integerColumn;
} | {@inheritDoc}
@see \n2n\persistence\meta\structure\ColumnFactory::createIntegerColumn()
@return IntegerColumn | entailment |
public function createFixedPointColumn(string $name, int $numIntegerDigits, int $numDecimalDigits): FixedPointColumn {
$fixedPointColumn = new CommonFixedPointColumn($name, $numIntegerDigits, $numDecimalDigits);
$this->table->addColumn($fixedPointColumn);
return $fixedPointColumn;
} | {@inheritDoc}
@see \n2n\persistence\meta\structure\ColumnFactory::createFixedPointColumn()
@return FixedPointColumn | entailment |
public function createFloatingPointColumn(string $name, int $size): FloatingPointColumn {
$floatingPointColumn = new CommonFloatingPointColumn($name, $size);
$this->table->addColumn($floatingPointColumn);
return $floatingPointColumn;
} | {@inheritDoc}
@see \n2n\persistence\meta\structure\ColumnFactory::createFloatingPointColumn()
@return FloatingPointColumn | entailment |
public function createDateTimeColumn(string $name, bool $dateAvailable = true, bool $timeAvailable = true): DateTimeColumn {
$dateTimeColumn = new PgsqlDateTimeColumn($name, $dateAvailable, $timeAvailable);
$this->table->addColumn($dateTimeColumn);
return $dateTimeColumn;
} | {@inheritDoc}
@see \n2n\persistence\meta\structure\ColumnFactory::createDateTimeColumn()
@return DateTimeColumn | entailment |
public function createEnumColumn(string $name, array $values): EnumColumn {
$enumColumn = new CommonEnumColumn($name, $values);
$this->table->addColumn($enumColumn);
return $enumColumn;
} | {@inheritDoc}
@see \n2n\persistence\meta\structure\ColumnFactory::createEnumColumn()
@return EnumColumn | entailment |
public function createColumnFactory(): ColumnFactory {
if (!($this->columnFactory)) {
$this->columnFactory = new SqliteColumnFactory($this);
}
return $this->columnFactory;
} | {@inheritDoc}
@see \n2n\persistence\meta\structure\Table::createColumnFactory()
@return ColumnFactory | entailment |
public function createTable(string $name): Table {
$metaEntity = new MssqlTable($name);
$this->database->addMetaEntity($metaEntity);
return $metaEntity;
} | {@inheritDoc}
@see \n2n\persistence\meta\structure\MetaEntityFactory::createTable()
@return Table | entailment |
public function createView($name, $query): View {
$metaEntity = new CommonView($name, $query);
$this->database->addMetaEntity($metaEntity);
return $metaEntity;
} | {@inheritDoc}
@see \n2n\persistence\meta\structure\MetaEntityFactory::createView()
@return View | entailment |
public function parseDateTime($rawValue) {
if (null === $rawValue) return null;
try {
return DateUtils::createDateTimeFromFormat(MssqlDateTimeColumn::generateFormatBuildRawValue(
MssqlDateTimeColumn::FORMAT_BUILD_TYPE_PARSE, true, true, self::COLUMN_TYPE_PRECISION, false),
$rawValue);
} catch (\n2n\util\DateParseException $e) {
throw new \InvalidArgumentException($e->getMessage(), 0, $e);
}
} | /* (non-PHPdoc)
@see \n2n\persistence\meta\OrmDialectConfig::parseDateTime() | entailment |
public function buildDateTimeRawValue(\DateTime $dateTime = null) {
if (null === $dateTime) return null;
return DateUtils::formatDateTime($dateTime, MssqlDateTimeColumn::generateFormatBuildRawValue(
MssqlDateTimeColumn::FORMAT_BUILD_TYPE_RAW_VALUE, true, true, self::COLUMN_TYPE_PRECISION, false));
} | /* (non-PHPdoc)
@see \n2n\persistence\meta\OrmDialectConfig::buildDateTimeRawValue() | entailment |
public function createMetaEntityFactory(): MetaEntityFactory {
if (null === $this->metaEntityFactory) {
$this->metaEntityFactory = new SqliteMetaEntityFactory($this);
}
return $this->metaEntityFactory;
} | {@inheritDoc}
@see \n2n\persistence\meta\Database::createMetaEntityFactory()
@return MetaEntityFactory | entailment |
public function createIntegerColumn(string $name, int $size, bool $signed = true): IntegerColumn {
$column = new SqliteIntegerColumn($name);
$this->table->addColumn($column);
return $column;
} | {@inheritDoc}
@see \n2n\persistence\meta\structure\ColumnFactory::createIntegerColumn()
@return IntegerColumn | entailment |
public function createTextColumn(string $name, int $size, string $charset = null): TextColumn {
throw new UnavailableTypeException('Sqlite does not support Text columns');
} | {@inheritDoc}
@see \n2n\persistence\meta\structure\ColumnFactory::createTextColumn()
@return TextColumn | entailment |
public function createFloatingPointColumn(string $name, int $size): FloatingPointColumn {
$column = new SqliteFloatingPointColumn($name);
$this->table->addColumn($column);
return $column;
} | {@inheritDoc}
@see \n2n\persistence\meta\structure\ColumnFactory::createFloatingPointColumn()
@return FloatingPointColumn | entailment |
public function getTitle() {
if ($this->pageState->hasCurrent()) {
return $this->pageState->getCurrentLeaf()->getTitle();
}
return $this->view->lookup(GeneralConfig::class)->getPageName();
} | Returns the title of the current page or the page name specified in app.ini if there is no
current page.
@return string | entailment |
public function applyMeta(string $seTitle = null, string $titleSeparator = self::DEFAULT_TITLE_SEPARATOR) {
$this->applySeMeta($seTitle, $titleSeparator);
$this->applyN2nLocaleMeta();
} | Combines {@link self::applySeMeta()} and {@link self::applyN2nLocaleMeta()}
@param string $seTitle See {@link self::applySeMeta()}
@param string $titleSeparator See {@link self::applySeMeta()} | entailment |
public function applySeMeta(string $seTitle = null, string $titleSeparator = self::DEFAULT_TITLE_SEPARATOR) {
if (!$this->pageState->hasCurrent()) return;
$leafContent = $this->pageState->getCurrentLeafContent();
$leaf = $leafContent->getLeaf();
$htmlMeta = $this->view->getHtmlBuilder()->meta();
if ($seTitle === null) {
$seTitle = $leafContent->getSeTitle();
}
if ($seTitle === null) {
$seTitle = $leaf->getName() . $titleSeparator
. $this->view->lookup(GeneralConfig::class)->getPageName();
}
$htmlMeta->setTitle($seTitle);
if (null !== ($seDescription = $leafContent->getSeDescription())) {
$htmlMeta->addMeta(array('name' => 'description', 'content' => $seDescription), 'name');
}
if (null !== ($seKeywords = $leafContent->getSeKeywords())) {
$htmlMeta->addMeta(array('name' => 'keywords', 'content' => $seKeywords), 'name');
}
if (!$leaf->isIndexable()) {
$htmlMeta->addMeta(array('name' => 'robots', 'content' => 'noindex, nofollow'), 'name');
}
} | <p>Applies meta information specified for the current page to the html header (e. g. <code><title></code>
or <code><meta name="description" content=".." /></code>) </p>
<p>If there is no current page nothing happens.</p>
@param string $seTitle If you want to overwrite the title for the <code><title></code> element.
@param string $titleSeparator The separator used to join the page title and the page name specified
in app.ini together for <code><title></code> element. | entailment |
public function applyN2nLocaleMeta() {
if (!$this->pageState->hasCurrent()) return;
$navBranch = $this->pageState->getCurrentNavBranch();
$leafs = $navBranch->getLeafs();
if (count($leafs) <= 1) return;
$htmlMeta = $this->view->getHtmlBuilder()->meta();
foreach ($leafs as $leaf) {
$n2nLocale = $leaf->getN2nLocale();
if (null !== ($href = $this->view->buildUrl(MurlPage::obj($leaf)->absolute(), false))) {
$htmlMeta->addLink(array('rel' => 'alternate',
'hreflang' => $this->view->getHttpContext()->n2nLocaleToHttpId($n2nLocale),
'href' => $href));
}
}
} | Applies a <code><link rel="alternate" hreflang="de" href=".." /></code>
element to the html header for every translation available for current page. | entailment |
public function getN2nLocaleSwitchUrls() {
if (!$this->pageState->hasCurrent()) return array();
$pageMurl = MurlPage::obj($this->pageState->getCurrentNavBranch())->fallback();
$urls = array();
foreach ($this->view->getHttpContext()->getAvailableN2nLocales() as $n2nLocale) {
if (null !== ($url = $this->view->buildUrl($pageMurl->locale($n2nLocale), false))) {
$urls[$n2nLocale->getId()] = $url;
}
}
return $urls;
} | <p>Returns the Urls to every translation of the current page. If it is no translation available
for a locale, a translation of its ancestors will be used. If they don't have a translation for this locale,
the locale will be skiped.</p>
<p>If there is no current page, an empty array will be returned.</p>
<p>You can use this method to build a customized locale switch.
<pre>
<ul>
<?php foreach ($pageHtml->meta()->getN2nLocaleSwitchUrls() as $n2nLocaleId => $url): ?>
<?php $n2nLocale = N2nLocale::create($n2nLocaleId) ?>
<li<?php $view->out($n2nLocale->equals($view->getN2nLocale()) ? ' class="active"' : '') ?>>
<?php $html->link($url, $n2nLocale->getName($view->getN2nLocale())) ?>
</li>
<?php endforeach ?>
</ul>
</pre>
</p>
@return \n2n\util\uri\Url[] The array key is the associated locale id. | entailment |
public function getBreadcrumbNavBranches() {
if (!$this->pageState->hasCurrent()) return array();
$navBranches = array();
$navBranch = $this->pageState->getCurrentNavBranch();
do {
$navBranches[] = $navBranch;
} while (null !== ($navBranch = $navBranch->getParent()));
return $navBranches;
} | <p>Returns the {@link NavBranch}es of the current page and all its ancestors. You can use this method to build
a customized breadcrumb navigation.
<pre>
<ul>
<?php foreach ($pageHtml->meta()->getBreadcrumbNavBranches() as $navBranch): ?>
<li><?php $html->link(MurlPage::obj($navBranch)) ?>
<?php endforeach ?>
</ul>
</pre>
</p>
@return NavBranch[] | entailment |
public function parseDateTime($rawValue) {
if (null === $rawValue) return null;
try {
return DateUtils::createDateTimeFromFormat(SqliteDateTimeColumn::FORMAT_DATE_TIME, $rawValue);
} catch (\n2n\util\DateParseException $e) {
throw new \InvalidArgumentException($e->getMessage(), 0, $e);
}
} | /* (non-PHPdoc)
@see n2n\persistence\meta.OrmDialectConfig::parseDateTime() | entailment |
public function buildDateTimeRawValue(\DateTime $dateTime = null) {
if (null === $dateTime) return null;
return DateUtils::formatDateTime($dateTime, SqliteDateTimeColumn::FORMAT_DATE_TIME);
} | /* (non-PHPdoc)
@see n2n\persistence\meta.OrmDialectConfig::buildDateTimeRawValue() | entailment |
public function createLeafContent(N2nContext $n2nContext, Path $cmdPath, Path $cmdContextPath): LeafContent {
return new CommonLeafContent($this, $cmdPath, $cmdContextPath, new EmptyController());
} | {@inheritDoc}
@see \page\model\nav\Leaf::createLeafContent($n2nContext, $cmdPath, $cmdContextPath) | entailment |
public function createMetaEntityFactory(): MetaEntityFactory {
if (!isset($this->metaEntityFactory)) {
$this->metaEntityFactory = new PgsqlMetaEntityFactory($this);
}
return $this->metaEntityFactory;
} | {@inheritDoc}
@see \n2n\persistence\meta\Database::createMetaEntityFactory()
@return MetaEntityFactory | entailment |
public function copy(string $newTableName = null): Table {
if (null === $newTableName) {
$newTableName = $this->getName();
}
$newTable = new MysqlTable($newTableName);
$newTable->applyColumnsFrom($this);
$newTable->applyIndexesFrom($this);
return $newTable;
} | {@inheritDoc}
@see \n2n\persistence\meta\structure\Table::copy()
@return Table | entailment |
public function createColumnFactory(): ColumnFactory {
if (!($this->columnFactory)) {
$this->columnFactory = new MysqlColumnFactory($this);
}
return $this->columnFactory;
} | {@inheritDoc}
@see \n2n\persistence\meta\structure\Table::createColumnFactory()
@return ColumnFactory | entailment |
public function escapeLikePattern(string $pattern): string {
$esc = $this->getLikeEscapeCharacter();
return str_replace(array($esc, QueryComparator::LIKE_WILDCARD_MANY_CHARS,
QueryComparator::LIKE_WILDCARD_ONE_CHAR),
array($esc . $esc, $esc . QueryComparator::LIKE_WILDCARD_MANY_CHARS, $esc .
QueryComparator::LIKE_WILDCARD_ONE_CHAR), $pattern);
} | Quotes the like wildcard chars
@param string $pattern | entailment |
public function createStringColumn(string $name, int $length, string $charset = null): StringColumn {
$column = new CommonStringColumn($name, $length, $charset);
$this->table->addColumn($column);
return $column;
} | {@inheritDoc}
@see \n2n\persistence\meta\structure\ColumnFactory::createStringColumn()
@return StringColumn | entailment |
public function createTextColumn(string $name, int $size, string $charset = null): TextColumn {
$column = new CommonTextColumn($name, $size, $charset);
$this->table->addColumn($column);
return $column;
} | {@inheritDoc}
@see \n2n\persistence\meta\structure\ColumnFactory::createTextColumn()
@return TextColumn | entailment |
public function createBinaryColumn(string $name, int $size): BinaryColumn {
$column = new CommonBinaryColumn($name, $size);
$this->table->addColumn($column);
return $column;
} | {@inheritDoc}
@see \n2n\persistence\meta\structure\ColumnFactory::createBinaryColumn()
@return BinaryColumn | entailment |
public function createDateTimeColumn(string $name, bool $dateAvailable = true, bool $timeAvailable = true): DateTimeColumn {
$column = new MssqlDateTimeColumn($name, $dateAvailable, $timeAvailable);
$this->table->addColumn($column);
return $column;
} | {@inheritDoc}
@see \n2n\persistence\meta\structure\ColumnFactory::createDateTimeColumn()
@return DateTimeColumn | entailment |
public function createMetaEntityFactory(): MetaEntityFactory {
if (!$this->metaEntityFactory) {
$this->metaEntityFactory = new MssqlMetaEntityFactory($this);
}
return $this->metaEntityFactory;
} | {@inheritDoc}
@see \n2n\persistence\meta\Database::createMetaEntityFactory()
@return MetaEntityFactory | entailment |
public function createLeafContent(N2nContext $n2nContext, Path $cmdPath, Path $cmdContextPath): LeafContent {
return new CommonLeafContent($this, $cmdPath, $cmdContextPath,
new ExternalController($this->httpLocation, $n2nContext));
} | {@inheritDoc}
@see \page\model\nav\Leaf::createLeafContent($n2nContext, $cmdPath, $cmdContextPath) | entailment |
public function execute(ControllerContext $controllerContext): bool {
if (!$controllerContext->getCmdPath()->isEmpty()) {
throw new PageNotFoundException();
}
$this->n2nContext->getHttpContext()->getResponse()->send(
new Redirect($this->httpLocation, Response::STATUS_301_MOVED_PERMANENTLY));
return true;
} | {@inheritDoc}
@see \n2n\web\http\controller\Controller::execute($controllerContext) | entailment |
public function buildCustomConfig() {
$attributes = $this->readCustomAttributes();
$pageConfig = new PageConfig();
$pageConfig->setN2nLocaleUrlsActive($attributes->optBool(self::ATTR_LOCALES_ACTIVE_KEY,
self::ATTR_LOCALES_ACTIVE_DEFAULT));
$pageConfig->setAutoN2nLocaleRedirectAllowed($attributes->optBool(self::ATTR_AUTO_LOCALE_REDIRECT_ACTIVE_KEY,
self::ATTR_AUTO_LOCALE_REDIRECT_ACTIVE_DEFAULT));
$pageConfig->setSslDefault($attributes->optBool(self::ATTR_SSL_SELECTABLE_KEY,
self::ATTR_SSL_SELECTABLE_DEFAULT));
$pageConfig->setSslDefault($attributes->optBool(self::ATTR_SSL_DEFAULT_KEY,
self::ATTR_SSL_DEFAULT_DEFAULT));
$hooks = array();
foreach ($attributes->getScalarArray(self::ATTR_HOOK_KEYS_KEY, false) as $key => $label) {
if (is_numeric($key)) {
$hooks[$label] = $label;
} else {
$hooks[$key] = $label;
}
}
$pageConfig->setHooks($hooks);
$pageConfig->setPageListenerLookupIds($attributes->getScalarArray(self::ATTR_PAGE_LISTENER_LOOKUP_IDS_KEY,
false));
$pageControllerConfigs = array();
foreach ($attributes->getArray(self::ATTR_PAGE_CONTROLLERS_KEY, false, array(),
TypeConstraint::createArrayLike('array')) as $pageControllerEiSpecId => $pageControllerAttrs) {
$ciPanelConfigs = array();
$pageControllerAttributes = new Attributes($pageControllerAttrs);
foreach ($pageControllerAttributes->getArray(self::ATTR_PAGE_CONTROLLER_CI_PANELS_KEY, false, array(),
TypeConstraint::createArrayLike('array')) as $panelName => $ciPanelAttrs) {
$ciPanelConfigs[] = CiConfigUtils::createPanelConfig($ciPanelAttrs, $panelName);
}
$pageConfig->addPageControllerConfig(new PageControllerConfig($pageControllerEiSpecId, $ciPanelConfigs));
}
return $pageConfig;
} | {@inheritDoc}
@see \n2n\core\module\ConfigDescriber::buildCustomConfig() | entailment |
public function parseDateTime($rawValue) {
if (null === $rawValue) {
return null;
}
try {
$dateTime = DateUtils::createDateTimeFromFormat(MysqlDateTimeColumn::FORMAT_DATE_TIME, $rawValue);
if ($dateTime->getTimestamp() === false) {
throw new DateParseException('Invalid datetime raw value: ' . $rawValue);
}
return $dateTime;
} catch (\n2n\util\DateParseException $e) {
throw new \InvalidArgumentException($e->getMessage(), 0, $e);
}
} | /* (non-PHPdoc)
@see n2n\persistence\meta.OrmDialectConfig::parseDateTime() | entailment |
public function buildDateTimeRawValue(\DateTime $dateTime = null) {
if (null === $dateTime) {
return null;
}
return DateUtils::formatDateTime($dateTime, MysqlDateTimeColumn::FORMAT_DATE_TIME);
} | /* (non-PHPdoc)
@see n2n\persistence\meta.OrmDialectConfig::buildRawValue() | entailment |
public function createBackuper(array $metaEnities = null): Backuper {
return new MssqlBackuper($this->dbh, $this->createDatabase(), $metaEnities);
} | {@inheritDoc}
@see \n2n\persistence\meta\Database::createBackuper()
@return Backuper | entailment |
public function createColumnFactory(): ColumnFactory {
if (!($this->columnFactory)) {
$this->columnFactory = new PgsqlColumnFactory($this);
}
return $this->columnFactory;
} | {@inheritDoc}
@see \n2n\persistence\meta\structure\Table::createColumnFactory()
@return ColumnFactory | entailment |
public function copy(string $newTableName = null): Table {
if (is_null($newTableName)) {
$newTableName = $this->getName();
}
$newTable = new PgsqlTable($newTableName);
$newTable->applyColumnsFrom($this);
$newTable->applyIndexesFrom($this);
return $newTable;
} | {@inheritDoc}
@see \n2n\persistence\meta\structure\Table::copy()
@return Table | entailment |
public function createMetaEntityFactory(): MetaEntityFactory {
if (!(isset($this->metaEntityFactory))) {
$this->metaEntityFactory = new OracleMetaEntityFactory($this);
}
return $this->metaEntityFactory;
} | {@inheritDoc}
@see \n2n\persistence\meta\Database::createMetaEntityFactory()
@return MetaEntityFactory | entailment |
public function createTable(string $name): Table {
$newTable = new PgsqlTable($name);
$this->database->addMetaEntity($newTable);
return $newTable;
} | {@inheritDoc}
@see \n2n\persistence\meta\structure\MetaEntityFactory::createTable()
@return Table | entailment |
public function createView(string $name, string $query): View {
$newView = new CommonView($name, $query);
$this->database->addMetaEntity($newView);
return $newView;
} | {@inheritDoc}
@see \n2n\persistence\meta\structure\MetaEntityFactory::createView()
@return View | entailment |
public function getTitle($overwriteTitle = null) {
if (null !== $overwriteTitle) {
return $this->view->getHtmlBuilder()->getOut($overwriteTitle);
}
return $this->view->getHtmlBuilder()->getEsc($this->meta->getTitle());
} | Same as {@link PageHtmlBuilder::title()} but returns the output.
@return \n2n\web\ui\UiComponent | entailment |
public function contentItems(string $panelName) {
foreach ($this->meta()->getContentItems($panelName) as $contentItem) {
$this->view->out($contentItem->createUiComponent($this->view));
}
} | <p>Prints the content items of the current page which are assigned to the panel with passed name.</p>
<pre>
<div><?php $pageHtml->contentItems('main') ?></div>
</pre>
@see PageHtmlBuilderMeta::getContentItems()
@param string $panelName | entailment |
public function getContentItems(string $panelName) {
$contentItems = $this->meta()->getContentItems($panelName);
if (empty($contentItems)) return null;
$htmlSnippet = new HtmlSnippet();
foreach ($contentItems as $contentItem) {
$htmlSnippet->appendLn($contentItem->createUiComponent($this->view));
}
return $htmlSnippet;
} | Same as {@link PageHtmlBuilder::contentItems()} but returns the output.
@return \n2n\web\ui\UiComponent|null | entailment |
public function navigation(NavComposer $navComposer = null, array $attrs = null, array $ulAttrs = null,
array $liAttrs = null, array $aAttrs = null) {
$this->view->out($this->getNavigation($navComposer, $attrs, $ulAttrs, $liAttrs, $aAttrs));
} | <p>Prints a customized navigation.</p>
<p>
<strong>Usage example</strong>
<pre>
<?php $pageHtml->navigation(Nav::root()->levels(2), array('id' => 'main-navigation')) ?>
</pre>
</p>
@param NavComposer $navComposer <p>Use {@link \page\ui\nav\Nav} to build a suitable {@link NavComposer}.
If you pass null, the default {@link NavComposer} will be used (<code>Nav::root()</code>).</p>
<p>See {@link \page\ui\nav\Nav} for further information.</p>
@param array $attrs html attributes of the outer ul
@param array $ulAttrs html attributes of every inner ul
@param array $liAttrs html attributes of every li | entailment |
public function getNavigation(NavComposer $navComposer = null, array $attrs = null, array $ulAttrs = null,
array $liAttrs = null, array $aAttrs = null) {
if ($navComposer === null) {
$navComposer = Nav::root();
}
return $navComposer->build($this->view, $attrs, $ulAttrs, $liAttrs, $aAttrs);
} | Same as {@link PageHtmlBuilder::navigation()} but returns the output.
@return \n2n\web\ui\UiComponent | entailment |
public function breadcrumbs(array $attrs = null, array $liAttrs = null, array $aAttrs = null, $divider = null) {
$this->view->out($this->getBreadcrumbs($attrs, $liAttrs, $aAttrs, $divider));
} | <p>Prints a breadcrumb navigation of the current page in form of a ul-/li-list.</p>
<p>Also see {@link PageHtmlBuilderMeta::getBreadcrumbNavBranches()} to find out how to build a breadcrumb navigation.</p>
@param array $attrs Html attributes of the ul element.
@param array $liAttrs Html attributes of each li element
@param string $divider Pass a {@link \n2n\web\ui\UiComponent} or string if a divider span element should be printed
in each li element. | entailment |
public function getBreadcrumbs(array $attrs = null, array $liAttrs = null, array $aAttrs = null, $divider = null) {
$navBranches = $this->meta->getBreadcrumbNavBranches();
if (empty($navBranches)) return null;
$html = $this->view->getHtmlBuilder();
$lis = array();
$lastNavBranch = array_pop($navBranches);
foreach ($navBranches as $navBranch) {
$lis[] = $li = new HtmlElement('li', $liAttrs, $html->getLink(MurlPage::obj($navBranch), null, $aAttrs));
if ($divider !== null) {
$li->appendContent(new HtmlElement('span', array('class' => 'divider'), $divider));
}
}
$lis[] = new HtmlElement('li', HtmlUtils::mergeAttrs(array('class' => 'active'), $liAttrs),
$html->getLink(MurlPage::obj($lastNavBranch), null, $aAttrs));
return new HtmlElement('ul', $attrs, $lis);
} | Same as {@link PageHtmlBuilder::breadcrumbs()} but returns the output.
@return \n2n\web\ui\UiComponent | entailment |
public function localeSwitch(array $ulAttrs = null, array $liAttrs = null, array $aAttrs = null) {
$this->view->out($this->getN2nLocaleSwitch($ulAttrs, $liAttrs, $aAttrs));
} | <p>Prints a locale switch navigation of the current page.</p>
<p>Also see {@link PageHtmlBuilderMeta::getN2nLocaleSwitchUrls()} to find out how to customize the output.</p>
@param array $ulAttrs
@param array $liAttrs | entailment |
public function getN2nLocaleSwitch(array $ulAttrs = null, array $liAttrs = null, array $aAttrs = null) {
$urls = $this->meta->getN2nLocaleSwitchUrls();
if (empty($urls)) {
return null;
}
$n2nLocales = array();
$langUsages = array();
foreach (array_keys($urls) as $n2nLocaleId) {
$n2nLocale = new N2nLocale($n2nLocaleId);
$n2nLocales[$n2nLocaleId] = $n2nLocale;
$langId = $n2nLocale->getLanguageId();
if (!isset($langUsages[$langId])) $langUsages[$langId] = 1;
else $langUsages[$langId]++;
}
$ul = new HtmlElement('ul', $ulAttrs);
$html = $this->view->getHtmlBuilder();
foreach ($urls as $n2nLocaleId => $navUrl) {
$label = null;
if ($langUsages[$n2nLocales[$n2nLocaleId]->getLanguageId()] > 1) {
$label = $n2nLocales[$n2nLocaleId]->toPrettyId();
} else {
$label = mb_strtoupper($n2nLocales[$n2nLocaleId]->getLanguageId());
}
$elemLiAttrs = $liAttrs;
if ($this->view->getN2nLocale()->equals($n2nLocales[$n2nLocaleId])) {
$elemLiAttrs = HtmlUtils::mergeAttrs((array) $elemLiAttrs, array('class' => 'active'));
}
$ul->appendLn(new HtmlElement('li', $elemLiAttrs, $html->getLink($navUrl, $label, $aAttrs)));
}
return $ul;
} | Same as {@link PageHtmlBuilder::breadcrumbs()} but returns the output.
@return \n2n\web\ui\UiComponent | entailment |
private function parseViewCreateStatement($createStatement) {
$matches = preg_split('/AS/i', $createStatement);
if (isset($matches[1])) {
return trim($matches[1]);
}
return $createStatement;
} | Parse the given create statement and extract the query
@param string $createStatement | entailment |
public function createBackuper(array $metaEnities = null): Backuper {
return new PgsqlBackuper($this->dbh, $this->createDatabase(), $metaEnities);
} | {@inheritDoc}
@see \n2n\persistence\meta\Database::createBackuper()
@return Backuper | entailment |
protected function buildDatabase(): DatabaseAdapter {
$dbName = $this->determineDbName();
$database = new PgsqlDatabase($dbName, $this->determineDbCharset($dbName),
$this->getPersistedMetaEntities($dbName), $this->determineDbAttrs($dbName));
foreach ($database->getMetaEntities() as $metaEntity) {
if (!$metaEntity instanceof Table) continue;
$this->metaEntityBuilder->applyIndexesForTable($dbName, $metaEntity);
}
return $database;
} | {@inheritDoc}
@see \n2n\persistence\meta\structure\common\MetaManagerAdapter::buildDatabase()
@return DatabaseAdapter | entailment |
public function createColumnFactory(): ColumnFactory {
if (!($this->columnFactory)) {
$this->columnFactory = new OracleColumnFactory($this);
}
return $this->columnFactory;
} | {@inheritDoc}
@see \n2n\persistence\meta\structure\Table::createColumnFactory()
@return ColumnFactory | entailment |
public static function hook(string ...$hookKeys): NavComposer {
return new NavComposer(NavBranchCriteria::create(null, null, $hookKeys));
} | Uses page as base which is marked with passed hooks.
See {@link https://support.n2n.rocks/de/page/docs/navigieren#hooks hooks article} for further
information about hooks.
@param string ...$hookKeys keys of hooks
@return \page\ui\nav\NavComposer | entailment |
public function createBackuper(array $metaEnities = null): Backuper {
return new MysqlBackuper($this->dbh, $this->createDatabase(), $metaEnities);
} | {@inheritDoc}
@see \n2n\persistence\meta\Database::createBackuper()
@return Backuper | entailment |
public function createEnumColumn(string $name, array $values): EnumColumn {
$column = new CommonEnumColumn($name, $values);
$this->table->addColumn($column);
return $column;
} | {@inheritDoc}
@see \n2n\persistence\meta\structure\ColumnFactory::createEnumColumn()
@return EnumColumn | entailment |
public function createRecord($tableName, array $recordData = [])
{
if (!$this->isNoneSystemTableNameAllowed($tableName)) {
throw new \InvalidArgumentException('The table name "' . $tableName . '" is not allowed.', 1334438817);
}
if (isset($recordData['uid'])) {
throw new \InvalidArgumentException('The column "uid" must not be set in $recordData.', 1334438963);
}
return $this->createRecordWithoutTableNameChecks($tableName, $recordData);
} | Creates a new dummy record for unit tests.
If no record data for the new array is given, an empty record will be
created. It will only contain a valid UID and the "is_dummy_record" flag
will be set to 1.
Should there be any problem creating the record (wrong table name or a
problem with the database), 0 instead of a valid UID will be returned.
@param string $tableName
the name of the table on which the record should be created, must
not be empty
@param array $recordData
associative array that contains the data to save in the new
record, may be empty, but must not contain the key "uid"
@return int the UID of the new record, will be > 0
@throws \InvalidArgumentException | entailment |
protected function createRecordWithoutTableNameChecks($tableName, array $recordData)
{
$dummyColumnName = $this->getDummyColumnName($tableName);
$recordData[$dummyColumnName] = 1;
$uid = \Tx_Phpunit_Service_Database::insert($tableName, $recordData);
$this->markTableAsDirty($tableName);
return $uid;
} | Creates a new dummy record for unit tests without checks for the table
name.
If no record data for the new array is given, an empty record will be
created. It will only contain a valid UID and the "is_dummy_record" flag
will be set to 1.
Should there be any problem creating the record (wrong table name or a
problem with the database), 0 instead of a valid UID will be returned.
@param string $tableName
the name of the table on which the record should be created, must
not be empty
@param array $recordData
associative array that contains the data to save in the new
record, may be empty, but must not contain the key "uid"
@return int the UID of the new record, will be > 0 | entailment |
protected function createGeneralPageRecord($documentType, $parentId, array $recordData)
{
if (isset($recordData['uid'])) {
throw new \InvalidArgumentException('The column "uid" must not be set in $recordData.', 1334438971);
}
if (isset($recordData['pid'])) {
throw new \InvalidArgumentException('The column "pid" must not be set in $recordData.', 1334438980);
}
if (isset($recordData['doktype'])) {
throw new \InvalidArgumentException('The column "doktype" must not be set in $recordData.', 1334438986);
}
$completeRecordData = $recordData;
$completeRecordData['pid'] = $parentId;
$completeRecordData['doktype'] = $documentType;
return $this->createRecordWithoutTableNameChecks('pages', $completeRecordData);
} | Creates a page record with the document type given by the first parameter
$documentType.
The record will be created on the page with the UID given by the second
parameter $parentId.
@param int $documentType
document type of the record to create, must be > 0
@param int $parentId
UID of the page on which the record should be created
@param array $recordData
associative array that contains the data to save in the record,
may be empty, but must not contain the keys "uid", "pid" or "doktype"
@return int the UID of the new record, will be > 0
@throws \InvalidArgumentException | entailment |
public function createContentElement($pageId = 0, array $recordData = [])
{
if (isset($recordData['uid'])) {
throw new \InvalidArgumentException('The column "uid" must not be set in $recordData.', 1334439000);
}
if (isset($recordData['pid'])) {
throw new \InvalidArgumentException('The column "pid" must not be set in $recordData.', 1334439007);
}
$completeRecordData = $recordData;
$completeRecordData['pid'] = $pageId;
if (!isset($completeRecordData['CType'])) {
$completeRecordData['CType'] = 'text';
}
return $this->createRecordWithoutTableNameChecks('tt_content', $completeRecordData);
} | Creates a FE content element on the page with the UID given by the first
parameter $pageId.
Created content elements are text elements by default, but the content
element's type can be overwritten by setting the key 'CType' in the
parameter $recordData.
@param int $pageId
UID of the page on which the content element should be created
@param array $recordData
associative array that contains the data to save in the content
element, may be empty, but must not contain the keys "uid" or "pid"
@return int the UID of the new content element, will be > 0
@throws \InvalidArgumentException | entailment |
public function createTemplate($pageId, array $recordData = [])
{
if ($pageId <= 0) {
throw new \InvalidArgumentException('$pageId must be > 0.', 1334439016);
}
if (isset($recordData['uid'])) {
throw new \InvalidArgumentException('The column "uid" must not be set in $recordData.', 1334439024);
}
if (isset($recordData['pid'])) {
throw new \InvalidArgumentException('The column "pid" must not be set in $recordData.', 1334439032);
}
$completeRecordData = $recordData;
$completeRecordData['pid'] = $pageId;
return $this->createRecordWithoutTableNameChecks('sys_template', $completeRecordData);
} | Creates a template on the page with the UID given by the first parameter
$pageId.
@param int $pageId
UID of the page on which the template should be created, must be > 0
@param array $recordData
associative array that contains the data to save in the new
template, may be empty, but must not contain the keys "uid" or "pid"
@return int the UID of the new template, will be > 0
@throws \InvalidArgumentException | entailment |
public function createFrontEndUser(
$frontEndUserGroups = '',
array $recordData = []
) {
$frontEndUserGroupsWithoutSpaces = str_replace(' ', '', $frontEndUserGroups);
if ($frontEndUserGroupsWithoutSpaces === '') {
$frontEndUserGroupsWithoutSpaces = $this->createFrontEndUserGroup();
}
if (!preg_match('/^(?:[1-9]+\\d*,?)+$/', $frontEndUserGroupsWithoutSpaces)
) {
throw new \InvalidArgumentException(
'$frontEndUserGroups must contain a comma-separated list of UIDs. Each UID must be > 0.',
1334439059
);
}
if (isset($recordData['uid'])) {
throw new \InvalidArgumentException('The column "uid" must not be set in $recordData.', 1334439065);
}
if (isset($recordData['usergroup'])) {
throw new \InvalidArgumentException('The column "usergroup" must not be set in $recordData.', 1334439071);
}
$completeRecordData = $recordData;
$completeRecordData['usergroup'] = $frontEndUserGroupsWithoutSpaces;
return $this->createRecordWithoutTableNameChecks('fe_users', $completeRecordData);
} | Creates a FE user record.
@param string $frontEndUserGroups
comma-separated list of UIDs of the user groups to which the new
user belongs, each must be > 0, may contain spaces, if empty a new
FE user group will be created
@param array $recordData
associative array that contains the data to save in the new user
record, may be empty, but must not contain the keys "uid" or
"usergroup"
@return int the UID of the new FE user, will be > 0
@throws \InvalidArgumentException | entailment |
public function createAndLoginFrontEndUser($frontEndUserGroups = '', array $recordData = [])
{
$frontEndUserUid = $this->createFrontEndUser($frontEndUserGroups, $recordData);
$this->loginFrontEndUser($frontEndUserUid);
return $frontEndUserUid;
} | Creates and logs in an FE user.
@param string $frontEndUserGroups
comma-separated list of UIDs of the user groups to which the new
user belongs, each must be > 0, may contain spaces; if empty a new
front-end user group is created
@param array $recordData
associative array that contains the data to save in the new user
record, may be empty, but must not contain the keys "uid" or
"usergroup"
@return int the UID of the new FE user, will be > 0 | entailment |
public function changeRecord($tableName, $uid, array $recordData)
{
$dummyColumnName = $this->getDummyColumnName($tableName);
if (!$this->isTableNameAllowed($tableName)) {
throw new \InvalidArgumentException(
'The table "' . $tableName . '" is not on the lists with allowed tables.',
1334439098
);
}
if ($uid === 0) {
throw new \InvalidArgumentException('The parameter $uid must not be zero.', 1334439105);
}
if (empty($recordData)) {
throw new \InvalidArgumentException('The array with the new record data must not be empty.', 1334439111);
}
if (isset($recordData['uid'])) {
throw new \InvalidArgumentException(
'The parameter $recordData must not contain changes to the UID of a record.',
1334439119
);
}
if (isset($recordData[$dummyColumnName])) {
throw new \InvalidArgumentException(
'The parameter $recordData must not contain changes to the ' .
'field "' . $dummyColumnName . '". It is impossible to ' .
'convert a dummy record into a regular record.',
1334439125
);
}
if (!$this->countRecords($tableName, 'uid=' . $uid)) {
throw new \Tx_Phpunit_Exception_Database(1334439132);
}
\Tx_Phpunit_Service_Database::update(
$tableName,
'uid = ' . $uid . ' AND ' . $dummyColumnName . ' = 1',
$recordData
);
} | Changes an existing dummy record and stores the new data for this
record. Only fields that get new values in $recordData will be changed,
everything else will stay untouched.
The array with the new recordData must contain at least one entry, but
must not contain a new UID for the record. If you need to change the UID,
you have to create a new record!
@param string $tableName
the name of the table, must not be empty
@param int $uid
the UID of the record to change, must not be empty
@param array $recordData
associative array containing key => value pairs for those fields
of the record that need to be changed, must not be empty
@return void
@throws \InvalidArgumentException
@throws \Tx_Phpunit_Exception_Database | entailment |
public function deleteRecord($tableName, $uid)
{
if (!$this->isNoneSystemTableNameAllowed($tableName)) {
throw new \InvalidArgumentException('The table name "' . $tableName . '" is not allowed.', 1334439187);
}
\Tx_Phpunit_Service_Database::delete(
$tableName,
'uid = ' . $uid . ' AND ' . $this->getDummyColumnName($tableName) . ' = 1'
);
} | Deletes a dummy record from the database.
Important: Only dummy records from non-system tables can be deleted with
this method. Should there for any reason exist a real record with that
UID, it would not be deleted.
@param string $tableName
name of the table from which the record should be deleted, must
not be empty
@param int $uid
UID of the record to delete, must be > 0
@return void
@throws \InvalidArgumentException | entailment |
public function createRelation($tableName, $uidLocal, $uidForeign, $sorting = 0)
{
if (!$this->isNoneSystemTableNameAllowed($tableName)) {
throw new \InvalidArgumentException('The table name "' . $tableName . '" is not allowed.', 1334439196);
}
// Checks that the two given UIDs are valid.
if ((int)$uidLocal <= 0) {
throw new \InvalidArgumentException(
'$uidLocal must be an integer > 0, but actually is "' . $uidLocal . '"',
1334439206
);
}
if ((int)$uidForeign <= 0) {
throw new \InvalidArgumentException(
'$uidForeign must be an integer > 0, but actually is "' . $uidForeign . '"',
1334439213
);
}
$this->markTableAsDirty($tableName);
$recordData = [
'uid_local' => $uidLocal,
'uid_foreign' => $uidForeign,
'sorting' => ($sorting > 0) ? $sorting : $this->getRelationSorting($tableName, $uidLocal),
$this->getDummyColumnName($tableName) => 1,
];
\Tx_Phpunit_Service_Database::insert($tableName, $recordData);
} | Creates a relation between two records on different tables (so called
m:n relation).
@param string $tableName
name of the m:n table to which the record should be added, must
not be empty
@param int $uidLocal
UID of the local table, must be > 0
@param int $uidForeign
UID of the foreign table, must be > 0
@param int $sorting
sorting value of the relation, the default value is 0, which
enables automatic sorting, a value >= 0 overwrites the automatic
sorting
@return void
@throws \InvalidArgumentException | entailment |
public function createRelationAndUpdateCounter(
$tableName,
$uidLocal,
$uidForeign,
$columnName
) {
if (!$this->isTableNameAllowed($tableName)) {
throw new \InvalidArgumentException('The table name "' . $tableName . '" is not allowed.');
}
if ($uidLocal <= 0) {
throw new \InvalidArgumentException(
'$uidLocal must be > 0, but actually is "' . $uidLocal . '"',
1334439220
);
}
if ($uidForeign <= 0) {
throw new \InvalidArgumentException(
'$uidForeign must be > 0, but actually is "' . $uidForeign . '"',
1334439233
);
}
$tca = \Tx_Phpunit_Service_Database::getTcaForTable($tableName);
$relationConfiguration = $tca['columns'][$columnName];
if (!isset($relationConfiguration['config']['MM']) || ($relationConfiguration['config']['MM'] === '')) {
throw new Exception(
'The column ' . $columnName . ' in the table ' . $tableName .
' is not configured to contain m:n relations using a m:n table.',
1334439257
);
}
if (isset($relationConfiguration['config']['MM_opposite_field'])) {
// Switches the order of $uidForeign and $uidLocal as the relation
// is the reverse part of a bidirectional relation.
$this->createRelationAndUpdateCounter(
$relationConfiguration['config']['foreign_table'],
$uidForeign,
$uidLocal,
$relationConfiguration['config']['MM_opposite_field']
);
} else {
$this->createRelation(
$relationConfiguration['config']['MM'],
$uidLocal,
$uidForeign
);
}
$this->increaseRelationCounter($tableName, $uidLocal, $columnName);
} | Creates a relation between two records based on the rules defined in TCA
regarding the relation.
@param string $tableName
name of the table from which a relation should be created, must
not be empty
@param int $uidLocal
UID of the record in the local table, must be > 0
@param int $uidForeign
UID of the record in the foreign table, must be > 0
@param string $columnName
name of the column in which the relation counter should be
updated, must not be empty
@return void
@throws \InvalidArgumentException
@throws Exception | entailment |
public function removeRelation($tableName, $uidLocal, $uidForeign)
{
if (!$this->isNoneSystemTableNameAllowed($tableName)) {
throw new \InvalidArgumentException('The table name "' . $tableName . '" is not allowed.', 1334439276);
}
\Tx_Phpunit_Service_Database::delete(
$tableName,
'uid_local = ' . $uidLocal . ' AND uid_foreign = ' . $uidForeign .
' AND ' . $this->getDummyColumnName($tableName) . ' = 1'
);
} | Deletes a dummy relation from an m:n table in the database.
Important: Only dummy records can be deleted with this method. Should there
for any reason exist a real record with that combination of local and
foreign UID, it would not be deleted!
@param string $tableName
name of the table from which the record should be deleted, must
not be empty
@param int $uidLocal
UID on the local table, must be > 0
@param int $uidForeign
UID on the foreign table, must be > 0
@return void
@throws \InvalidArgumentException | entailment |
public function cleanUp($performDeepCleanUp = false)
{
$this->cleanUpTableSet(false, $performDeepCleanUp);
$this->cleanUpTableSet(true, $performDeepCleanUp);
$this->deleteAllDummyFoldersAndFiles();
$this->discardFakeFrontEnd();
foreach ($this->getHooks() as $hook) {
if (!($hook instanceof \Tx_Phpunit_Interface_FrameworkCleanupHook)) {
throw new Exception(
'The class ' . get_class($hook) . ' must implement \\Tx_Phpunit_Interface_FrameworkCleanupHook.',
1299257923
);
}
/** @var \Tx_Phpunit_Interface_FrameworkCleanupHook $hook */
$hook->cleanUp();
}
RootlineUtility::purgeCaches();
} | Deletes all dummy records that have been added through this framework.
For this, all records with the "is_dummy_record" flag set to 1 will be
deleted from all tables that have been used within this instance of the
testing framework.
If you set $performDeepCleanUp to TRUE, it will go through ALL tables to
which the current instance of the testing framework has access. Please
consider well, whether you want to do this as it's a huge performance
issue.
@param bool $performDeepCleanUp
whether a deep clean up should be performed
@return void
@throws Exception | entailment |
protected function cleanUpTableSet($useSystemTables, $performDeepCleanUp)
{
if ($useSystemTables) {
$tablesToCleanUp = $performDeepCleanUp ? $this->allowedSystemTables : $this->dirtySystemTables;
} else {
$tablesToCleanUp = $performDeepCleanUp ? $this->ownAllowedTables : $this->dirtyTables;
}
foreach ($tablesToCleanUp as $currentTable) {
$dummyColumnName = $this->getDummyColumnName($currentTable);
if (!\Tx_Phpunit_Service_Database::tableHasColumn($currentTable, $dummyColumnName)) {
continue;
}
// Runs a delete query for each allowed table. A "one-query-deletes-them-all" approach was tested,
// but we didn't find a working solution for that.
\Tx_Phpunit_Service_Database::delete($currentTable, $dummyColumnName . ' = 1');
$this->resetAutoIncrementLazily($currentTable);
}
$this->dirtyTables = [];
} | Deletes a set of records that have been added through this framework for
a set of tables (either the test tables or the allowed system tables).
For this, all records with the "is_dummy_record" flag set to 1 will be
deleted from all tables that have been used within this instance of the
testing framework.
If you set $performDeepCleanUp to TRUE, it will go through ALL tables to
which the current instance of the testing framework has access. Please
consider well, whether you want to do this as it's a huge performance
issue.
@param bool $useSystemTables
whether to clean up the system tables (true) or the non-system
test tables (false)
@param bool $performDeepCleanUp
whether a deep clean up should be performed
@return void | entailment |
protected function deleteAllDummyFoldersAndFiles()
{
// If the upload folder was created by the testing framework, it can be
// removed at once.
if (isset($this->dummyFolders['uploadFolder'])) {
GeneralUtility::rmdir($this->getUploadFolderPath(), true);
$this->dummyFolders = [];
$this->dummyFiles = [];
} else {
foreach ($this->dummyFiles as $dummyFile) {
$this->deleteDummyFile($dummyFile);
}
foreach ($this->dummyFolders as $dummyFolder) {
$this->deleteDummyFolder($dummyFolder);
}
}
} | Deletes all dummy files and folders.
@return void | entailment |
public function createDummyFile($fileName = 'test.txt', $content = '')
{
$this->createDummyUploadFolder();
$uniqueFileName = $this->getUniqueFileOrFolderPath($fileName);
if (!GeneralUtility::writeFile($uniqueFileName, $content)) {
throw new Exception('The file ' . $uniqueFileName . ' could not be created.', 1334439291);
}
$this->addToDummyFileList($uniqueFileName);
return $uniqueFileName;
} | Creates an empty dummy file with a unique file name in the calling
extension's upload directory.
@param string $fileName
path of the dummy file to create, relative to the calling
extension's upload directory, must not be empty
@param string $content
string content for the file to create, may be empty
@return string
the absolute path of the created dummy file, will not be empty
@throws Exception | entailment |
public function createDummyZipArchive($fileName = 'test.zip', array $filesToAddToArchive = [])
{
$this->checkForZipArchive();
$this->createDummyUploadFolder();
$uniqueFileName = $this->getUniqueFileOrFolderPath($fileName);
$zip = new ZipArchive();
if ($zip->open($uniqueFileName, ZipArchive::CREATE) !== true) {
throw new Exception('The new ZIP archive "' . $fileName . '" could not be created.', 1334439299);
}
$contents = !empty($filesToAddToArchive) ? $filesToAddToArchive : [$this->createDummyFile()];
foreach ($contents as $pathToFile) {
if (!file_exists($pathToFile)) {
throw new Exception(
'The provided path "' . $pathToFile . '" does not point to an existing file.',
1334439306
);
}
$zip->addFile($pathToFile, $this->getPathRelativeToUploadDirectory($pathToFile));
}
$zip->close();
$this->addToDummyFileList($uniqueFileName);
return $uniqueFileName;
} | Creates a dummy ZIP archive with a unique file name in the calling
extension's upload directory.
@param string $fileName
path of the dummy ZIP archive to create, relative to the calling
extension's upload directory, must not be empty
@param string[] $filesToAddToArchive
Absolute paths of the files to add to the ZIP archive. Note that
the archives directory structure will be relative to the upload
folder path, so only files within this folder or in sub-folders of
this folder can be added.
The provided array may be empty, but as ZIP archives cannot be
empty, a content-less dummy text file will be added to the archive
then.
@return string
the absolute path of the created dummy ZIP archive, will not be empty
@throws Exception if the PHP installation does not provide ZIPArchive | entailment |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.