本文整理汇总了PHP中StringUtil::startsWith方法的典型用法代码示例。如果您正苦于以下问题:PHP StringUtil::startsWith方法的具体用法?PHP StringUtil::startsWith怎么用?PHP StringUtil::startsWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringUtil
的用法示例。
在下文中一共展示了StringUtil::startsWith方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renderFile
public function renderFile()
{
header("Content-Type: application/json;charset=utf-8");
$aRequest = array();
$sContentType = 'application/x-www-form-urlencoded';
if (isset($_SERVER['CONTENT_TYPE'])) {
$sContentType = $_SERVER['CONTENT_TYPE'];
}
if (isset($_SERVER['HTTP_CONTENT_TYPE'])) {
$sContentType = $_SERVER['HTTP_CONTENT_TYPE'];
}
if (StringUtil::startsWith($sContentType, 'application/json')) {
$aRequest = json_decode(file_get_contents('php://input'), true);
} else {
foreach ($_REQUEST as $sKey => $sValue) {
$aRequest[$sKey] = json_decode($sValue, true);
}
}
$oSession = Session::getSession();
if (!isset($aRequest['session_language']) && $oSession->isAuthenticated()) {
$aRequest['session_language'] = $oSession->getUser()->getLanguageId();
}
$sPrevSessionLanguage = null;
$sSetSessionLanguage = null;
if (isset($aRequest['session_language'])) {
$sPrevSessionLanguage = Session::language();
$sSetSessionLanguage = $aRequest['session_language'];
$oSession->setLanguage($sSetSessionLanguage);
}
try {
try {
$mJSONData = $this->getJSON($aRequest);
$sResult = json_encode($mJSONData);
$iError = json_last_error();
if ($iError !== JSON_ERROR_NONE) {
throw new LocalizedException('wns.error.json', array('json_error' => $iError, 'json_error_message' => self::$JSON_ERRORS[$iError]));
}
print $sResult;
} catch (Exception $e) {
//Handle the gift, not the wrapping…
if ($e->getPrevious()) {
throw $e->getPrevious();
} else {
throw $e;
}
}
} catch (LocalizedException $ex) {
LinkUtil::sendHTTPStatusCode(500, 'Server Error');
print json_encode(array('exception' => array('message' => $ex->getLocalizedMessage(), 'code' => $ex->getCode(), 'file' => $ex->getFile(), 'line' => $ex->getLine(), 'trace' => $ex->getTrace(), 'parameters' => $ex->getMessageParameters(), 'exception_type' => $ex->getExceptionType())));
} catch (Exception $ex) {
LinkUtil::sendHTTPStatusCode(500, 'Server Error');
ErrorHandler::handleException($ex, true);
print json_encode(array('exception' => array('message' => "Exception when trying to execute the last action {$ex->getMessage()}", 'code' => $ex->getCode(), 'file' => $ex->getFile(), 'line' => $ex->getLine(), 'trace' => $ex->getTrace(), 'exception_type' => get_class($ex))));
}
//If we changed the session language and no widget willfully changed it as well, reset it to the previous state
if ($sPrevSessionLanguage !== null && Session::language() === $sSetSessionLanguage) {
$oSession->setLanguage($sPrevSessionLanguage);
}
}
示例2: __call
public function __call($sMethodName, $aParameters)
{
//Event name
if (!StringUtil::startsWith($sMethodName, 'handle')) {
return 0;
}
$sEventName = substr($sMethodName, strlen('handle'));
return $this->doHandleEvent($sEventName, $aParameters);
}
示例3: prepareUrlForCurl
public static function prepareUrlForCurl($url)
{
$url = StringUtil::startsWith($url, '//') ? 'http:' . $url : $url;
// URL encode based of MDN spec
// http://stackoverflow.com/a/19858404
return preg_replace_callback("{[^0-9a-z_.!~*'();,/?:@&=+\$#]}i", function ($m) {
return sprintf('%%%02X', ord($m[0]));
}, $url);
}
示例4: onRichtextWriteTagForIdentifier
public function onRichtextWriteTagForIdentifier($sTagName, $aParameters, $oIdentifier, $sTagContent, $oLink)
{
if (Manager::getCurrentManager() instanceof BackendManager || $oIdentifier->getName() !== 'external_link' || !StringUtil::startsWith($aParameters[0]['href'], 'subs://') || !$oLink instanceof Link) {
return;
}
$aParameters[0]['href'] = EXT_WEB_DIR_FE . '/' . substr($aParameters[0]['href'], strlen('subs://'));
$aParameters[0]['class'] = 'internal_link subsite';
$aParameters[0]['rel'] = 'internal';
}
示例5: suite
public static function suite()
{
$oResult = new PHPUnit_Framework_TestSuite("ResourceFinder test suite");
foreach (ResourceFinder::getFolderContents(dirname(__FILE__)) as $sFileName => $sFilePath) {
if (StringUtil::endsWith($sFileName, "Tests.php") && (StringUtil::startsWith($sFileName, "ResourceFinder") || StringUtil::startsWith($sFileName, "FileResource") || StringUtil::startsWith($sFileName, "ResourceIncluder"))) {
$oResult->addTestFile($sFilePath);
}
}
return $oResult;
}
示例6: suite
public static function suite()
{
$oResult = new PHPUnit_Framework_TestSuite("Complete test suite");
foreach (ResourceFinder::getFolderContents(dirname(__FILE__)) as $sFileName => $sFilePath) {
if (StringUtil::endsWith($sFileName, ".php") && StringUtil::startsWith($sFileName, "Test") && !StringUtil::startsWith($sFileName, "TestUtil") && $sFilePath !== __FILE__) {
require_once $sFilePath;
$oResult->addTest(call_user_func(array(substr($sFileName, 0, -strlen('.php')), "suite")));
}
}
return $oResult;
}
示例7: processCSSContent
public static function processCSSContent($sContent, $oFile)
{
$oCache = new Cache('preview_css' . $oFile->getInternalPath(), DIRNAME_TEMPLATES);
header("Content-Type: text/css;charset=" . Settings::getSetting('encoding', 'browser', 'utf-8'));
if ($oCache->entryExists() && !$oCache->isOutdated($oFile->getFullPath())) {
$oCache->sendCacheControlHeaders();
$oCache->passContents();
exit;
}
$oParser = new Sabberworm\CSS\Parser($sContent, Sabberworm\CSS\Settings::create()->withDefaultCharset(Settings::getSetting('encoding', 'browser', 'utf-8')));
$oCssContents = $oParser->parse();
//Make all rules important
// foreach($oCssContents->getAllRuleSets() as $oCssRuleSet) {
// foreach($oCssRuleSet->getRules() as $oRule) {
// $oRule->setIsImportant(true);
// }
// }
//Multiply all rules and prepend specific strings
$aPrependages = array('#rapila_admin_menu', '.filled-container.editing', '.ui-dialog', '.cke_dialog_contents', '#widget-notifications', '.cke_reset', 'body > .cke_reset_all', '.tag_panel');
foreach ($oCssContents->getAllDeclarationBlocks() as $oBlock) {
$aNewSelector = array();
foreach ($oBlock->getSelectors() as $iKey => $oSelector) {
$sSelector = $oSelector->getSelector();
if (StringUtil::startsWith($sSelector, "body ") || StringUtil::startsWith($sSelector, "html ")) {
$aNewSelector[] = $sSelector;
} else {
foreach ($aPrependages as $sPrependage) {
if (StringUtil::startsWith($sSelector, "{$sPrependage} ") || StringUtil::startsWith($sSelector, "{$sPrependage}.") || $sSelector === $sPrependage) {
$aNewSelector[] = $sSelector;
} else {
$aNewSelector[] = "{$sPrependage} {$sSelector}";
}
}
}
}
$oBlock->setSelector($aNewSelector);
}
//Absolutize all URLs
foreach ($oCssContents->getAllValues() as $oValue) {
if ($oValue instanceof Sabberworm\CSS\Value\URL) {
$sURL = $oValue->getURL()->getString();
if (!StringUtil::startsWith($sURL, '/') && !preg_match('/^\\w+:/', $sURL)) {
$sURL = $oFile->getFrontendDirectoryPath() . DIRECTORY_SEPARATOR . $sURL;
}
$oValue->setURL(new Sabberworm\CSS\Value\CSSString($sURL));
}
}
$sContents = $oCssContents->render(Sabberworm\CSS\OutputFormat::createCompact());
$oCache->setContents($sContents);
$oCache->sendCacheControlHeaders();
print $sContents;
}
示例8: createMethodGetter
private function createMethodGetter($methodName, $isSpecialColumn = false)
{
if (StringUtil::startsWith($methodName, $this->formatMethodPrefix)) {
$conversion = null;
} else {
$formatMethod = preg_replace('/^get/', $this->formatMethodPrefix, $methodName, 1);
if (method_exists($this->class, $formatMethod)) {
$methodName = $formatMethod;
$conversion = null;
} else {
$conversion = $this->formatConversion;
}
}
return new afMethodGetter($methodName, $conversion, $isSpecialColumn);
}
示例9: getMissingRights
public function getMissingRights($mPage, $bInheritedOnly = false)
{
$oRightMethods = get_class_methods("Right");
$aResult = array();
foreach ($oRightMethods as $iKey => $sRightMethodName) {
if (!StringUtil::startsWith($sRightMethodName, 'getMay')) {
continue;
}
$sRightName = substr($sRightMethodName, strlen('getMay'));
if (!$this->may($mPage, $sRightName, $bInheritedOnly)) {
$aResult[] = $sRightName;
}
}
return $aResult;
}
示例10: __call
public function __call($sMethodName, $aArguments)
{
if ($this->aFilterTypes !== null && StringUtil::startsWith($sMethodName, 'set') && $sMethodName[3] === strtoupper($sMethodName[3])) {
$sFilterColumn = StringUtil::deCamelize(lcfirst(substr($sMethodName, 3)));
if ($this->filterTypeForColumn($sFilterColumn) !== null) {
return $this->oListSettings->setFilterColumnValue($sFilterColumn, $aArguments[0]);
}
}
if ($this->aFilterTypes !== null && StringUtil::startsWith($sMethodName, 'get') && $sMethodName[3] === strtoupper($sMethodName[3])) {
$sFilterColumn = StringUtil::deCamelize(lcfirst(substr($sMethodName, 3)));
if ($this->filterTypeForColumn($sFilterColumn) !== null) {
return $this->oListSettings->getFilterColumnValue($sFilterColumn);
}
}
return call_user_func_array(array($this->oCriteriaDelegate, $sMethodName), $aArguments);
}
示例11: getResourceIncluderContents
public static function getResourceIncluderContents($oIncluder)
{
$sContents = '';
foreach ($oIncluder->getResourceInfosForIncludedResourcesOfPriority() as $aInfo) {
if (isset($aInfo['file_resource'])) {
$sContents .= file_get_contents($aInfo['file_resource']->getFullPath());
} else {
$sLocation = $aInfo['location'];
if (StringUtil::startsWith($sLocation, '//')) {
$sLocation = 'http:' . $sLocation;
}
$sContents .= file_get_contents($sLocation);
}
}
return $sContents;
}
示例12: setConnectionCharset
public function setConnectionCharset($sAdapter, $sCharset, PDOConnection $oConnection = null)
{
if ($oConnection === null) {
$oConnection = Propel::getConnection();
}
$sCharset = self::convertEncodingNameToSql($sCharset);
if (StringUtil::startsWith($sAdapter, 'mysql')) {
$sAdapter = 'mysql';
}
$sFile = ResourceFinder::create(array('data', 'sql', 'charset', "{$sAdapter}.dump"))->find();
if ($sFile === null) {
return;
}
$sCharsetCode = file_get_contents($sFile);
$sCharsetCode = str_replace('{{charset}}', $sCharset, $sCharsetCode);
$oConnection->exec($sCharsetCode);
}
示例13: loadFromBackup
public function loadFromBackup($sFileName = null)
{
$sFilePath = ResourceFinder::findResource(array(DIRNAME_DATA, 'sql', $sFileName));
$oConnection = Propel::getConnection();
$bFileError = false;
if ($sFilePath === null) {
$bFileError = true;
}
if (!$bFileError) {
if (!is_readable($sFilePath)) {
$bFileError = true;
}
if (!$bFileError) {
$rFile = fopen($sFilePath, 'r');
if (!$rFile) {
$bFileError = true;
}
}
}
// throw error and filename on error
if ($bFileError) {
throw new LocalizedException('wns.backup.loader.load_error', array('filename' => $sFilePath));
}
// continue importing from local file
$sStatement = "";
$sReadLine = "";
$iQueryCount = 1;
while (($sReadLine = fgets($rFile)) !== false) {
if ($sReadLine !== "\n" && !StringUtil::startsWith($sReadLine, "#") && !StringUtil::startsWith($sReadLine, "--")) {
$sStatement .= $sReadLine;
}
if ($sReadLine === "\n" || StringUtil::endsWith($sReadLine, ";\n")) {
if (trim($sStatement) !== "") {
$oConnection->exec($sStatement);
$iQueryCount++;
}
$sStatement = "";
}
}
if (trim($sStatement) !== "") {
$oConnection->exec($sStatement);
}
Cache::clearAllCaches();
return $iQueryCount;
}
示例14: redirect
/**
* Redirects (locally by default).
* Use with LinkUtil::link()ed URLs (because this redirect does not add the base path/context MAIN_DIR_FE).
* Discards all buffered output and exits
* Pass $sHost = false to mark $sLocation as absolute URL
*/
public static function redirect($sLocation, $sHost = null, $sProtocol = 'default', $bPermanent = true)
{
while (ob_get_level() > 0) {
ob_end_clean();
}
if ($bPermanent) {
self::sendHTTPStatusCode(301, "Moved Permanently");
} else {
self::sendHTTPStatusCode(302, "Found");
}
if ($sHost !== false) {
$sLocation = self::absoluteLink($sLocation, $sHost, $sProtocol);
}
if (StringUtil::startsWith($sLocation, '//')) {
$sLocation = (self::isSSL() ? 'https:' : 'http:') . $sLocation;
}
$sRedirectString = "Location: {$sLocation}";
header($sRedirectString);
exit;
}
示例15: getCustomMethods
public static function getCustomMethods()
{
$aMethods = array();
$aStaticMethods = array();
$oSuperClass = new ReflectionClass('WidgetModule');
$oClass = new ReflectionClass(get_called_class());
foreach ($oClass->getMethods(ReflectionMethod::IS_PUBLIC) as $oMethod) {
if (StringUtil::startsWith($oMethod->getName(), '__')) {
continue;
}
if ($oSuperClass->hasMethod($oMethod->getName())) {
continue;
}
if ($oMethod->isStatic()) {
$aStaticMethods[] = $oMethod->getName();
} else {
$aMethods[] = $oMethod->getName();
}
}
$aMethods[] = 'getInputName';
$aMethods[] = 'setInputName';
return array('static' => $aStaticMethods, 'instance' => $aMethods);
}