本文整理汇总了PHP中strcasecmp函数的典型用法代码示例。如果您正苦于以下问题:PHP strcasecmp函数的具体用法?PHP strcasecmp怎么用?PHP strcasecmp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了strcasecmp函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: unmarshalFrom
/**
* Unmarshal return value from a specified node
*
* @param xml.Node node
* @return webservices.uddi.BusinessList
* @see xp://webservices.uddi.UDDICommand#unmarshalFrom
* @throws lang.FormatException in case of an unexpected response
*/
public function unmarshalFrom($node)
{
if (0 != strcasecmp($node->name, 'businessList')) {
throw new \lang\FormatException('Expected "businessList", got "' . $node->name . '"');
}
// Create business list object from XML representation
with($list = new BusinessList(), $children = $node->nodeAt(0)->getChildren());
$list->setOperator($node->getAttribute('operator'));
$list->setTruncated(0 == strcasecmp('true', $node->getAttribute('truncated')));
for ($i = 0, $s = sizeof($children); $i < $s; $i++) {
$b = new Business($children[$i]->getAttribute('businessKey'));
for ($j = 0, $t = sizeof($children[$i]->getChildren()); $j < $s; $j++) {
switch ($children[$i]->nodeAt($j)->name) {
case 'name':
$b->names[] = $children[$i]->nodeAt($j)->getContent();
break;
case 'description':
$b->description = $children[$i]->nodeAt($j)->getContent();
break;
}
}
$list->items[] = $b;
}
return $list;
}
开发者ID:treuter,项目名称:webservices,代码行数:33,代码来源:FindBusinessesCommand.class.php
示例2: getAllProjects
public function getAllProjects()
{
$key = "{$this->cachePrefix}-all-projects";
if ($this->cache && ($projects = $this->cache->fetch($key))) {
return $projects;
}
$first = json_decode($this->client->get('projects.json', ['query' => ['limit' => 100]])->getBody(), true);
$projects = $first['projects'];
if ($first['total_count'] > 100) {
$requests = [];
for ($i = 100; $i < $first['total_count']; $i += 100) {
$requests[] = $this->client->getAsync('projects.json', ['query' => ['limit' => 100, 'offset' => $i]]);
}
/** @var Response[] $responses */
$responses = Promise\unwrap($requests);
$responseProjects = array_map(function (Response $response) {
return json_decode($response->getBody(), true)['projects'];
}, $responses);
$responseProjects[] = $projects;
$projects = call_user_func_array('array_merge', $responseProjects);
}
usort($projects, function ($projectA, $projectB) {
return strcasecmp($projectA['name'], $projectB['name']);
});
$this->cache && $this->cache->save($key, $projects);
return $projects;
}
开发者ID:stelsvitya,项目名称:server-manager,代码行数:27,代码来源:Projects.php
示例3: getTableFieldList
protected function getTableFieldList($tableName)
{
$tableFieldList = array();
$factory = WebserviceField::fromArray($this->pearDB, array('tablename' => $tableName));
$dbTableFields = $factory->getTableFields();
foreach ($dbTableFields as $dbField) {
if ($dbField->primaryKey) {
if ($this->idColumn === null) {
$this->idColumn = $dbField->name;
} else {
throw new WebServiceException(WebServiceErrorCode::$UNKOWNENTITY, "Entity table with multi column primary key is not supported");
}
}
$field = $this->getFieldArrayFromDBField($dbField, $tableName);
$webserviceField = WebserviceField::fromArray($this->pearDB, $field);
$fieldDataType = $this->getFieldType($dbField, $tableName);
if ($fieldDataType === null) {
$fieldDataType = $this->getFieldDataTypeFromDBType($dbField->type);
}
$webserviceField->setFieldDataType($fieldDataType);
if (strcasecmp($fieldDataType, 'reference') === 0) {
$webserviceField->setReferenceList($this->getReferenceList($dbField, $tableName));
}
array_push($tableFieldList, $webserviceField);
}
return $tableFieldList;
}
开发者ID:Bergdahls,项目名称:YetiForceCRM,代码行数:27,代码来源:VtigerCRMActorMeta.php
示例4: call_elucidat
/**
* Makes an API request to elucidat
* @param $headers
* @param $fields
* @param $url
* @param $consumer_secret
* @return mixed
*/
function call_elucidat($headers, $fields, $method, $url, $consumer_secret)
{
//Build a signature
$headers['oauth_signature'] = build_signature($consumer_secret, array_merge($headers, $fields), $method, $url);
//Build OAuth headers
$auth_headers = 'Authorization:';
$auth_headers .= build_base_string($headers, ',');
//Build the request string
$fields_string = build_base_string($fields, '&');
//Set the headers
$header = array($auth_headers, 'Expect:');
// Create curl options
if (strcasecmp($method, "GET") == 0) {
$url .= '?' . $fields_string;
$options = array(CURLOPT_HTTPHEADER => $header, CURLOPT_HEADER => false, CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false);
} else {
$options = array(CURLOPT_HTTPHEADER => $header, CURLOPT_HEADER => false, CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_POST => count($fields), CURLOPT_POSTFIELDS => $fields_string);
}
//Init the request and set its params
$request = curl_init();
curl_setopt_array($request, $options);
//Make the request
$response = curl_exec($request);
$status = curl_getinfo($request, CURLINFO_HTTP_CODE);
curl_close($request);
return array('status' => $status, 'response' => json_decode($response, true));
}
开发者ID:elucidat,项目名称:website-integration-example,代码行数:35,代码来源:index.php
示例5: get_profile_url
function get_profile_url($html)
{
$profiles = array();
$keys = array();
$doc = new \DOMDocument();
$html = "<html><head> <title> test </title> </head> <body> " . $html . "</body> </html>";
@$doc->loadHTML($html);
$links = $doc->getElementsByTagName("a");
$length = $links->length;
if ($length <= 0) {
return $profiles;
}
for ($i = 0; $i < $length; $i++) {
//individual link node
$link = $links->item($i);
$href = $link->getAttribute("href");
//does the link href end in profile?
$pos = strrpos($href, "/");
if ($pos !== false) {
$token = substr($href, $pos + 1);
if (strcasecmp($token, "profile") == 0) {
$key = md5($href);
//avoid duplicates!
if (!in_array($key, $keys)) {
array_push($profiles, $href);
array_push($keys, $key);
}
}
}
}
return $profiles;
}
开发者ID:rjha,项目名称:sc,代码行数:32,代码来源:curl-search.php
示例6: strtoupper
function &getTransport($url, $encoding = SOAP_DEFAULT_ENCODING)
{
$urlparts = @parse_url($url);
if (!$urlparts['scheme']) {
return SOAP_Base_Object::_raiseSoapFault("Invalid transport URI: {$url}");
}
if (strcasecmp($urlparts['scheme'], 'mailto') == 0) {
$transport_type = 'SMTP';
} else {
if (strcasecmp($urlparts['scheme'], 'https') == 0) {
$transport_type = 'HTTP';
} else {
/* handle other transport types */
$transport_type = strtoupper($urlparts['scheme']);
}
}
$transport_include = 'SOAP/Transport/' . $transport_type . '.php';
$res = @(include_once $transport_include);
if (!$res && !in_array($transport_include, get_included_files())) {
return SOAP_Base_Object::_raiseSoapFault("No Transport for {$urlparts['scheme']}");
}
$transport_class = "SOAP_Transport_{$transport_type}";
if (!class_exists($transport_class)) {
return SOAP_Base_Object::_raiseSoapFault("No Transport class {$transport_class}");
}
return new $transport_class($url, $encoding);
}
开发者ID:ronaldoof,项目名称:geocloud2,代码行数:27,代码来源:Transport.php
示例7: requestForgotPassword
public function requestForgotPassword($request)
{
$request = new Vtiger_Request($request);
$adb = PearDatabase::getInstance();
$username = vtlib_purify($request->get('user_name'));
$result = $adb->pquery('select id,email1 from vtiger_users where user_name = ? ', array($username));
if ($adb->num_rows($result) > 0) {
$email = $adb->query_result($result, 0, 'email1');
}
if (strcasecmp($request->get('emailId'), $email) === 0) {
$userId = $adb->query_result($result, 0, 'id');
$time = time();
$options = array('handler_path' => 'modules/Users/handlers/ForgotPassword.php', 'handler_class' => 'Users_ForgotPassword_Handler', 'handler_function' => 'changePassword', 'handler_data' => array('username' => $username, 'email' => $email, 'time' => $time, 'hash' => md5($username . $time)));
$trackURL = Vtiger_ShortURL_Helper::generateURL($options);
$data = ['sysname' => 'UsersForgotPassword', 'to_email' => $email, 'module' => 'Users', 'record' => $userId, 'trackURL' => $trackURL];
$recordModel = Vtiger_Record_Model::getCleanInstance('OSSMailTemplates');
$status = $recordModel->sendMailFromTemplate($data);
$site_URL = vglobal('site_URL') . 'index.php?modules=Users&view=Login';
if ($status === 1) {
header('Location: ' . $site_URL . '&status=1');
} else {
header('Location: ' . $site_URL . '&statusError=1');
}
} else {
$site_URL = vglobal('site_URL') . 'index.php?modules=Users&view=Login';
header('Location: ' . $site_URL . '&fpError=1');
}
}
开发者ID:awflu,项目名称:YetiForceCRM,代码行数:28,代码来源:ForgotPassword.php
示例8: factory
/**
* Factory
*
* @param string $backend backend name
* @param array $backendOptions associative array of options for the corresponding backend constructor
* @return Zend_Memory_Manager
* @throws Zend_Memory_Exception
*/
public static function factory($backend, $backendOptions = array())
{
if (strcasecmp($backend, 'none') == 0) {
return new Zend_Memory_Manager();
}
// Look through available backendsand
// (that allows to specify it in any case)
$backendIsFound = false;
foreach (Zend_Cache::$standardBackends as $zendCacheBackend) {
if (strcasecmp($backend, $zendCacheBackend) == 0) {
$backend = $zendCacheBackend;
$backendIsFound = true;
break;
}
}
if (!$backendIsFound) {
// require_once 'Zend/Memory/Exception.php';
throw new Zend_Memory_Exception("Incorrect backend ({$backend})");
}
$backendClass = 'Zend_Cache_Backend_' . $backend;
// For perfs reasons, we do not use the Zend_Loader::loadClass() method
// (security controls are explicit)
// require_once str_replace('_', DIRECTORY_SEPARATOR, $backendClass) . '.php';
$backendObject = new $backendClass($backendOptions);
return new Zend_Memory_Manager($backendObject);
}
开发者ID:JaroslavRamba,项目名称:ex-facebook-bundle,代码行数:34,代码来源:Memory.php
示例9: validate
/**
* 最大値のチェックを行う
*
* @access public
* @param string $name フォームの名前
* @param mixed $var フォームの値
* @param array $params プラグインのパラメータ
* @return true: 成功 Ethna_Error: エラー
*/
public function validate($name, $var, $params)
{
$true = true;
$type = $this->getFormType($name);
if (isset($params['strmaxcompat']) == false || $this->isEmpty($var, $type)) {
return $true;
}
$ctl = $this->backend->getController();
$client_enc = $ctl->getClientEncoding();
if (mb_enabled() && (strcasecmp('EUC-JP', $client_enc) != 0 && strcasecmp('eucJP-win', $client_enc) != 0)) {
$var = mb_convert_encoding($var, 'EUC-JP', $client_enc);
}
if ($type == VAR_TYPE_STRING) {
$max_param = $params['strmaxcompat'];
if (strlen($var) > $max_param) {
if (isset($params['error'])) {
$msg = $params['error'];
} else {
$msg = _et('Please input less than %d full-size (%d half-size) characters to {form}.');
}
return Ethna::raiseNotice($msg, E_FORM_MAX_STRING, array(intval($max_param / 2), $max_param));
}
}
return $true;
}
开发者ID:t-f-m,项目名称:ethna,代码行数:34,代码来源:Strmaxcompat.php
示例10: simple_fields_uasort
function simple_fields_uasort($a, $b)
{
if ($a["name"] == $b["name"]) {
return 0;
}
return strcasecmp($a["name"], $b["name"]);
}
开发者ID:Savantos,项目名称:cow-theme,代码行数:7,代码来源:functions_admin.php
示例11: curl
public function curl($server = NULL, $parameters = array())
{
$response = false;
$start = microtime(true);
if ($server) {
$this->CI->curl->create($server);
$this->CI->curl->option('buffersize', 10);
$this->CI->curl->option('useragent', 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8 (.NET CLR 3.5.30729)');
$this->CI->curl->option('returntransfer', true);
$this->CI->curl->option('followlocation', true);
$this->CI->curl->option('connecttimeout', true);
$this->CI->curl->post($parameters);
$data = $this->CI->curl->execute();
$this->CI->response_time = round(microtime(true) - $start, 3) . " seconds";
if ($data !== false) {
if (strcasecmp(element('format', $parameters), 'json') == 0) {
$response = json_decode($data, true);
} else {
$response = $data;
}
$this->CI->notification->set_message('idol_server_response_success');
} else {
$this->CI->notification->set_error('idol_server_response_error');
}
$this->CI->curl->close();
} else {
$this->CI->notification->set_error('idol_server_response_noserverdefined');
}
return $response;
}
开发者ID:benznext,项目名称:CIDashboard,代码行数:30,代码来源:Api_lib.php
示例12: is_soap_fault
function is_soap_fault($obj)
{
if (!is_object($obj)) {
return false;
}
return strcasecmp(get_class($obj), 'soap_fault') === 0;
}
开发者ID:ajv,项目名称:Offline-Caching,代码行数:7,代码来源:soaplib.php
示例13: handle_md5
function handle_md5($string)
{
if (strcasecmp(substr($string, 0, 1), "0") == 0) {
$string = substr($string, 1);
}
return $string;
}
开发者ID:saharin94,项目名称:jcr_source,代码行数:7,代码来源:jcr_theme.php
示例14: getOptions
/**
* {@inheritdoc}
*/
public function getOptions($dataLocale, $collectionId = null, $search = '', array $options = [])
{
if (null === $collectionId) {
throw new \InvalidArgumentException('Please supply attribute id as collectionId');
}
$qb = $this->createQueryBuilder('o')->select('o.id, o.code, v.value AS label, a.properties')->leftJoin('o.optionValues', 'v', 'WITH', 'v.locale=:locale')->leftJoin('o.attribute', 'a')->where('o.attribute=:attribute')->orderBy('o.sortOrder')->setParameter('locale', $dataLocale)->setParameter('attribute', $collectionId);
if ($search) {
$qb->andWhere('v.value like :search OR o.code LIKE :search')->setParameter('search', "{$search}%");
}
if (isset($options['ids'])) {
$qb->andWhere($qb->expr()->in('o.id', ':ids'))->setParameter('ids', $options['ids']);
}
if (isset($options['limit'])) {
$qb->setMaxResults((int) $options['limit']);
if (isset($options['page'])) {
$qb->setFirstResult((int) $options['limit'] * ((int) $options['page'] - 1));
}
}
$results = [];
$autoSorting = null;
foreach ($qb->getQuery()->getArrayResult() as $row) {
if (null === $autoSorting && isset($row['properties']['autoOptionSorting'])) {
$autoSorting = $row['properties']['autoOptionSorting'];
}
$results[] = ['id' => isset($options['type']) && 'code' === $options['type'] ? $row['code'] : $row['id'], 'text' => null !== $row['label'] ? $row['label'] : sprintf('[%s]', $row['code'])];
}
if ($autoSorting) {
usort($results, function ($first, $second) {
return strcasecmp($first['text'], $second['text']);
});
}
return ['results' => $results];
}
开发者ID:abdeldayem,项目名称:pim-community-dev,代码行数:36,代码来源:AttributeOptionRepository.php
示例15: checkUrlMatch
private function checkUrlMatch($regx, $rule)
{
$m1 = explode('/', $regx);
$m2 = explode('/', $rule);
$match = true;
// 是否匹配
foreach ($m2 as $key => $val) {
if (':' == substr($val, 0, 1)) {
// 动态变量
if (strpos($val, '\\')) {
$type = substr($val, -1);
if ('d' == $type && !is_numeric($m1[$key])) {
$match = false;
break;
}
} elseif (strpos($val, '^')) {
$array = explode('|', substr(strstr($val, '^'), 1));
if (in_array($m1[$key], $array)) {
$match = false;
break;
}
}
} elseif (0 !== strcasecmp($val, $m1[$key])) {
$match = false;
break;
}
}
return $match;
}
开发者ID:yangyadong,项目名称:CarMarket,代码行数:29,代码来源:CheckActionRouteBehavior.class.php
示例16: getip
function getip($format = 0)
{
global $_iGLOBAL;
if (empty($_iGLOBAL['ip'])) {
if (getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
$onlineip = getenv('HTTP_CLIENT_IP');
} elseif (getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
$onlineip = getenv('HTTP_X_FORWARDED_FOR');
} elseif (getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
$onlineip = getenv('REMOTE_ADDR');
} elseif (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
$onlineip = $_SERVER['REMOTE_ADDR'];
}
preg_match("/[\\d\\.]{7,15}/", $onlineip, $onlineipmatches);
$_iGLOBAL['ip'] = $onlineipmatches[0] ? $onlineipmatches[0] : 'unknown';
}
if ($format) {
$ips = explode('.', $_iGLOBAL['ip']);
for ($i = 0; $i < 3; $i++) {
$ips[$i] = intval($ips[$i]);
}
return sprintf('%03d%03d%03d', $ips[0], $ips[1], $ips[2]);
} else {
return $_iGLOBAL['ip'];
}
}
开发者ID:idreamsoft,项目名称:iCMS5.0,代码行数:26,代码来源:common.php
示例17: decode
/**
* Decodes a JSON string.
* @param string
* @param int accepts Json::FORCE_ARRAY
* @return mixed
*/
public static function decode($json, $options = 0)
{
$json = (string) $json;
if (!preg_match('##u', $json)) {
throw new JsonException('Invalid UTF-8 sequence', 5);
// workaround for PHP < 5.3.3 & PECL JSON-C
}
$forceArray = (bool) ($options & self::FORCE_ARRAY);
if (!$forceArray && preg_match('#(?<=[^\\\\]")\\\\u0000(?:[^"\\\\]|\\\\.)*+"\\s*+:#', $json)) {
// workaround for json_decode fatal error when object key starts with \u0000
throw new JsonException(static::$messages[JSON_ERROR_CTRL_CHAR]);
}
$args = array($json, $forceArray, 512);
if (PHP_VERSION_ID >= 50400 && !(defined('JSON_C_VERSION') && PHP_INT_SIZE > 4)) {
// not implemented in PECL JSON-C 1.3.2 for 64bit systems
$args[] = JSON_BIGINT_AS_STRING;
}
$value = call_user_func_array('json_decode', $args);
if ($value === NULL && $json !== '' && strcasecmp(trim($json, " \t\n\r"), 'null') !== 0) {
// '' is not clearing json_last_error
$error = json_last_error();
throw new JsonException(isset(static::$messages[$error]) ? static::$messages[$error] : 'Unknown error', $error);
}
return $value;
}
开发者ID:NetteCamp,项目名称:2015-nextras-orm-twitter,代码行数:31,代码来源:Json.php
示例18: renderizar
public function renderizar($nome, $item = FALSE)
{
if (Session::get('autenticado')) {
$menu[] = array("id" => "", "titulo" => "", "link" => URL . "");
} else {
$menu[] = array("id" => "login", "titulo" => "Inciar Sessão", "link" => URL . "login");
}
if (strcasecmp(Session::get('nivel'), 'administrador') == 0) {
$admin = array(array("id" => "matricula", "titulo" => "Matricula", "link" => URL . "matricula"), array("id" => "docente", "titulo" => "Docente", "link" => URL . "docente"), array("id" => "curso", "titulo" => "Curso", "link" => URL . "curso"), array("id" => "nota", "titulo" => "Nota", "link" => URL . "nota"), array("id" => "programa", "titulo" => "Programa", "link" => URL . "programa"), array("id" => "relatorio", "titulo" => "Relatorio", "link" => URL . "relatorio"));
} else {
$admin = "";
}
$js = array();
if (count($this->_js)) {
$js = $this->_js;
}
$css = array();
if (count($this->_css)) {
$css = $this->_css;
}
$_layoutParam = array("caminho_css" => URL . "views/layout" . DS1 . DEFAULT_LAYOUT . "/bootstrap" . DS1 . "css/", "caminho_js" => URL . "views/layout" . DS1 . DEFAULT_LAYOUT . "/bootstrap" . DS1 . "js/", "caminho_images" => URL . "views/layout" . DS1 . DEFAULT_LAYOUT . "/images/", "caminho_vendores" => URL . "views/layout" . DS1 . DEFAULT_LAYOUT . "/vendors/", "caminho_assets" => URL . "views/layout" . DS1 . DEFAULT_LAYOUT . "/assets/", "menu" => $menu, "admin" => $admin, "js" => $js, "css" => $css);
$caminho = ROOT . "views" . DS1 . $this->_controller . DS1 . $nome . ".phtml";
//ou phtml
$header = ROOT . "views" . DS1 . "layout" . DS1 . DEFAULT_LAYOUT . DS1 . "header.php";
$footer = ROOT . "views" . DS1 . "layout" . DS1 . DEFAULT_LAYOUT . DS1 . "footer.php";
if (is_readable($caminho)) {
require $header;
//$this->assign("conteudo",$caminho);
require $caminho;
require $footer;
} else {
throw new Exception("Erro ao incluir a view, verifique o arquivo View");
}
}
开发者ID:ndongalameck,项目名称:ceafieUan,代码行数:34,代码来源:View.php
示例19: post_req
function post_req($url_str, $username, $password, $headers_arr, $req_str)
{
fwrite(STDERR, $url_str);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url_str);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req_str);
// Don't get the headers
//curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers_arr);
// execute the request
$output = curl_exec($ch);
$errno = curl_errno($ch);
$error = curl_error($ch);
if ($errno !== 0) {
curl_close($ch);
return array("success" => FALSE, "message" => "Error sending request to service {$url_str}: {$error}");
}
$sc_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($sc_code !== 200) {
$ct = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
curl_close($ch);
if (strcasecmp($ct, "application/json") == 0) {
$err_obj = json_decode($output, true);
return array("success" => FALSE, "message" => $err_obj['user_message']);
}
return array("success" => FALSE, "message" => "Service returned http code: {$sc_code}");
}
// close curl resource to free up system resources
curl_close($ch);
return array("success" => TRUE, "output" => $output);
}
开发者ID:jschoudt,项目名称:personality-insights-php,代码行数:35,代码来源:post-req.php
示例20: processTokenWithinScope
/**
* Processes this test when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The current file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
* @param int $currScope A pointer to the start of the scope.
*
* @return void
*/
protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope)
{
$className = $phpcsFile->getDeclarationName($currScope);
$methodName = $phpcsFile->getDeclarationName($stackPtr);
if (strcasecmp($methodName, $className) === 0) {
$error = 'PHP4 style constructors are not allowed; use "__construct()" instead';
$phpcsFile->addError($error, $stackPtr, 'OldStyle');
} else {
if (strcasecmp($methodName, '__construct') !== 0) {
// Not a constructor.
return;
}
}
$tokens = $phpcsFile->getTokens();
$parentClassName = $phpcsFile->findExtendedClassName($currScope);
if ($parentClassName === false) {
return;
}
$endFunctionIndex = $tokens[$stackPtr]['scope_closer'];
$startIndex = $stackPtr;
while ($doubleColonIndex = $phpcsFile->findNext(array(T_DOUBLE_COLON), $startIndex, $endFunctionIndex)) {
if ($tokens[$doubleColonIndex + 1]['code'] === T_STRING && $tokens[$doubleColonIndex + 1]['content'] === $parentClassName) {
$error = 'PHP4 style calls to parent constructors are not allowed; use "parent::__construct()" instead';
$phpcsFile->addError($error, $doubleColonIndex + 1, 'OldStyleCall');
}
$startIndex = $doubleColonIndex + 1;
}
}
开发者ID:sunnystone85,项目名称:CsPCHookSugar,代码行数:38,代码来源:ConstructorNameSniff.php
注:本文中的strcasecmp函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论