本文整理汇总了PHP中TYPO3\CMS\Core\Utility\StringUtility::beginsWith方法的典型用法代码示例。如果您正苦于以下问题:PHP StringUtility::beginsWith方法的具体用法?PHP StringUtility::beginsWith怎么用?PHP StringUtility::beginsWith使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TYPO3\CMS\Core\Utility\StringUtility
的用法示例。
在下文中一共展示了StringUtility::beginsWith方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
/**
* @param array|NULL $backendUser
* @param int $size
* @param bool $showIcon
* @return string
*/
public function render(array $backendUser = NULL, $size = 32, $showIcon = FALSE)
{
$size = (int) $size;
if (!is_array($backendUser)) {
$backendUser = $this->getBackendUser()->user;
}
$image = parent::render($backendUser, $size, $showIcon);
if (!StringUtility::beginsWith($image, '<span class="avatar"><span class="avatar-image"></span>') || empty($backendUser['email'])) {
return $image;
}
$cachedFilePath = PATH_site . 'typo3temp/t3gravatar/';
$cachedFileName = sha1($backendUser['email'] . $size) . '.jpg';
if (!file_exists($cachedFilePath . $cachedFileName)) {
$gravatar = 'https://www.gravatar.com/avatar/' . md5(strtolower($backendUser['email'])) . '?s=' . $size . '&d=404';
$gravatarImage = GeneralUtility::getUrl($gravatar);
if (empty($gravatarImage)) {
return $image;
}
GeneralUtility::writeFileToTypo3tempDir($cachedFileName, $gravatarImage);
}
// Icon
$icon = '';
if ($showIcon) {
$icon = '<span class="avatar-icon">' . IconUtility::getSpriteIconForRecord('be_users', $backendUser) . '</span>';
}
$relativeFilePath = PathUtility::getRelativePath(PATH_typo3, $cachedFilePath);
return '<span class="avatar"><span class="avatar-image">' . '<img src="' . $relativeFilePath . $cachedFileName . '" width="' . $size . '" height="' . $size . '" /></span>' . $icon . '</span>';
}
示例2: tearDown
/**
* Unset all additional properties of test classes to help PHP
* garbage collection. This reduces memory footprint with lots
* of tests.
*
* If owerwriting tearDown() in test classes, please call
* parent::tearDown() at the end. Unsetting of own properties
* is not needed this way.
*
* @throws \RuntimeException
* @return void
*/
protected function tearDown()
{
// Unset properties of test classes to safe memory
$reflection = new \ReflectionObject($this);
foreach ($reflection->getProperties() as $property) {
$declaringClass = $property->getDeclaringClass()->getName();
if (!$property->isStatic() && $declaringClass !== \TYPO3\CMS\Core\Tests\UnitTestCase::class && $declaringClass !== \TYPO3\CMS\Core\Tests\BaseTestCase::class && strpos($property->getDeclaringClass()->getName(), 'PHPUnit_') !== 0) {
$propertyName = $property->getName();
unset($this->{$propertyName});
}
}
unset($reflection);
// Delete registered test files and directories
foreach ($this->testFilesToDelete as $absoluteFileName) {
$absoluteFileName = GeneralUtility::fixWindowsFilePath(PathUtility::getCanonicalPath($absoluteFileName));
if (!GeneralUtility::validPathStr($absoluteFileName)) {
throw new \RuntimeException('tearDown() cleanup: Filename contains illegal characters', 1410633087);
}
if (!StringUtility::beginsWith($absoluteFileName, PATH_site . 'typo3temp/')) {
throw new \RuntimeException('tearDown() cleanup: Files to delete must be within typo3temp/', 1410633412);
}
// file_exists returns false for links pointing to not existing targets, so handle links before next check.
if (@is_link($absoluteFileName) || @is_file($absoluteFileName)) {
unlink($absoluteFileName);
} elseif (@is_dir($absoluteFileName)) {
GeneralUtility::rmdir($absoluteFileName, true);
} else {
throw new \RuntimeException('tearDown() cleanup: File, link or directory does not exist', 1410633510);
}
}
$this->testFilesToDelete = array();
}
示例3: addData
/**
* Resolve placeholders for input/text fields. Placeholders that are simple
* strings will be returned unmodified. Placeholders beginning with __row are
* being resolved, possibly traversing multiple tables.
*
* @param array $result
* @return array
*/
public function addData(array $result)
{
foreach ($result['processedTca']['columns'] as $fieldName => $fieldConfig) {
// Placeholders are only valid for input and text type fields
if ($fieldConfig['config']['type'] !== 'input' && $fieldConfig['config']['type'] !== 'text' || !isset($fieldConfig['config']['placeholder'])) {
continue;
}
// Resolve __row|field type placeholders
if (StringUtility::beginsWith($fieldConfig['config']['placeholder'], '__row|')) {
// split field names into array and remove the __row indicator
$fieldNameArray = array_slice(GeneralUtility::trimExplode('|', $fieldConfig['config']['placeholder'], true), 1);
$result['processedTca']['columns'][$fieldName]['config']['placeholder'] = $this->getPlaceholderValue($fieldNameArray, $result);
}
// Resolve placeholders from language files
if (StringUtility::beginsWith($fieldConfig['config']['placeholder'], 'LLL:')) {
$result['processedTca']['columns'][$fieldName]['config']['placeholder'] = $this->getLanguageService()->sl($fieldConfig['config']['placeholder']);
}
// Remove empty placeholders
if (empty($fieldConfig['config']['placeholder'])) {
unset($result['processedTca']['columns'][$fieldName]['config']['placeholder']);
continue;
}
}
return $result;
}
示例4: fetchType
/**
* Type fetching method, based on the type that softRefParserObj returns
*
* @param array $value Reference properties
* @param string $type Current type
* @param string $key Validator hook name
* @return string fetched type
*/
public function fetchType($value, $type, $key)
{
if (StringUtility::beginsWith(strtolower($value['tokenValue']), 'file:')) {
$type = 'file';
}
return $type;
}
示例5: generateInlineMarkup
/**
* @param Icon $icon
* @param array $options
* @return string
* @throws \InvalidArgumentException
*/
protected function generateInlineMarkup(Icon $icon, array $options)
{
if (empty($options['source'])) {
throw new \InvalidArgumentException('The option "source" is required and must not be empty', 1440754980);
}
$source = $options['source'];
if (StringUtility::beginsWith($source, 'EXT:') || !StringUtility::beginsWith($source, '/')) {
$source = GeneralUtility::getFileAbsFileName($source);
}
return $this->getInlineSvg($source);
}
示例6: generateMarkup
/**
* @param Icon $icon
* @param array $options
* @return string
* @throws \InvalidArgumentException
*/
protected function generateMarkup(Icon $icon, array $options)
{
if (empty($options['source'])) {
throw new \InvalidArgumentException('[' . $icon->getIdentifier() . '] The option "source" is required and must not be empty', 1440754980);
}
$source = $options['source'];
if (StringUtility::beginsWith($source, 'EXT:') || !StringUtility::beginsWith($source, '/')) {
$source = GeneralUtility::getFileAbsFileName($source);
}
$source = PathUtility::getAbsoluteWebPath($source);
return '<img src="' . htmlspecialchars($source) . '" width="' . $icon->getDimension()->getWidth() . '" height="' . $icon->getDimension()->getHeight() . '" />';
}
示例7: getNativeDefaultValue
/**
* Return the default value of a field formatted to match the native MySQL SQL dialect
*
* @param array $fieldDefinition
* @return mixed
*/
protected function getNativeDefaultValue($fieldDefinition)
{
if (!$fieldDefinition['has_default']) {
$returnValue = null;
} elseif ($fieldDefinition['type'] === 'SERIAL' && substr($fieldDefinition['default_value'], 0, 7) === 'nextval') {
$returnValue = null;
} elseif ($fieldDefinition['type'] === 'varchar') {
// Strip character class and unquote string
if (StringUtility::beginsWith($fieldDefinition['default_value'], 'NULL::')) {
$returnValue = null;
} else {
$returnValue = str_replace("\\'", "'", preg_replace('/\'(.*)\'(::(?:character\\svarying|varchar|character|char|text)(?:\\(\\d+\\))?)?\\z/', '\\1', $fieldDefinition['default_value']));
}
} elseif (substr($fieldDefinition['type'], 0, 3) === 'int') {
$returnValue = (int) preg_replace('/^\\(?(\\-?\\d+)\\)?$/', '\\1', $fieldDefinition['default_value']);
} else {
$returnValue = $fieldDefinition['default_value'];
}
return $returnValue;
}
示例8: decryptDataArray
/**
* @param array $data
* @return array
*/
protected function decryptDataArray(array $data)
{
foreach ($data as $key => $value) {
if (empty($value)) {
continue;
}
if (is_array($value)) {
$data[$key] = $this->decryptDataArray($value);
continue;
}
if (!StringUtility::beginsWith($value, 'rsa:')) {
continue;
}
$decryptedValue = $this->getBackend()->decrypt($this->getKey(), substr($value, 4));
if ($decryptedValue !== null) {
$data[$key] = $decryptedValue;
}
}
return $data;
}
示例9: addData
/**
* Determine which fields are required to render the placeholders and
* add those to the list of columns that must be processed by the next
* data providers.
*
* @param array $result
* @return array
*/
public function addData(array $result)
{
foreach ($result['processedTca']['columns'] as $fieldName => $fieldConfig) {
// Placeholders are only valid for input and text type fields
if ($fieldConfig['config']['type'] !== 'input' && $fieldConfig['config']['type'] !== 'text' || !isset($fieldConfig['config']['placeholder'])) {
continue;
}
// Process __row|field type placeholders
if (StringUtility::beginsWith($fieldConfig['config']['placeholder'], '__row|')) {
// split field names into array and remove the __row indicator
$fieldNameArray = array_slice(GeneralUtility::trimExplode('|', $fieldConfig['config']['placeholder'], true), 1);
// only the first field is required to be processed as it's the one referring to
// the current record. All other columns will be resolved in a later pass through
// the related records.
if (!empty($fieldNameArray[0])) {
$result['columnsToProcess'][] = $fieldNameArray[0];
}
}
}
return $result;
}
示例10: process
/**
* Generates the JumpURL for the given parameters.
*
* @see \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::processUrlModifiers()
* @param string $context The context in which the URL is generated (e.g. "typolink").
* @param string $url The URL that should be processed.
* @param array $configuration The link configuration.
* @param \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObjectRenderer The calling content object renderer.
* @param bool $keepProcessing If this is set to FALSE no further hooks will be processed after the current one.
* @return string
*/
public function process($context, $url, array $configuration, ContentObjectRenderer $contentObjectRenderer, &$keepProcessing)
{
if (!$this->isEnabled($context, $configuration)) {
return $url;
}
$this->contentObjectRenderer = $contentObjectRenderer;
// Strip the absRefPrefix from the URLs.
$urlPrefix = (string) $this->getTypoScriptFrontendController()->absRefPrefix;
if ($urlPrefix !== '' && StringUtility::beginsWith($url, $urlPrefix)) {
$url = substr($url, strlen($urlPrefix));
}
// Make sure the slashes in the file URL are not encoded.
if ($context === UrlProcessorInterface::CONTEXT_FILE) {
$url = str_replace('%2F', '/', rawurlencode(rawurldecode($url)));
}
$url = $this->build($url, isset($configuration['jumpurl.']) ? $configuration['jumpurl.'] : array());
// Now add the prefix again if it was not added by a typolink call already.
if ($urlPrefix !== '' && !StringUtility::beginsWith($url, $urlPrefix)) {
$url = $urlPrefix . $url;
}
return $url;
}
示例11: processDatamap_afterDatabaseOperations
/**
* @param string $status
* @param string $table
* @param int $id
* @param array $fieldArray
* @param DataHandler $parentObject
*/
public function processDatamap_afterDatabaseOperations($status, $table, $id, $fieldArray, $parentObject)
{
if ($table !== 'be_groups' || $GLOBALS['TYPO3_CONF_VARS']['BE']['explicitADmode'] !== 'explicitAllow') {
return;
}
$backendUserGroup = BackendUtility::getRecord($table, $id, 'explicit_allowdeny');
$explicitAllowDenyFields = GeneralUtility::trimExplode(',', $backendUserGroup['explicit_allowdeny']);
foreach ($explicitAllowDenyFields as $value) {
if (StringUtility::beginsWith($value, 'tt_content:list_type:')) {
if (!in_array('tt_content:CType:list:ALLOW', $explicitAllowDenyFields, true)) {
/** @var $flashMessage FlashMessage */
$flashMessage = GeneralUtility::makeInstance(FlashMessage::class, $this->getLanguageService()->sl('LLL:EXT:lang/locallang_core.xlf:error.backendUserGroupListTypeError.message'), $this->getLanguageService()->sl('LLL:EXT:lang/locallang_core.xlf:error.backendUserGroupListTypeError.header'), FlashMessage::WARNING, true);
/** @var $flashMessageService FlashMessageService */
$flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
/** @var $defaultFlashMessageQueue FlashMessageQueue */
$defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
$defaultFlashMessageQueue->enqueue($flashMessage);
}
return;
}
}
}
示例12: canHandleLink
/**
* Checks if this is the handler for the given link
*
* The handler may store this information locally for later usage.
*
* @param array $linkParts Link parts as returned from TypoLinkCodecService
*
* @return bool
*/
public function canHandleLink(array $linkParts)
{
if (!$linkParts['url']) {
return false;
}
$url = rawurldecode($linkParts['url']);
if (StringUtility::beginsWith($url, 'file:') && !StringUtility::beginsWith($url, 'file://')) {
$rel = substr($url, 5);
try {
// resolve FAL-api "file:UID-of-sys_file-record" and "file:combined-identifier"
$fileOrFolderObject = ResourceFactory::getInstance()->retrieveFileOrFolderObject($rel);
if (is_a($fileOrFolderObject, $this->expectedClass)) {
$this->linkParts = $linkParts;
$this->linkParts['url'] = $rel;
$this->linkParts['name'] = $fileOrFolderObject->getName();
return true;
}
} catch (FileDoesNotExistException $e) {
}
}
return false;
}
示例13: isInCurrentDomain
/**
* Determines whether the URL is on the current host and belongs to the
* current TYPO3 installation. The scheme part is ignored in the comparison.
*
* @param string $url URL to be checked
* @return bool Whether the URL belongs to the current TYPO3 installation
*/
protected function isInCurrentDomain($url)
{
$urlWithoutSchema = preg_replace('#^https?://#', '', $url);
$siteUrlWithoutSchema = preg_replace('#^https?://#', '', GeneralUtility::getIndpEnv('TYPO3_SITE_URL'));
return StringUtility::beginsWith($urlWithoutSchema . '/', GeneralUtility::getIndpEnv('HTTP_HOST') . '/') && StringUtility::beginsWith($urlWithoutSchema, $siteUrlWithoutSchema);
}
示例14: resolveMixedLinkParameter
/**
* called from the typoLink() function
*
* does the magic to split the full "typolink" string like "15,13 _blank myclass &more=1"
* into separate parts
*
* @param string $linkText The string (text) to link
* @param string $mixedLinkParameter destination data like "15,13 _blank myclass &more=1" used to create the link
* @param array $configuration TypoScript configuration
* @return array | string
* @see typoLink()
*/
protected function resolveMixedLinkParameter($linkText, $mixedLinkParameter, &$configuration = array())
{
$linkParameter = null;
// Link parameter value = first part
$linkParameterParts = GeneralUtility::makeInstance(TypoLinkCodecService::class)->decode($mixedLinkParameter);
// Check for link-handler keyword:
list($linkHandlerKeyword, $linkHandlerValue) = explode(':', $linkParameterParts['url'], 2);
if ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['typolinkLinkHandler'][$linkHandlerKeyword] && (string) $linkHandlerValue !== '') {
$linkHandlerObj = GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['typolinkLinkHandler'][$linkHandlerKeyword]);
if (method_exists($linkHandlerObj, 'main')) {
return $linkHandlerObj->main($linkText, $configuration, $linkHandlerKeyword, $linkHandlerValue, $mixedLinkParameter, $this);
}
}
// Resolve FAL-api "file:UID-of-sys_file-record" and "file:combined-identifier"
if ($linkHandlerKeyword === 'file' && !StringUtility::beginsWith($linkParameterParts['url'], 'file://')) {
try {
$fileOrFolderObject = $this->getResourceFactory()->retrieveFileOrFolderObject($linkHandlerValue);
// Link to a folder or file
if ($fileOrFolderObject instanceof File || $fileOrFolderObject instanceof Folder) {
$linkParameter = $fileOrFolderObject->getPublicUrl();
} else {
$linkParameter = null;
}
} catch (\RuntimeException $e) {
// Element wasn't found
$linkParameter = null;
} catch (ResourceDoesNotExistException $e) {
// Resource was not found
return $linkText;
}
// Disallow direct javascript: links
} elseif (strtolower(trim($linkHandlerKeyword)) === 'javascript') {
return $linkText;
} else {
$linkParameter = $linkParameterParts['url'];
}
// additional parameters that need to be set
if ($linkParameterParts['additionalParams'] !== '') {
$forceParams = $linkParameterParts['additionalParams'];
// params value
$configuration['additionalParams'] .= $forceParams[0] === '&' ? $forceParams : '&' . $forceParams;
}
return array('href' => $linkParameter, 'target' => $linkParameterParts['target'], 'class' => $linkParameterParts['class'], 'title' => $linkParameterParts['title']);
}
示例15: changeFunc
/**
* Detects if a control button (up/down/around/delete) has been pressed for an item and accordingly it will
* manipulate the internal TABLECFG array
*
* @return void
* @internal
*/
public function changeFunc()
{
if ($this->TABLECFG['col_remove']) {
$kk = key($this->TABLECFG['col_remove']);
$cmd = 'col_remove';
} elseif ($this->TABLECFG['col_add']) {
$kk = key($this->TABLECFG['col_add']);
$cmd = 'col_add';
} elseif ($this->TABLECFG['col_start']) {
$kk = key($this->TABLECFG['col_start']);
$cmd = 'col_start';
} elseif ($this->TABLECFG['col_end']) {
$kk = key($this->TABLECFG['col_end']);
$cmd = 'col_end';
} elseif ($this->TABLECFG['col_left']) {
$kk = key($this->TABLECFG['col_left']);
$cmd = 'col_left';
} elseif ($this->TABLECFG['col_right']) {
$kk = key($this->TABLECFG['col_right']);
$cmd = 'col_right';
} elseif ($this->TABLECFG['row_remove']) {
$kk = key($this->TABLECFG['row_remove']);
$cmd = 'row_remove';
} elseif ($this->TABLECFG['row_add']) {
$kk = key($this->TABLECFG['row_add']);
$cmd = 'row_add';
} elseif ($this->TABLECFG['row_top']) {
$kk = key($this->TABLECFG['row_top']);
$cmd = 'row_top';
} elseif ($this->TABLECFG['row_bottom']) {
$kk = key($this->TABLECFG['row_bottom']);
$cmd = 'row_bottom';
} elseif ($this->TABLECFG['row_up']) {
$kk = key($this->TABLECFG['row_up']);
$cmd = 'row_up';
} elseif ($this->TABLECFG['row_down']) {
$kk = key($this->TABLECFG['row_down']);
$cmd = 'row_down';
} else {
$kk = '';
$cmd = '';
}
if ($cmd && MathUtility::canBeInterpretedAsInteger($kk)) {
if (StringUtility::beginsWith($cmd, 'row_')) {
switch ($cmd) {
case 'row_remove':
unset($this->TABLECFG['c'][$kk]);
break;
case 'row_add':
for ($a = 1; $a <= $this->numNewRows; $a++) {
// Checking if set: The point is that any new row between existing rows
// will be TRUE after one row is added while if rows are added in the bottom
// of the table there will be no existing rows to stop the addition of new rows
// which means it will add up to $this->numNewRows rows then.
if (!isset($this->TABLECFG['c'][$kk + $a])) {
$this->TABLECFG['c'][$kk + $a] = array();
} else {
break;
}
}
break;
case 'row_top':
$this->TABLECFG['c'][1] = $this->TABLECFG['c'][$kk];
unset($this->TABLECFG['c'][$kk]);
break;
case 'row_bottom':
$this->TABLECFG['c'][10000000] = $this->TABLECFG['c'][$kk];
unset($this->TABLECFG['c'][$kk]);
break;
case 'row_up':
$this->TABLECFG['c'][$kk - 3] = $this->TABLECFG['c'][$kk];
unset($this->TABLECFG['c'][$kk]);
break;
case 'row_down':
$this->TABLECFG['c'][$kk + 3] = $this->TABLECFG['c'][$kk];
unset($this->TABLECFG['c'][$kk]);
break;
}
ksort($this->TABLECFG['c']);
}
if (StringUtility::beginsWith($cmd, 'col_')) {
foreach ($this->TABLECFG['c'] as $cAK => $value) {
switch ($cmd) {
case 'col_remove':
unset($this->TABLECFG['c'][$cAK][$kk]);
break;
case 'col_add':
$this->TABLECFG['c'][$cAK][$kk + 1] = '';
break;
case 'col_start':
$this->TABLECFG['c'][$cAK][1] = $this->TABLECFG['c'][$cAK][$kk];
unset($this->TABLECFG['c'][$cAK][$kk]);
break;
//.........这里部分代码省略.........