本文整理汇总了PHP中cast函数的典型用法代码示例。如果您正苦于以下问题:PHP cast函数的具体用法?PHP cast怎么用?PHP cast使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cast函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: verify
/**
* Executes this check
*
* @param xp.compiler.ast.Node node
* @param xp.compiler.types.Scope scope
* @return bool
*/
public function verify(\xp\compiler\ast\Node $node, \xp\compiler\types\Scope $scope)
{
$field = \cast($node, 'xp.compiler.ast.FieldNode');
if ($scope->declarations[0] instanceof \xp\compiler\ast\InterfaceNode) {
return ['I403', 'Interfaces may not have field declarations'];
}
}
示例2: verify
/**
* Executes this check
*
* @param xp.compiler.ast.Node node
* @param xp.compiler.types.Scope scope
* @return bool
*/
public function verify(\xp\compiler\ast\Node $node, \xp\compiler\types\Scope $scope)
{
$a = \cast($node, 'xp.compiler.ast.AssignmentNode');
if (!$this->isWriteable($a->variable)) {
return ['A403', 'Cannot assign to ' . ($a->variable instanceof \lang\Generic ? nameof($a->variable) : \xp::stringOf($a->variable)) . 's'];
}
}
示例3: verify
/**
* Executes this check
*
* @param xp.compiler.ast.Node node
* @param xp.compiler.types.Scope scope
* @return bool
*/
public function verify(\xp\compiler\ast\Node $node, \xp\compiler\types\Scope $scope)
{
$member = \cast($node, 'xp.compiler.ast.RoutineNode');
if (!isset($member->comment) && !$scope->declarations[0]->synthetic) {
return ['D201', 'No api doc for member ' . $scope->declarations[0]->name->compoundName() . '::' . $member->getName()];
}
}
示例4: verify
/**
* Executes this check
*
* @param xp.compiler.ast.Node node
* @param xp.compiler.types.Scope scope
* @return bool
*/
public function verify(\xp\compiler\ast\Node $node, \xp\compiler\types\Scope $scope)
{
$access = \cast($node, 'xp.compiler.ast.ArrayAccessNode');
$type = $scope->typeOf($access->target);
$result = TypeName::$VAR;
$message = null;
if ($type->isArray()) {
$result = $type->arrayComponentType();
} else {
if ($type->isMap()) {
$result = $type->mapComponentType();
} else {
if ($type->isClass()) {
$ptr = new TypeInstance($scope->resolveType($type));
if ($ptr->hasIndexer()) {
$result = $ptr->getIndexer()->type;
} else {
$message = ['T305', 'Type ' . $ptr->name() . ' does not support offset access'];
}
} else {
if ($type->isVariable()) {
$message = ['T203', 'Array access (var)' . $access->hashCode() . ' verification deferred until runtime'];
} else {
if ('string' === $type->name) {
$result = $type;
} else {
$message = ['T305', 'Using array-access on unsupported type ' . $type->toString()];
}
}
}
}
}
$scope->setType($access, $result);
return $message;
}
示例5: verify
/**
* Executes this check
*
* @param xp.compiler.ast.Node node
* @param xp.compiler.types.Scope scope
* @return bool
*/
public function verify(\xp\compiler\ast\Node $node, \xp\compiler\types\Scope $scope)
{
$routine = \cast($node, 'xp.compiler.ast.PropertyNode');
if ($scope->declarations[0] instanceof \xp\compiler\ast\InterfaceNode) {
return ['I403', 'Interfaces may not have properties'];
}
}
示例6: verify
/**
* Executes this check
*
* @param xp.compiler.ast.Node node
* @param xp.compiler.types.Scope scope
* @return bool
*/
public function verify(\xp\compiler\ast\Node $node, \xp\compiler\types\Scope $scope)
{
$routine = \cast($node, 'xp.compiler.ast.RoutineNode');
$qname = $scope->declarations[0]->name->compoundName() . '::' . $routine->getName();
$empty = $routine->body === null;
if ($scope->declarations[0] instanceof \xp\compiler\ast\InterfaceNode) {
if (!$empty) {
return ['R403', 'Interface methods may not have a body ' . $qname];
} else {
if ($routine->modifiers !== MODIFIER_PUBLIC && $routine->modifiers !== 0) {
return ['R401', 'Interface methods may only be public ' . $qname];
}
}
} else {
if (Modifiers::isAbstract($routine->modifiers) && !$empty) {
return ['R403', 'Abstract methods may not have a body ' . $qname];
} else {
if (!Modifiers::isAbstract($routine->modifiers) && $empty) {
return ['R401', 'Non-abstract methods must have a body ' . $qname];
}
}
if ($routine->extension && !Modifiers::isStatic($routine->modifiers)) {
return ['E403', 'Extension methods must be static ' . $qname];
}
}
}
示例7: verify
/**
* Executes this check
*
* @param xp.compiler.ast.Node node
* @param xp.compiler.types.Scope scope
* @return bool
*/
public function verify(\xp\compiler\ast\Node $node, \xp\compiler\types\Scope $scope)
{
$decl = \cast($node, 'xp.compiler.ast.TypeDeclarationNode');
if (!isset($decl->comment) && !$decl->synthetic) {
return ['D201', 'No api doc for type ' . $decl->name->compoundName()];
}
}
示例8: verify
/**
* Executes this check
*
* @param xp.compiler.ast.Node node
* @param xp.compiler.types.Scope scope
* @return bool
*/
public function verify(\xp\compiler\ast\Node $node, \xp\compiler\types\Scope $scope)
{
$access = \cast($node, 'xp.compiler.ast.MemberAccessNode');
// Verify type
// * var: Might have method
// * primitive, array, map, int: Definitely don't have fields
$type = $scope->typeOf($access->target);
if ($type->isVariable()) {
return ['T203', 'Member access (var).' . $access->name . '() verification deferred until runtime'];
} else {
if (!$type->isClass()) {
return ['T305', 'Using member access on unsupported type ' . $type->compoundName()];
}
}
// Verify target method exists
$target = new \xp\compiler\types\TypeInstance($scope->resolveType($type));
if ($target->hasField($access->name)) {
$member = $target->getField($access->name);
} else {
if ($target->hasProperty($access->name)) {
$member = $target->getProperty($access->name);
} else {
return ['T404', 'No such field $' . $access->name . ' in ' . $target->name()];
}
}
// Verify visibility
if (!($member->modifiers & MODIFIER_PUBLIC)) {
$enclosing = $scope->resolveType($scope->declarations[0]->name);
if ($member->modifiers & MODIFIER_PRIVATE && !$enclosing->equals($target) || $member->modifiers & MODIFIER_PROTECTED && !($enclosing->equals($target) || $enclosing->isSubclassOf($target))) {
return ['T403', sprintf('Accessing %s %s::$%s from %s', implode(' ', \lang\reflect\Modifiers::namesOf($member->modifiers)), $target->name(), $member->name, $enclosing->name())];
}
}
}
示例9: verify
/**
* Executes this check
*
* @param xp.compiler.ast.Node node
* @param xp.compiler.types.Scope scope
* @return bool
*/
public function verify(\xp\compiler\ast\Node $node, \xp\compiler\types\Scope $scope)
{
$v = \cast($node, 'xp.compiler.ast.VariableNode');
if (!$scope->getType($v)) {
return ['V404', 'Uninitialized variable ' . $v->name];
}
}
示例10: code
/** @return string */
public function code()
{
$r = '';
foreach ($this->nodes as $node) {
$r .= "\n" . cast($node, 'net.daringfireball.markdown.Text')->value;
}
return substr($r, 1);
}
示例11: verify
/**
* Executes this check
*
* @param xp.compiler.ast.Node node
* @param xp.compiler.types.Scope scope
* @return bool
*/
public function verify(\xp\compiler\ast\Node $node, \xp\compiler\types\Scope $scope)
{
$arm = cast($node, 'xp.compiler.ast.ArmNode');
foreach ($arm->initializations as $i => $init) {
$type = $scope->resolveType($scope->typeOf($init), false);
if (!$type->isSubclassOf(self::$closeable)) {
return ['A403', 'Type ' . $type->name() . ' for assignment #' . ($i + 1) . ' in ARM block is not closeable'];
}
}
}
示例12: expanding
/**
* Add expansion `${kind.X}` with a given expansion function `f(X)`
*
* @param string $kind
* @param [:var]|function(string): string $expansion
* @return self
*/
public function expanding($kind, $expansion)
{
$this->expansion = $this->expansion ?: clone self::$env;
if ($expansion instanceof \ArrayAccess || is_array($expansion) && 0 !== key($expansion)) {
$func = function ($name) use($expansion) {
return isset($expansion[$name]) ? $expansion[$name] : null;
};
} else {
$func = cast($expansion, 'function(string): string');
}
$this->expansion->expand($kind, $func);
return $this;
}
示例13: loader
/**
* Loader
*
* @param array $attr
* @param array $item
*
* @return mixed
*/
function loader(array $attr, array $item)
{
$item[$attr['id']] = cast($attr, $item[$attr['id']] ?? null);
$callback = fqn('loader_' . $attr['type']);
if (is_callable($callback)) {
return $callback($attr, $item);
}
// @todo
if ($attr['backend'] === 'json') {
return loader_json($attr, $item);
}
return $item[$attr['id']];
}
示例14: optimize
/**
* Optimize a given node
*
* @param xp.compiler.ast.Node in
* @param xp.compiler.types.Scope scope
* @param xp.compiler.optimize.Optimizations optimizations
* @param xp.compiler.ast.Node optimized
*/
public function optimize(\xp\compiler\ast\Node $in, \xp\compiler\types\Scope $scope, Optimizations $optimizations)
{
$method = \cast($in, 'xp.compiler.ast.RoutineNode');
// Search for return statement, then see if anything comes after it
$s = sizeof($method->body);
foreach ($method->body as $i => $statement) {
if ($statement instanceof ReturnNode && $i < $s) {
$method->body = array_slice($method->body, 0, $i + 1);
// Include return
break;
}
}
return $method;
}
示例15: cast
private static function cast($_inputs)
{
if (is_object($_inputs)) {
if (class_exists($_inputs->getEqType_name())) {
return cast($_inputs, $_inputs->getEqType_name());
}
}
if (is_array($_inputs)) {
$return = array();
foreach ($_inputs as $input) {
$return[] = self::cast($input);
}
return $return;
}
return $_inputs;
}