diff --git a/docs/auto-completion-static.php b/docs/auto-completion-static.php index b71415409..bb6e9c1d0 100755 --- a/docs/auto-completion-static.php +++ b/docs/auto-completion-static.php @@ -113,7 +113,7 @@ public static function until($name, $args = []) /** * Attach a handler to an event * - * @param string|array $name The name of event, or an array that the key is event name and the value is event hanlder + * @param string|array $name The name of event, or an associative array contains event name and event handler pairs * @param callable $fn The event handler * @param int $priority The event priority * @throws \InvalidArgumentException when the second argument is not callable @@ -238,7 +238,7 @@ class Password * Hash the password using the specified algorithm * * @param string $password The password to hash - * @return string|false The hashed password, or false on error. + * @return string|false the hashed password, or false on error * @throws \InvalidArgumentException * @see Password::hash */ @@ -259,7 +259,7 @@ public static function hash($password) * ) * * @param string $hash The password hash to extract info from - * @return array The array of information about the hash. + * @return array the array of information about the hash * @see Password::getInfo */ public static function getInfo($hash) @@ -272,7 +272,7 @@ public static function getInfo($hash) * If the answer is true, after validating the password using password_verify, rehash it. * * @param string $hash The hash to test - * @return boolean True if the password needs to be rehashed. + * @return bool true if the password needs to be rehashed * @see Password::needsRehash */ public static function needsRehash($hash) @@ -284,7 +284,7 @@ public static function needsRehash($hash) * * @param string $password The password to verify * @param string $hash The hash to verify against - * @return boolean If the password matches the hash + * @return bool If the password matches the hash * @see Password::verify */ public static function verify($password, $hash) @@ -340,6 +340,97 @@ class Session { } +class Share +{ + /** + * @param string $title + * @return $this + * @see Share::setTitle + */ + public static function setTitle($title) + { + } + + /** + * @return string + * @see Share::getTitle + */ + public static function getTitle() + { + } + + /** + * @param string $image + * @return $this + * @see Share::setImage + */ + public static function setImage($image) + { + } + + /** + * @return string + * @see Share::getImage + */ + public static function getImage() + { + } + + /** + * @param string $description + * @return Share + * @see Share::setDescription + */ + public static function setDescription($description) + { + } + + /** + * @return string + * @see Share::getDescription + */ + public static function getDescription() + { + } + + /** + * @param string $url + * @return Share + * @see Share::setUrl + */ + public static function setUrl($url) + { + } + + /** + * @return string + * @see Share::getUrl + */ + public static function getUrl() + { + } + + /** + * Returns share data as JSON + * + * @return string + * @see Share::toJson + */ + public static function toJson() + { + } + + /** + * Returns share data as JSON for WeChat + * + * @return string + * @see Share::toWechatJson + */ + public static function toWechatJson() + { + } +} + class Soap { } @@ -868,7 +959,7 @@ public function until($name, $args = []) /** * Attach a handler to an event * - * @param string|array $name The name of event, or an array that the key is event name and the value is event hanlder + * @param string|array $name The name of event, or an associative array contains event name and event handler pairs * @param callable $fn The event handler * @param int $priority The event priority * @throws \InvalidArgumentException when the second argument is not callable @@ -993,7 +1084,7 @@ class Password * Hash the password using the specified algorithm * * @param string $password The password to hash - * @return string|false The hashed password, or false on error. + * @return string|false the hashed password, or false on error * @throws \InvalidArgumentException * @see Password::hash */ @@ -1014,7 +1105,7 @@ public function hash($password) * ) * * @param string $hash The password hash to extract info from - * @return array The array of information about the hash. + * @return array the array of information about the hash * @see Password::getInfo */ public function getInfo($hash) @@ -1027,7 +1118,7 @@ public function getInfo($hash) * If the answer is true, after validating the password using password_verify, rehash it. * * @param string $hash The hash to test - * @return boolean True if the password needs to be rehashed. + * @return bool true if the password needs to be rehashed * @see Password::needsRehash */ public function needsRehash($hash) @@ -1039,7 +1130,7 @@ public function needsRehash($hash) * * @param string $password The password to verify * @param string $hash The hash to verify against - * @return boolean If the password matches the hash + * @return bool If the password matches the hash * @see Password::verify */ public function verify($password, $hash) @@ -1095,6 +1186,97 @@ class Session { } +class Share +{ + /** + * @param string $title + * @return $this + * @see Share::setTitle + */ + public function setTitle($title) + { + } + + /** + * @return string + * @see Share::getTitle + */ + public function getTitle() + { + } + + /** + * @param string $image + * @return $this + * @see Share::setImage + */ + public function setImage($image) + { + } + + /** + * @return string + * @see Share::getImage + */ + public function getImage() + { + } + + /** + * @param string $description + * @return Share + * @see Share::setDescription + */ + public function setDescription($description) + { + } + + /** + * @return string + * @see Share::getDescription + */ + public function getDescription() + { + } + + /** + * @param string $url + * @return Share + * @see Share::setUrl + */ + public function setUrl($url) + { + } + + /** + * @return string + * @see Share::getUrl + */ + public function getUrl() + { + } + + /** + * Returns share data as JSON + * + * @return string + * @see Share::toJson + */ + public function toJson() + { + } + + /** + * Returns share data as JSON for WeChat + * + * @return string + * @see Share::toWechatJson + */ + public function toWechatJson() + { + } +} + class Soap { } diff --git a/docs/auto-completion.php b/docs/auto-completion.php index f804b5ae8..298252700 100755 --- a/docs/auto-completion.php +++ b/docs/auto-completion.php @@ -309,6 +309,12 @@ class ServiceTraitMixin { class SessionMixin { } +/** + * @property Wei\Share $share A service contains share data + */ +class ShareMixin { +} + /** * @property Wei\Soap $soap A Soap client that works like HTTP service * @method Wei\Soap soap($options = []) Create a new Soap service and execute @@ -331,7 +337,7 @@ class TMixin { /** * @property Wei\TagCache $tagCache A cache service that support tagging - * @method Wei\TagCache tagCache($tag, $_ = null, $__ = null) Manager: Create a new cache service with tagging support + * @method Wei\TagCache tagCache($tag, $ignore1 = null, $ignore2 = null) Manager: Create a new cache service with tagging support */ class TagCacheMixin { } @@ -693,14 +699,14 @@ class IsLuhnMixin { /** * @property Wei\Validator\MaxLength $isMaxLength Check if the length (or size) of input is lower than specified length - * @method mixed isMaxLength($input, $max = null, $__ = null) + * @method mixed isMaxLength($input, $max = null, $ignore = null) */ class IsMaxLengthMixin { } /** * @property Wei\Validator\MinLength $isMinLength Check if the length (or size) of input is greater than specified length - * @method mixed isMinLength($input, $min = null, $__ = null) + * @method mixed isMinLength($input, $min = null, $ignore = null) */ class IsMinLengthMixin { } @@ -721,7 +727,7 @@ class IsNaturalNumberMixin { /** * @property Wei\Validator\NoneOf $isNoneOf Check if the input is NOT valid by all of specified rules - * @method mixed isNoneOf($input, $rules = [], $__ = null) + * @method mixed isNoneOf($input, $rules = [], $ignore = null) */ class IsNoneOfMixin { } @@ -927,6 +933,7 @@ class IsUuidMixin { * @mixin SchemaMixin * @mixin ServiceTraitMixin * @mixin SessionMixin + * @mixin ShareMixin * @mixin SoapMixin * @mixin StatsDMixin * @mixin TMixin diff --git a/lib/Share.php b/lib/Share.php new file mode 100644 index 000000000..c87608ee2 --- /dev/null +++ b/lib/Share.php @@ -0,0 +1,147 @@ +title = $title; + return $this; + } + + /** + * @return string + * @svc + */ + protected function getTitle() + { + return $this->title; + } + + /** + * @param string $image + * @return $this + * @svc + */ + protected function setImage($image) + { + $this->image = $image; + return $this; + } + + /** + * @return string + * @svc + */ + protected function getImage() + { + return $this->image; + } + + /** + * @param string $description + * @return Share + * @svc + */ + protected function setDescription($description) + { + $this->description = $description; + return $this; + } + + /** + * @return string + * @svc + */ + protected function getDescription() + { + return $this->description; + } + + /** + * @param string $url + * @return Share + * @svc + */ + protected function setUrl($url) + { + $this->url = $url; + return $this; + } + + /** + * @return string + * @svc + */ + protected function getUrl() + { + return $this->url; + } + + /** + * Returns share data as JSON + * + * @return string + * @svc + */ + protected function toJson() + { + return json_encode([ + 'title' => $this->title, + 'image' => $this->image, + 'description' => $this->description, + 'url' => $this->url, + ], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); + } + + /** + * Returns share data as JSON for WeChat + * + * @return string + * @svc + */ + protected function toWechatJson() + { + return json_encode([ + 'title' => $this->title, + 'desc' => $this->description, + 'link' => $this->url, + 'imgUrl' => $this->image, + ], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); + } +} diff --git a/tests/unit/ShareTest.php b/tests/unit/ShareTest.php new file mode 100644 index 000000000..ad324b9ed --- /dev/null +++ b/tests/unit/ShareTest.php @@ -0,0 +1,70 @@ +assertNull(Share::getTitle()); + + Share::setTitle('title'); + + $this->assertSame('title', Share::getTitle()); + } + + public function testUrl() + { + $this->assertNull(Share::getUrl()); + + Share::setUrl('url'); + + $this->assertSame('url', Share::getUrl()); + } + + public function testDescription() + { + $this->assertNull(Share::getDescription()); + + Share::setDescription('description'); + + $this->assertSame('description', Share::getDescription()); + } + + public function testImage() + { + $this->assertNull(Share::getImage()); + + Share::setImage('image'); + + $this->assertSame('image', Share::getImage()); + } + + public function testToJson() + { + Share::setTitle('title') + ->setUrl('url') + ->setDescription('description') + ->setImage('image'); + + $this->assertSame('{"title":"title","image":"image","description":"description","url":"url"}', Share::toJson()); + } + + public function testToWechatJson() + { + Share::setTitle('title') + ->setUrl('url') + ->setDescription('description') + ->setImage('image'); + + $this->assertSame( + '{"title":"title","desc":"description","link":"url","imgUrl":"image"}', + Share::toWechatJson() + ); + } +}