本文整理汇总了PHP中StringUtils::endsWith方法的典型用法代码示例。如果您正苦于以下问题:PHP StringUtils::endsWith方法的具体用法?PHP StringUtils::endsWith怎么用?PHP StringUtils::endsWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringUtils
的用法示例。
在下文中一共展示了StringUtils::endsWith方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testEndsWith
/**
* Test for Schwaen\Stdlib\StringUtils::endsWith
*/
public function testEndsWith()
{
$this->assertEquals(false, StringUtils::endsWith('Hallo Welt', 'welt'));
$this->assertEquals(true, StringUtils::endsWith('Hallo Welt', 'Welt'));
$this->assertEquals(false, StringUtils::endsWith('Hallo Welt', 'Test'));
$this->assertEquals(true, StringUtils::endsWith('Hallo Welt', ''));
}
示例2: extractMainDomainFromUrl
/**
* Extract the domain from a url
*
* @param string $url
*
* @return string
*/
public static function extractMainDomainFromUrl($url)
{
$matchesMainDomain = null;
$hostString = self::urlToString($url);
$pattern = '/[^.]+\\.[^.]+$/';
foreach (self::$excludedTld as $extension) {
if (StringUtils::endsWith($hostString, $extension)) {
$pattern = sprintf('/.*\\.(.*%s)/', str_replace('.', '\\.', $extension));
break;
}
}
preg_match($pattern, $hostString, $matchesMainDomain);
$mainDomain = array_pop($matchesMainDomain);
return $mainDomain;
}
示例3: processAspects
/**
* Adds all the plugin's aspects
*
* @param Plugin $plugin The plugin to analyze
* @param string &$log A variable that will get logging detail appended
*
* @return void
*/
public function processAspects(Plugin $plugin, &$log = '')
{
$anyChanged = false;
$processedSlugs = array();
$pluginPath = $plugin->Path;
$aspectsPath = $pluginPath . '/aspects';
if (file_exists($aspectsPath)) {
$iter = new DirectoryIterator($aspectsPath);
foreach ($iter as $aspectFile) {
if ($aspectFile->isFile() && StringUtils::endsWith($aspectFile->getBasename(), '.xml')) {
$aspectSlug = $aspectFile->getBasename(".xml");
try {
$log .= "Processing aspect descriptor: {$aspectFile->getBasename()}\n";
$ts = $this->DateFactory->newLocalDate(filemtime($aspectFile->getPathname()));
$md5 = md5_file($aspectFile->getPathname());
if ($this->AspectService->slugExists($aspectSlug)) {
$aspect = $this->AspectService->getBySlug($aspectSlug);
if ($aspect->Md5 !== $md5) {
$aspectXML = $this->SimpleXMLParser->parseXMLFile($aspectFile->getPathname());
if ($aspectXML == false) {
throw new Exception('Unable to load aspect XML [' . $aspectFile->getPathname() . ']');
}
$aspect = $this->SystemXMLConverter->xmlToAspect($aspect, $aspectXML);
if ($aspect->PluginID != $plugin->PluginID) {
throw new Exception('Aspect installed by another plugin: ' . $aspect->Slug);
}
$aspect->ModifiedDate = $ts;
$aspect->Md5 = $md5;
$log .= "Aspect updated...\n";
$this->AspectService->edit($aspect);
$anyChanged = true;
}
} else {
$aspectXML = $this->SimpleXMLParser->parseXMLFile($aspectFile->getPathname());
if ($aspectXML == false) {
throw new Exception('Unable to load aspect XML [' . $aspectFile->getPathname() . ']');
}
$aspect = new Aspect();
$this->ModelMapper->defaultsOnModel($aspect);
$aspect = $this->SystemXMLConverter->xmlToAspect($aspect, $aspectXML);
$aspect->Slug = $aspectSlug;
$aspect->PluginID = $plugin->PluginID;
$aspect->ModifiedDate = $ts;
$aspect->Md5 = $md5;
$log .= "Aspect created...\n";
$this->AspectService->add($aspect);
$anyChanged = true;
}
// resolve schema
if ($aspect->getXMLSchema() != "") {
$schemaXML = "<?xml version='1.0'?><schema>";
$schemaXML .= preg_replace('/\\<\\?xml([^\\>\\/]*)\\>/', '', $aspect->getXMLSchema());
$schemaXML .= "</schema>";
try {
$this->NodeSchemaParser->parse($schemaXML);
} catch (Exception $e) {
throw new SchemaException("Unable to parse schema for aspect [{$aspect->Slug}]:\n " . $e->getMessage());
}
}
$this->AspectService->getBySlug($aspect->Slug);
$log .= "ID: {$aspect->AspectID}\n";
$log .= "Slug: {$aspect->Slug}\n";
$log .= "Name: {$aspect->Name}\n";
$log .= "Description: {$aspect->Description}\n";
$log .= "Md5: {$aspect->Md5}\n";
$log .= "\n";
} catch (ValidationException $ve) {
throw new Exception('Aspect [' . $aspectSlug . ']: ' . $ve->getMessage());
}
$processedSlugs[] = $aspectSlug;
}
}
}
if ($plugin->PluginID == '') {
return $anyChanged;
}
$existing = $this->AspectService->findAll(new DTO(array('PluginID' => $plugin->PluginID)))->getResults();
foreach ($existing as $e) {
if (!in_array($e->Slug, $processedSlugs)) {
$this->AspectService->delete($e->Slug);
}
}
return $anyChanged;
}
示例4: _importPhotosFromDir
protected function _importPhotosFromDir($dir)
{
$h = opendir($dir);
while (($fname = readdir($h)) !== FALSE) {
if (StringUtils::endsWith(strtolower($fname), '.jpg')) {
try {
echo "importing {$fname}...";
$nodeRef = $this->NodeRefService->oneFromAspect('@images');
$nodeRef = $this->NodeRefService->generateNodeRef($nodeRef, $fname);
$node = $nodeRef->generateNode();
$node->Title = $fname;
$node->Status = "published";
$node->ActiveDate = $this->DateFactory->newStorageDate();
$node = $this->ImageService->storeMedia(rtrim($dir, '/') . '/' . $fname, $node);
$this->NodeService->add($node);
echo "done\n";
unset($nodeRef);
unset($node);
} catch (Exception $e) {
echo "Exception: " . $e->getMessage() . "\n";
}
}
}
closedir($h);
}