本文整理汇总了PHP中Zephir\Utils::escapeClassName方法的典型用法代码示例。如果您正苦于以下问题:PHP Utils::escapeClassName方法的具体用法?PHP Utils::escapeClassName怎么用?PHP Utils::escapeClassName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zephir\Utils
的用法示例。
在下文中一共展示了Utils::escapeClassName方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: compile
/**
* Creates a new instance
*
* @param $expression
* @param CompilationContext $compilationContext
* @return CompiledExpression
* @throws CompilerException
*/
public function compile(array $expression, CompilationContext $compilationContext)
{
$codePrinter = $compilationContext->codePrinter;
/**
* Resolves the symbol that expects the value
*/
$this->_literalOnly = false;
$symbolVariable = $this->getExpectedNonLiteral($compilationContext, $expression);
if (!$symbolVariable->isVariable()) {
throw new CompilerException("Objects can only be instantiated into dynamic variables", $expression);
}
if ($symbolVariable->isLocalOnly()) {
throw new CompilerException("Cannot use non-heap variable to store new instance", $expression);
}
if ($symbolVariable->getName() != 'return_value') {
if ($symbolVariable->hasDifferentDynamicType(array('unknown', 'undefined', 'object', 'null'))) {
$compilationContext->logger->warning('Possible attempt to use non-object in "new" operator', 'non-valid-new', $expression);
}
}
/**
* Mark variables as dynamic objects
*/
$symbolVariable->setDynamicTypes('object');
$dynamic = false;
if ($expression['class'] == 'self' || $expression['class'] == 'static') {
$className = $compilationContext->classDefinition->getCompleteName();
} else {
$className = $expression['class'];
$dynamic = $expression['dynamic'];
if (!$dynamic) {
$className = $compilationContext->getFullName($expression['class']);
}
}
if (!$className) {
throw new CompilerException("A class name is required to instantiate the object", $expression);
}
/**
* stdclass doesn't have constructors
*/
$lowerClassName = strtolower($className);
$isStdClass = $lowerClassName === 'stdclass' || $lowerClassName === '\\stdclass';
if ($isStdClass) {
if (isset($expression['parameters']) && count($expression['parameters']) > 0) {
throw new CompilerException("stdclass does not receive parameters in its constructor", $expression);
}
$compilationContext->backend->initObject($symbolVariable, null, $compilationContext);
$symbolVariable->setClassTypes('stdclass');
} else {
$classDefinition = false;
if ($compilationContext->compiler->isClass($className)) {
$classDefinition = $compilationContext->compiler->getClassDefinition($className);
}
/**
* Classes inside the same extension
*/
if ($classDefinition) {
$compilationContext->backend->initObject($symbolVariable, $classDefinition->getClassEntry($compilationContext), $compilationContext);
$symbolVariable->setClassTypes($className);
$symbolVariable->setAssociatedClass($classDefinition);
} else {
/**
* Classes outside the extension
*/
if ($dynamic) {
$classNameVariable = $compilationContext->symbolTable->getVariableForRead($className, $compilationContext, $expression);
if ($classNameVariable->isNotVariableAndString()) {
throw new CompilerException("Only dynamic/string variables can be used in new operator. " . $classNameVariable->getName(), $expression);
}
/**
* Use a safe string version of the variable to avoid segfaults
*/
$compilationContext->headersManager->add('kernel/object');
$safeSymbolVariable = $compilationContext->symbolTable->getTempVariable('variable', $compilationContext, $expression);
$safeSymbolVariable->setMustInitNull(true);
$safeSymbolVariable->setIsInitialized(true, $compilationContext, $expression);
$safeSymbolVariable->increaseUses();
$compilationContext->codePrinter->output('zephir_fetch_safe_class(' . $safeSymbolVariable->getName() . ', ' . $classNameVariable->getName() . ');');
$safeSymbol = $compilationContext->backend->getVariableCode($safeSymbolVariable);
$classNameToFetch = 'Z_STRVAL_P(' . $safeSymbol . '), Z_STRLEN_P(' . $safeSymbol . ')';
$zendClassEntry = $compilationContext->cacheManager->getClassEntryCache()->get($classNameToFetch, true, $compilationContext);
$classEntry = $zendClassEntry->getName();
} else {
if (!class_exists($className, false)) {
$compilationContext->logger->warning('Class "' . $className . '" does not exist at compile time', "nonexistent-class", $expression);
$classNameToFetch = 'SL("' . Utils::escapeClassName($className) . '")';
$zendClassEntry = $compilationContext->cacheManager->getClassEntryCache()->get($classNameToFetch, false, $compilationContext);
$classEntry = $zendClassEntry->getName();
} else {
$reflectionClass = new \ReflectionClass($className);
if ($reflectionClass->isInterface()) {
throw new CompilerException('Interfaces cannot be instantiated', $expression);
} else {
//.........这里部分代码省略.........
示例2: getClassEntryByClassName
//.........这里部分代码省略.........
$classEntry = 'reflection_exception_ptr';
break;
case 'reflection':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_ptr';
break;
case 'reflectionfunctionabstract':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_function_abstract_ptr';
break;
case 'reflectionfunction':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_function_ptr';
break;
case 'reflectionparameter':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_parameter_ptr';
break;
case 'reflectionclass':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_class_ptr';
break;
case 'reflectionobject':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_object_ptr';
break;
case 'reflectionmethod':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_method_ptr';
break;
case 'reflectionproperty':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_property_ptr';
break;
case 'reflectionextension':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_extension_ptr';
break;
case 'reflectionzendextension':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_zend_extension_ptr';
break;*/
// Reflection
/*case 'reflector':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflector_ptr';
break;
case 'reflectionexception':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_exception_ptr';
break;
case 'reflection':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_ptr';
break;
case 'reflectionfunctionabstract':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_function_abstract_ptr';
break;
case 'reflectionfunction':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_function_ptr';
break;
case 'reflectionparameter':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_parameter_ptr';
break;
case 'reflectionclass':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_class_ptr';
break;
case 'reflectionobject':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_object_ptr';
break;
case 'reflectionmethod':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_method_ptr';
break;
case 'reflectionproperty':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_property_ptr';
break;
case 'reflectionextension':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_extension_ptr';
break;
case 'reflectionzendextension':
$compilationContext->headersManager->add('ext/reflection/php_reflection');
$classEntry = 'reflection_zend_extension_ptr';
break;*/
default:
if (!$check) {
throw new CompilerException('Unknown class entry for "' . $className . '"');
} else {
$classEntry = $compilationContext->backend->fetchClassEntry(Utils::escapeClassName(strtolower($className)));
}
}
return $classEntry;
}
示例3: generateFunctionInformation
public function generateFunctionInformation()
{
$headerPrinter = new CodePrinter();
$entryPrinter = new CodePrinter();
/**
* Create argument info
*/
foreach ($this->functionDefinitions as $func) {
$funcName = $func->getInternalName();
$argInfoName = 'arginfo_' . strtolower($funcName);
$headerPrinter->output('PHP_FUNCTION(' . $funcName . ');');
$parameters = $func->getParameters();
if (count($parameters)) {
$headerPrinter->output('ZEND_BEGIN_ARG_INFO_EX(' . $argInfoName . ', 0, 0, ' . $func->getNumberOfRequiredParameters() . ')');
foreach ($parameters->getParameters() as $parameter) {
switch ($parameter['data-type']) {
case 'array':
$headerPrinter->output("\t" . 'ZEND_ARG_ARRAY_INFO(0, ' . $parameter['name'] . ', ' . (isset($parameter['default']) ? 1 : 0) . ')');
break;
case 'variable':
if (isset($parameter['cast'])) {
switch ($parameter['cast']['type']) {
case 'variable':
$value = $parameter['cast']['value'];
$headerPrinter->output("\t" . 'ZEND_ARG_OBJ_INFO(0, ' . $parameter['name'] . ', ' . Utils::escapeClassName($compilationContext->getFullName($value)) . ', ' . (isset($parameter['default']) ? 1 : 0) . ')');
break;
default:
throw new Exception('Unexpected exception');
}
} else {
$headerPrinter->output("\t" . 'ZEND_ARG_INFO(0, ' . $parameter['name'] . ')');
}
break;
default:
$headerPrinter->output("\t" . 'ZEND_ARG_INFO(0, ' . $parameter['name'] . ')');
break;
}
}
$headerPrinter->output('ZEND_END_ARG_INFO()');
$headerPrinter->outputBlankLine();
}
/** Generate FE's */
$paramData = count($parameters) ? $argInfoName : 'NULL';
if ($func->isGlobal()) {
$entryPrinter->output('ZEND_NAMED_FE(' . $func->getName() . ', ZEND_FN(' . $funcName . '), ' . $paramData . ')');
} else {
$entryPrinter->output('ZEND_NS_NAMED_FE("' . str_replace('\\', '\\\\', $func->getNamespace()) . '", ' . $func->getName() . ', ZEND_FN(' . $funcName . '), ' . $paramData . ')');
}
}
$entryPrinter->output('ZEND_FE_END');
return array($headerPrinter->getOutput(), $entryPrinter->getOutput());
}
示例4: compile
//.........这里部分代码省略.........
*/
$symbol->setIsInitialized(true, $compilationContext, $parameter);
/**
* Variables with class/type must be objects across the execution
*/
if (isset($parameter['cast'])) {
$symbol->setDynamicTypes('object');
$symbol->setClassTypes($compilationContext->getFullName($parameter['cast']['value']));
$classCastChecks[] = array($symbol, $parameter);
} else {
if (isset($parameter['data-type'])) {
if ($parameter['data-type'] == 'variable') {
$symbol->setDynamicTypes('undefined');
}
} else {
$symbol->setDynamicTypes('undefined');
}
}
}
$compilationContext->codePrinter->increaseLevel();
/**
* Checks that a class-hinted variable meets its declaration
*/
foreach ($classCastChecks as $classCastCheck) {
foreach ($classCastCheck[0]->getClassTypes() as $className) {
/**
* If the parameter is nullable check it must pass the 'instanceof' validation
*/
if (!isset($classCastCheck[1]['default'])) {
$evalExpr = new UnaryOperatorBuilder('not', new BinaryOperatorBuilder('instanceof', new VariableBuilder($classCastCheck[0]->getName()), new VariableBuilder('\\' . $className)));
} else {
$evalExpr = new BinaryOperatorBuilder('and', new BinaryOperatorBuilder('not-equals', new TypeOfOperatorBuilder(new VariableBuilder($classCastCheck[0]->getName())), new LiteralBuilder("string", "null")), new UnaryOperatorBuilder('not', new BinaryOperatorBuilder('instanceof', new VariableBuilder($classCastCheck[0]->getName()), new VariableBuilder('\\' . $className))));
}
$ifCheck = new IfStatementBuilder($evalExpr, new StatementsBlockBuilder(array(new ThrowStatementBuilder(new NewInstanceOperatorBuilder('\\InvalidArgumentException', array(new ParameterBuilder(new LiteralBuilder("string", "Parameter '" . $classCastCheck[0]->getName() . "' must be an instance of '" . Utils::escapeClassName($className) . "'"))))))));
$ifStatement = new IfStatement($ifCheck->get());
$ifStatement->compile($compilationContext);
}
}
$compilationContext->codePrinter->decreaseLevel();
}
/**
* Compile the block of statements if any
*/
if (is_object($this->_statements)) {
if ($this->hasModifier('static')) {
$compilationContext->staticContext = true;
} else {
$compilationContext->staticContext = false;
}
/**
* Compile the statements block as a 'root' branch
*/
$this->_statements->compile($compilationContext, false, Branch::TYPE_ROOT);
}
/**
* Initialize default values in dynamic variables
*/
$initVarCode = "";
foreach ($symbolTable->getVariables() as $variable) {
/**
* Initialize 'dynamic' variables with default values
*/
if ($variable->getType() == 'variable') {
if ($variable->getNumberUses() > 0) {
if ($variable->getName() != 'this_ptr' && $variable->getName() != 'return_value' && $variable->getName() != 'return_value_ptr') {
$defaultValue = $variable->getDefaultInitValue();
示例5: compile
/**
* @param $expression
* @param CompilationContext $context
* @return CompiledExpression
* @throws CompilerException
* @throws \Zephir\Exception
*/
public function compile($expression, CompilationContext $context)
{
$left = new Expression($expression['left']);
$resolved = $left->compile($context);
if ($resolved->getType() != 'variable') {
throw new CompilerException("InstanceOf requires a 'dynamic variable' in the left operand", $expression);
}
$symbolVariable = $context->symbolTable->getVariableForRead($resolved->getCode(), $context, $expression);
if (!$symbolVariable->isVariable()) {
throw new CompilerException("InstanceOf requires a 'dynamic variable' in the left operand", $expression);
}
$right = new Expression($expression['right']);
$resolved = $right->compile($context);
$resolvedVariable = $resolved->getCode();
switch ($resolved->getType()) {
case 'string':
$className = Utils::getFullName($resolvedVariable, $context->classDefinition->getNamespace(), $context->aliasManager);
if ($context->compiler->isClass($className)) {
$classDefinition = $context->compiler->getClassDefinition($className);
$classEntry = $classDefinition->getClassEntry($context);
} else {
if (!class_exists($className, false)) {
$code = 'SL("' . $resolvedVariable . '")';
} else {
$classEntry = $context->classDefinition->getClassEntryByClassName($className, $context, true);
if (!$classEntry) {
$code = 'SL("' . $resolvedVariable . '")';
}
}
}
break;
default:
switch ($resolved->getType()) {
case 'variable':
if ($resolvedVariable == 'this') {
/**
* @todo It's an optimization variant, but maybe we need to get entry in runtime?
*/
$classEntry = $context->classDefinition->getClassEntry($context);
} elseif (!$context->symbolTable->hasVariable($resolvedVariable)) {
$className = $context->getFullName($resolvedVariable);
if ($className == 'Traversable') {
$symbol = $context->backend->getVariableCode($symbolVariable);
return new CompiledExpression('bool', 'zephir_zval_is_traversable(' . $symbol . ' TSRMLS_CC)', $expression);
}
if ($context->compiler->isClass($className)) {
$classDefinition = $context->compiler->getClassDefinition($className);
$classEntry = $classDefinition->getClassEntry($context);
} else {
if ($context->compiler->isInterface($className)) {
$classDefinition = $context->compiler->getClassDefinition($className);
$classEntry = $classDefinition->getClassEntry($context);
} else {
if (!class_exists($className, false)) {
$code = 'SL("' . trim(Utils::escapeClassName($className), "\\") . '")';
} else {
$classEntry = $context->classDefinition->getClassEntryByClassName($className, $context, true);
if (!$classEntry) {
$code = 'SL("' . trim(Utils::escapeClassName($className), "\\") . '")';
}
}
}
}
} else {
$code = 'Z_STRVAL_P(' . $resolvedVariable . '), Z_STRLEN_P(' . $resolvedVariable . ')';
}
break;
case 'property-access':
case 'array-access':
$context->headersManager->add('kernel/operators');
$tempVariable = $context->symbolTable->getTempVariableForWrite('string', $context);
$tempVariable->setMustInitNull(true);
$tempVariableName = $tempVariable->getName();
$context->codePrinter->output('zephir_get_strval(' . $tempVariableName . ', ' . $resolvedVariable . ');');
$code = 'Z_STRVAL_P(' . $tempVariableName . '), Z_STRLEN_P(' . $tempVariableName . ')';
break;
default:
throw new CompilerException("InstanceOf requires a 'variable' or a 'string' in the right operand", $expression);
}
}
/* @TODO, Possible optimization is use zephir_is_instance when the const class name is an internal class or interface */
$context->headersManager->add('kernel/object');
$symbol = $context->backend->getVariableCode($symbolVariable);
if (isset($code)) {
return new CompiledExpression('bool', 'zephir_is_instance_of(' . $symbol . ', ' . $code . ' TSRMLS_CC)', $expression);
}
return new CompiledExpression('bool', 'zephir_instance_of_ev(' . $symbol . ', ' . $classEntry . ' TSRMLS_CC)', $expression);
}
示例6: testEscapeClassName
/**
* Test escapeClassName method.
*/
public function testEscapeClassName()
{
$classname = '\\Bar\\Foo';
$this->assertSame(Utils::escapeClassName($classname), '\\\\Bar\\\\Foo');
}