Namespaces

  • Latte
    • Loaders
    • Macros
    • Runtime
  • Nette
    • Application
      • Responses
      • Routers
      • UI
    • Bridges
      • ApplicationLatte
      • ApplicationTracy
      • CacheLatte
      • DatabaseDI
      • DatabaseTracy
      • DITracy
      • FormsLatte
      • Framework
      • HttpTracy
      • SecurityTracy
    • Caching
      • Storages
    • ComponentModel
    • Database
      • Drivers
      • Reflection
      • Table
    • DI
      • Config
        • Adapters
      • Extensions
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
    • Reflection
    • Security
    • Templating
    • Utils
  • NetteModule
  • none
  • Tracy

Classes

  • ClassType
  • Helpers
  • Method
  • Parameter
  • PhpLiteral
  • Property
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Other releases
  • Nette homepage
 1: <?php
 2: 
 3: /**
 4:  * This file is part of the Nette Framework (https://nette.org)
 5:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
 6:  */
 7: 
 8: namespace Nette\PhpGenerator;
 9: 
10: use Nette;
11: 
12: 
13: /**
14:  * Method parameter description.
15:  *
16:  * @author     David Grudl
17:  *
18:  * @method Parameter setName(string)
19:  * @method string getName()
20:  * @method Parameter setReference(bool)
21:  * @method bool isReference()
22:  * @method Parameter setTypeHint(string)
23:  * @method string getTypeHint()
24:  * @method Parameter setOptional(bool)
25:  * @method bool isOptional()
26:  * @method Parameter setDefaultValue(mixed)
27:  * @method mixed getDefaultValue()
28:  */
29: class Parameter extends Nette\Object
30: {
31:     /** @var string */
32:     private $name;
33: 
34:     /** @var bool */
35:     private $reference;
36: 
37:     /** @var string */
38:     private $typeHint;
39: 
40:     /** @var bool */
41:     private $optional;
42: 
43:     /** @var mixed */
44:     public $defaultValue;
45: 
46: 
47:     /** @return Parameter */
48:     public static function from(\ReflectionParameter $from)
49:     {
50:         $param = new static;
51:         $param->name = $from->getName();
52:         $param->reference = $from->isPassedByReference();
53:         try {
54:             $param->typeHint = $from->isArray() ? 'array' : ($from->getClass() ? '\\' . $from->getClass()->getName() : '');
55:         } catch (\ReflectionException $e) {
56:             if (preg_match('#Class (.+) does not exist#', $e->getMessage(), $m)) {
57:                 $param->typeHint = '\\' . $m[1];
58:             } else {
59:                 throw $e;
60:             }
61:         }
62:         $param->optional = PHP_VERSION_ID < 50407 ? $from->isOptional() || ($param->typeHint && $from->allowsNull()) : $from->isDefaultValueAvailable();
63:         $param->defaultValue = (PHP_VERSION_ID === 50316 ? $from->isOptional() : $from->isDefaultValueAvailable()) ? $from->getDefaultValue() : NULL;
64: 
65:         $namespace = $from->getDeclaringClass()->getNamespaceName();
66:         $namespace = $namespace ? "\\$namespace\\" : '\\';
67:         if (Nette\Utils\Strings::startsWith($param->typeHint, $namespace)) {
68:             $param->typeHint = substr($param->typeHint, strlen($namespace));
69:         }
70:         return $param;
71:     }
72: 
73: }
74: 
Nette 2.2 API documentation generated by ApiGen 2.8.0