From e2aacad8aab9c14385499b5eda75cc63f37ed2f5 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Fri, 7 Mar 2014 19:41:43 +0100 Subject: [PATCH] Added links to PHP.net to apidoc --- extensions/apidoc/helpers/ApiMarkdown.php | 6 +++++ extensions/apidoc/renderers/BaseRenderer.php | 25 ++++++++++++++++++- .../apidoc/templates/html/ApiRenderer.php | 8 +++--- extensions/sphinx/Query.php | 4 +-- framework/base/ArrayAccessTrait.php | 2 +- framework/base/Component.php | 4 +-- framework/base/Event.php | 4 +-- framework/grid/ActionColumn.php | 2 +- framework/mail/BaseMailer.php | 2 +- framework/validators/FilterValidator.php | 2 +- framework/web/AccessControl.php | 2 +- framework/web/AccessRule.php | 4 +-- framework/web/HttpCache.php | 4 +-- 13 files changed, 49 insertions(+), 20 deletions(-) diff --git a/extensions/apidoc/helpers/ApiMarkdown.php b/extensions/apidoc/helpers/ApiMarkdown.php index 5a1ace8a2f..4fff8275b7 100644 --- a/extensions/apidoc/helpers/ApiMarkdown.php +++ b/extensions/apidoc/helpers/ApiMarkdown.php @@ -179,6 +179,7 @@ class ApiMarkdown extends GithubMarkdown $offset ]; } + if ($context !== null) { // Collection resolves relative types $object = (new Collection([$object], $context->phpDocContext))->__toString(); @@ -188,6 +189,11 @@ class ApiMarkdown extends GithubMarkdown static::$renderer->createTypeLink($type, null, $title), $offset ]; + } elseif (strpos($typeLink = static::$renderer->createTypeLink($object, null, $title), 'apiContext->errors[] = [ 'file' => ($context !== null) ? $context->sourceFile : null, diff --git a/extensions/apidoc/renderers/BaseRenderer.php b/extensions/apidoc/renderers/BaseRenderer.php index 786ec61cf6..3c94310e2d 100644 --- a/extensions/apidoc/renderers/BaseRenderer.php +++ b/extensions/apidoc/renderers/BaseRenderer.php @@ -85,7 +85,30 @@ abstract class BaseRenderer extends Component } } if (!is_object($type)) { - $links[] = $type; + $linkText = ltrim($type, '\\'); + if ($title !== null) { + $linkText = $title; + } + $phpTypes = [ + 'callable', + 'array', + 'string', + 'boolean', + 'integer', + 'float', + 'object', + 'resource', + 'null', + ]; + // check if it is PHP internal class + if (((class_exists($type, false) || interface_exists($type, false) || trait_exists($type, false)) && + ($reflection = new \ReflectionClass($type)) && $reflection->isInternal())) { + $links[] = $this->generateLink($linkText, 'http://www.php.net/class.' . strtolower(ltrim($type, '\\'))) . $postfix; + } elseif (in_array($type, $phpTypes)) { + $links[] = $this->generateLink($linkText, 'http://www.php.net/language.types.' . strtolower(ltrim($type, '\\'))) . $postfix; + } else { + $links[] = $type; + } } else { $linkText = $type->name; if ($title !== null) { diff --git a/extensions/apidoc/templates/html/ApiRenderer.php b/extensions/apidoc/templates/html/ApiRenderer.php index 5fbdca704f..b83b0e6a00 100644 --- a/extensions/apidoc/templates/html/ApiRenderer.php +++ b/extensions/apidoc/templates/html/ApiRenderer.php @@ -148,7 +148,7 @@ class ApiRenderer extends BaseApiRenderer implements ViewContextInterface $class = $this->apiContext->classes[$class->parentClass]; $parents[] = $this->createTypeLink($class); } else { - $parents[] = $class->parentClass; // TODO link to php.net + $parents[] = $this->createTypeLink($class->parentClass); break; } } @@ -167,7 +167,7 @@ class ApiRenderer extends BaseApiRenderer implements ViewContextInterface if(isset($this->apiContext->interfaces[$interface])) { $interfaces[] = $this->createTypeLink($this->apiContext->interfaces[$interface]); } else { - $interfaces[] = $interface; // TODO link to php.net + $interfaces[] = $this->createTypeLink($interface); } } return implode(', ', $interfaces); @@ -185,7 +185,7 @@ class ApiRenderer extends BaseApiRenderer implements ViewContextInterface if(isset($this->apiContext->traits[$trait])) { $traits[] = $this->createTypeLink($this->apiContext->traits[$trait]); } else { - $traits[] = $trait; // TODO link to php.net + $traits[] = $this->createTypeLink($trait); } } return implode(', ', $traits); @@ -203,7 +203,7 @@ class ApiRenderer extends BaseApiRenderer implements ViewContextInterface if(isset($this->apiContext->classes[$class])) { $classes[] = $this->createTypeLink($this->apiContext->classes[$class]); } else { - $classes[] = $class; // TODO link to php.net + $classes[] = $this->createTypeLink($class); } } return implode(', ', $classes); diff --git a/extensions/sphinx/Query.php b/extensions/sphinx/Query.php index 8ad7c3ae5c..8ad5efc259 100644 --- a/extensions/sphinx/Query.php +++ b/extensions/sphinx/Query.php @@ -99,7 +99,7 @@ class Query extends Component implements QueryInterface */ public $params = []; /** - * @var callback PHP callback, which should be used to fetch source data for the snippets. + * @var callable PHP callback, which should be used to fetch source data for the snippets. * Such callback will receive array of query result rows as an argument and must return the * array of snippet source strings in the order, which match one of incoming rows. * For example: @@ -642,7 +642,7 @@ class Query extends Component implements QueryInterface /** * Sets the PHP callback, which should be used to retrieve the source data * for the snippets building. - * @param callback $callback PHP callback, which should be used to fetch source data for the snippets. + * @param callable $callback PHP callback, which should be used to fetch source data for the snippets. * @return static the query object itself * @see snippetCallback */ diff --git a/framework/base/ArrayAccessTrait.php b/framework/base/ArrayAccessTrait.php index e4b58562e2..3ccbd975d2 100644 --- a/framework/base/ArrayAccessTrait.php +++ b/framework/base/ArrayAccessTrait.php @@ -8,7 +8,7 @@ namespace yii\base; /** - * ArrayAccessTrait provides the implementation for `IteratorAggregate`, `ArrayAccess` and `Countable`. + * ArrayAccessTrait provides the implementation for [[\IteratorAggregate]], [[\ArrayAccess]] and [[\Countable]]. * * Note that ArrayAccessTrait requires the class using it contain a property named `data` which should be an array. * The data will be exposed by ArrayAccessTrait to support accessing the class object like an array. diff --git a/framework/base/Component.php b/framework/base/Component.php index bacd8d6ded..a5c6d46047 100644 --- a/framework/base/Component.php +++ b/framework/base/Component.php @@ -460,7 +460,7 @@ class Component extends Object * where `$event` is an [[Event]] object which includes parameters associated with the event. * * @param string $name the event name - * @param callback $handler the event handler + * @param callable $handler the event handler * @param mixed $data the data to be passed to the event handler when the event is triggered. * When the event handler is invoked, this data can be accessed via [[Event::data]]. * @see off() @@ -475,7 +475,7 @@ class Component extends Object * Detaches an existing event handler from this component. * This method is the opposite of [[on()]]. * @param string $name event name - * @param callback $handler the event handler to be removed. + * @param callable $handler the event handler to be removed. * If it is null, all handlers attached to the named event will be removed. * @return boolean if a handler is found and detached * @see on() diff --git a/framework/base/Event.php b/framework/base/Event.php index 9845c77009..1a83467daf 100644 --- a/framework/base/Event.php +++ b/framework/base/Event.php @@ -71,7 +71,7 @@ class Event extends Object * * @param string $class the fully qualified class name to which the event handler needs to attach. * @param string $name the event name. - * @param callback $handler the event handler. + * @param callable $handler the event handler. * @param mixed $data the data to be passed to the event handler when the event is triggered. * When the event handler is invoked, this data can be accessed via [[Event::data]]. * @see off() @@ -88,7 +88,7 @@ class Event extends Object * * @param string $class the fully qualified class name from which the event handler needs to be detached. * @param string $name the event name. - * @param callback $handler the event handler to be removed. + * @param callable $handler the event handler to be removed. * If it is null, all handlers attached to the named event will be removed. * @return boolean whether a handler is found and detached. * @see on() diff --git a/framework/grid/ActionColumn.php b/framework/grid/ActionColumn.php index 7d42becf6f..cae5530f8e 100644 --- a/framework/grid/ActionColumn.php +++ b/framework/grid/ActionColumn.php @@ -63,7 +63,7 @@ class ActionColumn extends Column */ public $buttons = []; /** - * @var callback a callback that creates a button URL using the specified model information. + * @var callable a callback that creates a button URL using the specified model information. * The signature of the callback should be the same as that of [[createUrl()]]. * If this property is not set, button URLs will be created using [[createUrl()]]. */ diff --git a/framework/mail/BaseMailer.php b/framework/mail/BaseMailer.php index 01f6635ac6..34f81044a6 100644 --- a/framework/mail/BaseMailer.php +++ b/framework/mail/BaseMailer.php @@ -88,7 +88,7 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont */ public $fileTransportPath = '@runtime/mail'; /** - * @var callback a PHP callback that will be called by [[send()]] when [[useFileTransport]] is true. + * @var callable a PHP callback that will be called by [[send()]] when [[useFileTransport]] is true. * The callback should return a file name which will be used to save the email message. * If not set, the file name will be generated based on the current timestamp. * diff --git a/framework/validators/FilterValidator.php b/framework/validators/FilterValidator.php index 685faee990..06a52d9eee 100644 --- a/framework/validators/FilterValidator.php +++ b/framework/validators/FilterValidator.php @@ -31,7 +31,7 @@ use yii\base\InvalidConfigException; class FilterValidator extends Validator { /** - * @var callback the filter. This can be a global function name, anonymous function, etc. + * @var callable the filter. This can be a global function name, anonymous function, etc. * The function signature must be as follows, * * ~~~ diff --git a/framework/web/AccessControl.php b/framework/web/AccessControl.php index 4499f5ce81..c4b38e4dec 100644 --- a/framework/web/AccessControl.php +++ b/framework/web/AccessControl.php @@ -54,7 +54,7 @@ use yii\base\ActionFilter; class AccessControl extends ActionFilter { /** - * @var callback a callback that will be called if the access should be denied + * @var callable a callback that will be called if the access should be denied * to the current user. If not set, [[denyAccess()]] will be called. * * The signature of the callback should be as follows: diff --git a/framework/web/AccessRule.php b/framework/web/AccessRule.php index 7aeaac1652..eb1011646f 100644 --- a/framework/web/AccessRule.php +++ b/framework/web/AccessRule.php @@ -61,7 +61,7 @@ class AccessRule extends Component */ public $verbs; /** - * @var callback a callback that will be called to determine if the rule should be applied. + * @var callable a callback that will be called to determine if the rule should be applied. * The signature of the callback should be as follows: * * ~~~ @@ -73,7 +73,7 @@ class AccessRule extends Component */ public $matchCallback; /** - * @var callback a callback that will be called if this rule determines the access to + * @var callable a callback that will be called if this rule determines the access to * the current action should be denied. If not set, the behavior will be determined by * [[AccessControl]]. * diff --git a/framework/web/HttpCache.php b/framework/web/HttpCache.php index 134df71ec7..fd579981cf 100644 --- a/framework/web/HttpCache.php +++ b/framework/web/HttpCache.php @@ -46,7 +46,7 @@ use yii\base\Action; class HttpCache extends ActionFilter { /** - * @var callback a PHP callback that returns the UNIX timestamp of the last modification time. + * @var callable a PHP callback that returns the UNIX timestamp of the last modification time. * The callback's signature should be: * * ~~~ @@ -58,7 +58,7 @@ class HttpCache extends ActionFilter */ public $lastModified; /** - * @var callback a PHP callback that generates the Etag seed string. + * @var callable a PHP callback that generates the Etag seed string. * The callback's signature should be: * * ~~~