PK SGP
LICENSE.mdnu W+A Copyright (c) 2019-2020, Laminas Foundation
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- Neither the name of Laminas Foundation nor the names of its contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
PK SGP%'\ \ COPYRIGHT.mdnu W+A Copyright (c) 2019-2020, Laminas Foundation.
All rights reserved. (https://getlaminas.org/)
PK SGPAé .travis.ymlnu W+A language: php
cache:
directories:
- $HOME/.composer/cache
env:
global:
- COMPOSER_ARGS="--no-interaction"
- COVERAGE_DEPS="php-coveralls/php-coveralls"
matrix:
fast_finish: true
include:
- php: 5.6
env:
- DEPS=lowest
- php: 5.6
env:
- DEPS=latest
- php: 7
env:
- DEPS=lowest
- php: 7
env:
- DEPS=latest
- php: 7.1
env:
- DEPS=lowest
- php: 7.1
env:
- DEPS=latest
- CS_CHECK=true
- TEST_COVERAGE=true
- php: 7.2
env:
- DEPS=lowest
- php: 7.2
env:
- DEPS=latest
- php: 7.3
env:
- DEPS=lowest
- php: 7.3
env:
- DEPS=latest
before_install:
- if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
install:
- travis_retry composer install $COMPOSER_ARGS --ignore-platform-reqs
- if [[ $LEGACY_DEPS != '' ]]; then travis_retry composer update $COMPOSER_ARGS --with-dependencies $LEGACY_DEPS ; fi
- if [[ $DEPS == 'latest' ]]; then travis_retry composer update $COMPOSER_ARGS ; fi
- if [[ $DEPS == 'lowest' ]]; then travis_retry composer update --prefer-lowest --prefer-stable $COMPOSER_ARGS ; fi
- if [[ $TEST_COVERAGE == 'true' ]]; then travis_retry composer require --dev $COMPOSER_ARGS $COVERAGE_DEPS ; fi
- stty cols 120 && composer show
script:
- if [[ $TEST_COVERAGE == 'true' ]]; then composer test-coverage ; else composer test ; fi
- if [[ $CS_CHECK == 'true' ]]; then composer cs-check ; fi
after_script:
- if [[ $TEST_COVERAGE == 'true' ]]; then travis_retry php vendor/bin/php-coveralls -v ; fi
notifications:
email: false
PK SGPx= = .coveralls.ymlnu W+A coverage_clover: clover.xml
json_path: coveralls-upload.json
PK SGP}CC phpcs.xmlnu W+A
src
test
PK SGPoq README.mdnu W+A # laminas-tag
[![Build Status](https://travis-ci.com/laminas/laminas-tag.svg?branch=master)](https://travis-ci.com/laminas/laminas-tag)
[![Coverage Status](https://coveralls.io/repos/github/laminas/laminas-tag/badge.svg?branch=master)](https://coveralls.io/github/laminas/laminas-tag?branch=master)
`Laminas\Tag` is a component suite which provides a facility to work with taggable
Items. As its base, it provides two classes to work with Tags, `Laminas\Tag\Item`
and `Laminas\Tag\ItemList`. Additionally, it comes with the interface
`Laminas\Tag\TaggableInterface`, which allows you to use any of your models as a
taggable item in conjunction with `Laminas\Tag`.
- File issues at https://github.com/laminas/laminas-tag/issues
- Documentation is at https://docs.laminas.dev/laminas-tag/
PK SGP@ݫ
.gitignorenu W+A /clover.xml
/composer.lock
/coveralls-upload.json
/docs/html/
/laminas-mkdoc-theme.tgz
/laminas-mkdoc-theme/
/phpunit.xml
/vendor/
PK SGPbR/ $ src/Exception/ExceptionInterface.phpnu W+A items);
}
/**
* Spread values in the items relative to their weight
*
* @param array $values
* @throws InvalidArgumentException When value list is empty
* @return void
*/
public function spreadWeightValues(array $values)
{
// Don't allow an empty value list
if (count($values) === 0) {
throw new InvalidArgumentException('Value list may not be empty');
}
// Re-index the array
$values = array_values($values);
// If just a single value is supplied simply assign it to to all tags
if (count($values) === 1) {
foreach ($this->items as $item) {
$item->setParam('weightValue', $values[0]);
}
} else {
// Calculate min- and max-weight
$minWeight = null;
$maxWeight = null;
foreach ($this->items as $item) {
if ($minWeight === null && $maxWeight === null) {
$minWeight = $item->getWeight();
$maxWeight = $item->getWeight();
} else {
$minWeight = min($minWeight, $item->getWeight());
$maxWeight = max($maxWeight, $item->getWeight());
}
}
// Calculate the thresholds
$steps = count($values);
$delta = ($maxWeight - $minWeight) / ($steps - 1);
$thresholds = [];
for ($i = 0; $i < $steps; $i++) {
$thresholds[$i] = floor(100 * log(($minWeight + $i * $delta) + 2));
}
// Then assign the weight values
foreach ($this->items as $item) {
$threshold = floor(100 * log($item->getWeight() + 2));
for ($i = 0; $i < $steps; $i++) {
if ($threshold <= $thresholds[$i]) {
$item->setParam('weightValue', $values[$i]);
break;
}
}
}
}
}
/**
* Seek to an absolute position
*
* @param int $index
* @throws OutOfBoundsException When the seek position is invalid
* @return void
*/
public function seek($index)
{
$this->rewind();
$position = 0;
while ($position < $index && $this->valid()) {
$this->next();
$position++;
}
if (! $this->valid()) {
throw new OutOfBoundsException('Invalid seek position');
}
}
/**
* Return the current element
*
* @return mixed
*/
public function current()
{
return current($this->items);
}
/**
* Move forward to next element
*
* @return mixed
*/
public function next()
{
return next($this->items);
}
/**
* Return the key of the current element
*
* @return mixed
*/
public function key()
{
return key($this->items);
}
/**
* Check if there is a current element after calls to rewind() or next()
*
* @return bool
*/
public function valid()
{
return ($this->current() !== false);
}
/**
* Rewind the Iterator to the first element
*
* @return void
*/
public function rewind()
{
reset($this->items);
}
/**
* Check if an offset exists
*
* @param mixed $offset
* @return bool
*/
public function offsetExists($offset)
{
return array_key_exists($offset, $this->items);
}
/**
* Get the value of an offset
*
* @param mixed $offset
* @return TaggableInterface
*/
public function offsetGet($offset)
{
return $this->items[$offset];
}
/**
* Append a new item
*
* @param mixed $offset
* @param TaggableInterface $item
* @throws OutOfBoundsException When item does not implement Laminas\Tag\TaggableInterface
* @return void
*/
public function offsetSet($offset, $item)
{
// We need to make that check here, as the method signature must be
// compatible with ArrayAccess::offsetSet()
if (! ($item instanceof TaggableInterface)) {
throw new OutOfBoundsException('Item must implement Laminas\Tag\TaggableInterface');
}
if ($offset === null) {
$this->items[] = $item;
} else {
$this->items[$offset] = $item;
}
}
/**
* Unset an item
*
* @param mixed $offset
* @return void
*/
public function offsetUnset($offset)
{
unset($this->items[$offset]);
}
}
PK SGP % src/Cloud/Decorator/AbstractCloud.phpnu W+A setOptions($options);
}
}
/**
* Set options from array
*
* @param array $options Configuration for the decorator
* @return AbstractTag
*/
public function setOptions(array $options)
{
foreach ($options as $key => $value) {
if (in_array(strtolower($key), $this->skipOptions)) {
continue;
}
$method = 'set' . $key;
if (method_exists($this, $method)) {
$this->$method($value);
}
}
return $this;
}
/**
* Get encoding
*
* @return string
*/
public function getEncoding()
{
return $this->encoding;
}
/**
* Set encoding
*
* @param string
* @return HTMLCloud
*/
public function setEncoding($value)
{
$this->encoding = (string) $value;
return $this;
}
/**
* Set Escaper instance
*
* @param Escaper $escaper
* @return HtmlCloud
*/
public function setEscaper($escaper)
{
$this->escaper = $escaper;
return $this;
}
/**
* Retrieve Escaper instance
*
* If none registered, instantiates and registers one using current encoding.
*
* @return Escaper
*/
public function getEscaper()
{
if (null === $this->escaper) {
$this->setEscaper(new Escaper($this->getEncoding()));
}
return $this->escaper;
}
/**
* Validate an HTML element name
*
* @param string $name
* @throws Exception\InvalidElementNameException
*/
protected function validateElementName($name)
{
if (! preg_match('/^[a-z0-9]+$/i', $name)) {
throw new Exception\InvalidElementNameException(sprintf(
'%s: Invalid element name "%s" provided; please provide valid HTML element names',
__METHOD__,
$this->getEscaper()->escapeHtml($name)
));
}
}
/**
* Validate an HTML attribute name
*
* @param string $name
* @throws Exception\InvalidAttributeNameException
*/
protected function validateAttributeName($name)
{
if (! preg_match('/^[a-z_:][-a-z0-9_:.]*$/i', $name)) {
throw new Exception\InvalidAttributeNameException(sprintf(
'%s: Invalid HTML attribute name "%s" provided; please provide valid HTML attribute names',
__METHOD__,
$this->getEscaper()->escapeHtml($name)
));
}
}
/**
* Wrap html with tag
*
* @param string $html
* @return string
*/
protected function wrapTag($html)
{
$escaper = $this->getEscaper();
foreach ($this->getHTMLTags() as $key => $data) {
if (is_array($data)) {
$attributes = '';
$htmlTag = $key;
$this->validateElementName($htmlTag);
foreach ($data as $param => $value) {
$this->validateAttributeName($param);
$attributes .= ' ' . $param . '="' . $escaper->escapeHtmlAttr($value) . '"';
}
} else {
$attributes = '';
$htmlTag = $data;
$this->validateElementName($htmlTag);
}
$html = sprintf('<%1$s%3$s>%2$s%1$s>', $htmlTag, $html, $attributes);
}
return $html;
}
}
PK SGPT- # src/Cloud/Decorator/AbstractTag.phpnu W+A ['class' => 'laminas-tag-cloud'],
];
/**
* Separator for the single tags
*
* @var string
*/
protected $separator = ' ';
/**
* Set the HTML tags surrounding all tags
*
* @param array $htmlTags
* @return HTMLCloud
*/
public function setHTMLTags(array $htmlTags)
{
$this->htmlTags = $htmlTags;
return $this;
}
/**
* Retrieve HTML tag map
*
* @return array
*/
public function getHTMLTags()
{
return $this->htmlTags;
}
/**
* Set the separator between the single tags
*
* @param string
* @return HTMLCloud
*/
public function setSeparator($separator)
{
$this->separator = $separator;
return $this;
}
/**
* Get tag separator
*
* @return string
*/
public function getSeparator()
{
return $this->separator;
}
/**
* Defined by Laminas\Tag\Cloud\Decorator\Cloud
*
* @param array $tags
* @throws Exception\InvalidArgumentException
* @return string
*/
public function render($tags)
{
if (! is_array($tags)) {
throw new Exception\InvalidArgumentException(sprintf(
'HtmlCloud::render() expects an array argument; received "%s"',
(is_object($tags) ? get_class($tags) : gettype($tags))
));
}
$cloudHTML = implode($this->getSeparator(), $tags);
$cloudHTML = $this->wrapTag($cloudHTML);
return $cloudHTML;
}
}
PK SGP( ( src/Cloud/Decorator/HtmlTag.phpnu W+A classList = $classList;
return $this;
}
/**
* Get class list
*
* @return array
*/
public function getClassList()
{
return $this->classList;
}
/**
* Set the font size unit
*
* Possible values are: em, ex, px, in, cm, mm, pt, pc and %
*
* @param string $fontSizeUnit
* @throws InvalidArgumentException When an invalid fontsize unit is specified
* @return HTMLTag
*/
public function setFontSizeUnit($fontSizeUnit)
{
if (! in_array($fontSizeUnit, $this->allowedFontSizeUnits)) {
throw new InvalidArgumentException('Invalid fontsize unit specified');
}
$this->fontSizeUnit = (string) $fontSizeUnit;
$this->setClassList(null);
return $this;
}
/**
* Retrieve font size unit
*
* @return string
*/
public function getFontSizeUnit()
{
return $this->fontSizeUnit;
}
/**
* Set the HTML tags surrounding the element
*
* @param array $htmlTags
* @return HTMLTag
*/
public function setHTMLTags(array $htmlTags)
{
$this->htmlTags = $htmlTags;
return $this;
}
/**
* Get HTML tags map
*
* @return array
*/
public function getHTMLTags()
{
return $this->htmlTags;
}
/**
* Set maximum font size
*
* @param int $maxFontSize
* @throws InvalidArgumentException When fontsize is not numeric
* @return HTMLTag
*/
public function setMaxFontSize($maxFontSize)
{
if (! is_numeric($maxFontSize)) {
throw new InvalidArgumentException('Fontsize must be numeric');
}
$this->maxFontSize = (int) $maxFontSize;
$this->setClassList(null);
return $this;
}
/**
* Retrieve maximum font size
*
* @return int
*/
public function getMaxFontSize()
{
return $this->maxFontSize;
}
/**
* Set minimum font size
*
* @param int $minFontSize
* @throws InvalidArgumentException When fontsize is not numeric
* @return HTMLTag
*/
public function setMinFontSize($minFontSize)
{
if (! is_numeric($minFontSize)) {
throw new InvalidArgumentException('Fontsize must be numeric');
}
$this->minFontSize = (int) $minFontSize;
$this->setClassList(null);
return $this;
}
/**
* Retrieve minimum font size
*
* @return int
*/
public function getMinFontSize()
{
return $this->minFontSize;
}
/**
* Defined by Tag
*
* @param ItemList $tags
* @throws InvalidArgumentException
* @return array
*/
public function render($tags)
{
if (! $tags instanceof ItemList) {
throw new InvalidArgumentException(sprintf(
'HtmlTag::render() expects a Laminas\Tag\ItemList argument; received "%s"',
(is_object($tags) ? get_class($tags) : gettype($tags))
));
}
if (null === ($weightValues = $this->getClassList())) {
$weightValues = range($this->getMinFontSize(), $this->getMaxFontSize());
}
$tags->spreadWeightValues($weightValues);
$result = [];
$escaper = $this->getEscaper();
foreach ($tags as $tag) {
if (null === ($classList = $this->getClassList())) {
$attribute = sprintf(
'style="font-size: %d%s;"',
$tag->getParam('weightValue'),
$this->getFontSizeUnit()
);
} else {
$attribute = sprintf('class="%s"', $escaper->escapeHtmlAttr($tag->getParam('weightValue')));
}
$tagHTML = sprintf(
'%s',
$escaper->escapeHtml($tag->getParam('url')),
$attribute,
$escaper->escapeHtml($tag->getTitle())
);
$tagHTML = $this->wrapTag($tagHTML);
$result[] = $tagHTML;
}
return $result;
}
}
PK SGP4ɹ $ src/Cloud/DecoratorPluginManager.phpnu W+A Decorator\HtmlCloud::class,
'htmlCloud' => Decorator\HtmlCloud::class,
'Htmlcloud' => Decorator\HtmlCloud::class,
'HtmlCloud' => Decorator\HtmlCloud::class,
'htmltag' => Decorator\HtmlTag::class,
'htmlTag' => Decorator\HtmlTag::class,
'Htmltag' => Decorator\HtmlTag::class,
'HtmlTag' => Decorator\HtmlTag::class,
'tag' => Decorator\HtmlTag::class,
'Tag' => Decorator\HtmlTag::class,
// Legacy Zend Framework aliases
\Zend\Tag\Cloud\Decorator\HtmlCloud::class => Decorator\HtmlCloud::class,
\Zend\Tag\Cloud\Decorator\HtmlTag::class => Decorator\HtmlTag::class,
// v2 normalized FQCNs
'zendtagclouddecoratorhtmlcloud' => Decorator\HtmlCloud::class,
'zendtagclouddecoratorhtmltag' => Decorator\HtmlTag::class,
];
protected $factories = [
Decorator\HtmlCloud::class => InvokableFactory::class,
Decorator\HtmlTag::class => InvokableFactory::class,
// Legacy (v2) due to alias resolution; canonical form of resolved
// alias is used to look up the factory, while the non-normalized
// resolved alias is used as the requested name passed to the factory.
'laminastagclouddecoratorhtmlcloud' => InvokableFactory::class,
'laminastagclouddecoratorhtmltag' => InvokableFactory::class
];
protected $instanceOf = Decorator\DecoratorInterface::class;
/**
* Validate the plugin is of the expected type (v3).
*
* Validates against `$instanceOf`.
*
* @param mixed $instance
* @throws InvalidServiceException
*/
public function validate($instance)
{
if (! $instance instanceof $this->instanceOf) {
throw new InvalidServiceException(sprintf(
'%s can only create instances of %s; %s is invalid',
get_class($this),
$this->instanceOf,
(is_object($instance) ? get_class($instance) : gettype($instance))
));
}
}
/**
* Validate the plugin is of the expected type (v2).
*
* Proxies to `validate()`.
*
* @param mixed $instance
* @throws InvalidServiceException
*/
public function validatePlugin($instance)
{
try {
$this->validate($instance);
} catch (InvalidServiceException $e) {
throw new RuntimeException($e->getMessage(), $e->getCode(), $e);
}
}
}
PK SGPCKF F src/Item.phpnu W+A setOptions($options);
if ($this->title === null) {
throw new Exception\InvalidArgumentException('Title was not set');
}
if ($this->weight === null) {
throw new Exception\InvalidArgumentException('Weight was not set');
}
}
/**
* Set options of the tag
*
* @param array $options
* @return \Laminas\Tag\Item
*/
public function setOptions(array $options)
{
foreach ($options as $key => $value) {
if (in_array(strtolower($key), $this->skipOptions)) {
continue;
}
$method = 'set' . $key;
if (method_exists($this, $method)) {
$this->$method($value);
}
}
return $this;
}
/**
* Defined by Laminas\Tag\TaggableInterface
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set the title
*
* @param string $title
* @throws \Laminas\Tag\Exception\InvalidArgumentException When title is no string
* @return \Laminas\Tag\Item
*/
public function setTitle($title)
{
if (! is_string($title)) {
throw new Exception\InvalidArgumentException('Title must be a string');
}
$this->title = (string) $title;
return $this;
}
/**
* Defined by Laminas\Tag\TaggableInterface
*
* @return float
*/
public function getWeight()
{
return $this->weight;
}
/**
* Set the weight
*
* @param float $weight
* @throws \Laminas\Tag\Exception\InvalidArgumentException When weight is not numeric
* @return \Laminas\Tag\Item
*/
public function setWeight($weight)
{
if (! is_numeric($weight)) {
throw new Exception\InvalidArgumentException('Weight must be numeric');
}
$this->weight = (float) $weight;
return $this;
}
/**
* Set multiple params at once
*
* @param array $params
* @return \Laminas\Tag\Item
*/
public function setParams(array $params)
{
foreach ($params as $name => $value) {
$this->setParam($name, $value);
}
return $this;
}
/**
* Defined by Laminas\Tag\TaggableInterface
*
* @param string $name
* @param mixed $value
* @return \Laminas\Tag\Item
*/
public function setParam($name, $value)
{
$this->params[$name] = $value;
return $this;
}
/**
* Defined by Laminas\Tag\TaggableInterface
*
* @param string $name
* @return mixed
*/
public function getParam($name)
{
if (isset($this->params[$name])) {
return $this->params[$name];
}
return;
}
}
PK SGPR$? ? src/TaggableInterface.phpnu W+A setOptions($options);
}
}
/**
* Set options from array
*
* @param array $options Configuration for Cloud
* @return Cloud
*/
public function setOptions(array $options)
{
foreach ($options as $key => $value) {
if (in_array(strtolower($key), $this->skipOptions)) {
continue;
}
$method = 'set' . $key;
if (method_exists($this, $method)) {
$this->$method($value);
}
}
return $this;
}
/**
* Set the tags for the tag cloud.
*
* $tags should be an array containing single tags as array. Each tag
* array should at least contain the keys 'title' and 'weight'. Optionally
* you may supply the key 'url', to which the tag links to. Any additional
* parameter in the array is silently ignored and can be used by custom
* decorators.
*
* @param array $tags
* @throws Exception\InvalidArgumentException
* @return Cloud
*/
public function setTags(array $tags)
{
foreach ($tags as $tag) {
$this->appendTag($tag);
}
return $this;
}
/**
* Append a single tag to the cloud
*
* @param TaggableInterface|array $tag
* @throws Exception\InvalidArgumentException
* @return Cloud
*/
public function appendTag($tag)
{
$tags = $this->getItemList();
if ($tag instanceof TaggableInterface) {
$tags[] = $tag;
return $this;
}
if (! is_array($tag)) {
throw new Exception\InvalidArgumentException(sprintf(
'Tag must be an instance of %s\TaggableInterface or an array; received "%s"',
__NAMESPACE__,
(is_object($tag) ? get_class($tag) : gettype($tag))
));
}
$tags[] = new Item($tag);
return $this;
}
/**
* Set the item list
*
* @param ItemList $itemList
* @return Cloud
*/
public function setItemList(ItemList $itemList)
{
$this->tags = $itemList;
return $this;
}
/**
* Retrieve the item list
*
* If item list is undefined, creates one.
*
* @return ItemList
*/
public function getItemList()
{
if (null === $this->tags) {
$this->setItemList(new ItemList());
}
return $this->tags;
}
/**
* Set the decorator for the cloud
*
* @param mixed $decorator
* @throws Exception\InvalidArgumentException
* @return Cloud
*/
public function setCloudDecorator($decorator)
{
$options = null;
if (is_array($decorator)) {
if (isset($decorator['options'])) {
$options = $decorator['options'];
}
if (isset($decorator['decorator'])) {
$decorator = $decorator['decorator'];
}
}
if (is_string($decorator)) {
$decorator = $this->getDecoratorPluginManager()->get($decorator, $options);
}
if (! ($decorator instanceof Cloud\Decorator\AbstractCloud)) {
throw new Exception\InvalidArgumentException(
'DecoratorInterface is no instance of Cloud\Decorator\AbstractCloud'
);
}
$this->cloudDecorator = $decorator;
return $this;
}
/**
* Get the decorator for the cloud
*
* @return Cloud\Decorator\AbstractCloud
*/
public function getCloudDecorator()
{
if (null === $this->cloudDecorator) {
$this->setCloudDecorator(HtmlCloud::class);
}
return $this->cloudDecorator;
}
/**
* Set the decorator for the tags
*
* @param mixed $decorator
* @throws Exception\InvalidArgumentException
* @return Cloud
*/
public function setTagDecorator($decorator)
{
$options = null;
if (is_array($decorator)) {
if (isset($decorator['options'])) {
$options = $decorator['options'];
}
if (isset($decorator['decorator'])) {
$decorator = $decorator['decorator'];
}
}
if (is_string($decorator)) {
$decorator = $this->getDecoratorPluginManager()->get($decorator, $options);
}
if (! ($decorator instanceof Cloud\Decorator\AbstractTag)) {
throw new Exception\InvalidArgumentException(
'DecoratorInterface is no instance of Cloud\Decorator\AbstractTag'
);
}
$this->tagDecorator = $decorator;
return $this;
}
/**
* Get the decorator for the tags
*
* @return Cloud\Decorator\AbstractTag
*/
public function getTagDecorator()
{
if (null === $this->tagDecorator) {
$this->setTagDecorator(HtmlTag::class);
}
return $this->tagDecorator;
}
/**
* Set plugin manager for use with decorators
*
* @param Cloud\DecoratorPluginManager $decorators
* @return Cloud
*/
public function setDecoratorPluginManager(Cloud\DecoratorPluginManager $decorators)
{
$this->decorators = $decorators;
return $this;
}
/**
* Get the plugin manager for decorators
*
* @return Cloud\DecoratorPluginManager
*/
public function getDecoratorPluginManager()
{
if ($this->decorators === null) {
$this->decorators = new Cloud\DecoratorPluginManager(new ServiceManager());
}
return $this->decorators;
}
/**
* Render the tag cloud
*
* @return string
*/
public function render()
{
$tags = $this->getItemList();
if (count($tags) === 0) {
return '';
}
$tagsResult = $this->getTagDecorator()->render($tags);
$cloudResult = $this->getCloudDecorator()->render($tagsResult);
return $cloudResult;
}
/**
* Render the tag cloud
*
* @return string
*/
public function __toString()
{
try {
$result = $this->render();
return $result;
} catch (\Exception $e) {
$message = "Exception caught by tag cloud: " . $e->getMessage()
. "\nStack Trace:\n" . $e->getTraceAsString();
trigger_error($message, E_USER_WARNING);
return '';
}
}
}
PK SGP5*r
mkdocs.ymlnu W+A docs_dir: docs/book
site_dir: docs/html
nav:
- Home: index.md
- "Quick Start": quick-start.md
- "Tag Clouds": tag-cloud.md
site_name: laminas-tag
site_description: Laminas\Tag
repo_url: 'https://github.com/laminas/laminas-tag'
extra:
project: Components
PK SGP"y4 4 .github/workflows/docs-build.ymlnu W+A name: docs-build
on:
push:
branches:
- master
repository_dispatch:
jobs:
build-deploy:
runs-on: ubuntu-latest
steps:
- name: Build Docs
uses: laminas/documentation-theme/github-actions/docs@master
env:
DOCS_DEPLOY_KEY: ${{ secrets.DOCS_DEPLOY_KEY }}
PK SGPtl .gitattributesnu W+A /.coveralls.yml export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/docs/ export-ignore
/mkdocs.yml export-ignore
/phpcs.xml export-ignore
/phpunit.xml.dist export-ignore
/test/ export-ignore
PK SGPٽŚ test/ItemTest.phpnu W+A 'foo',
'weight' => 10,
'params' => [
'bar' => 'baz'
]
]);
$this->assertEquals('foo', $tag->getTitle());
$this->assertEquals(10, $tag->getWeight());
$this->assertEquals('baz', $tag->getParam('bar'));
}
public function testSetOptions()
{
$tag = new Tag\Item(['title' => 'foo', 'weight' => 1]);
$tag->setOptions([
'title' => 'bar',
'weight' => 10,
'params' => [
'bar' => 'baz'
]
]);
$this->assertEquals('bar', $tag->getTitle());
$this->assertEquals(10, $tag->getWeight());
$this->assertEquals('baz', $tag->getParam('bar'));
}
public function testSetParam()
{
$tag = new Tag\Item(['title' => 'foo', 'weight' => 1]);
$tag->setParam('bar', 'baz');
$this->assertEquals('baz', $tag->getParam('bar'));
}
public function testSetTitle()
{
$tag = new Tag\Item(['title' => 'foo', 'weight' => 1]);
$tag->setTitle('baz');
$this->assertEquals('baz', $tag->getTitle());
}
public function testInvalidTitle()
{
$this->expectException('\Laminas\Tag\Exception\InvalidArgumentException');
$this->expectExceptionMessage('Title must be a string');
$tag = new Tag\Item(['title' => 10, 'weight' => 1]);
}
public function testSetWeight()
{
$tag = new Tag\Item(['title' => 'foo', 'weight' => 1]);
$tag->setWeight('10');
$this->assertEquals(10.0, $tag->getWeight());
$this->assertInternalType('float', $tag->getWeight());
}
public function testInvalidWeight()
{
$this->expectException('\Laminas\Tag\Exception\InvalidArgumentException');
$this->expectExceptionMessage('Weight must be numeric');
$tag = new Tag\Item(['title' => 'foo', 'weight' => 'foobar']);
}
public function testSkipOptions()
{
$tag = new Tag\Item(['title' => 'foo', 'weight' => 1, 'param' => 'foobar']);
// In case would fail due to an error
}
public function testInvalidOptions()
{
$this->expectException('\Laminas\Tag\Exception\InvalidArgumentException');
$this->expectExceptionMessage('Invalid options provided to constructor');
$tag = new Tag\Item('test');
}
public function testMissingTitle()
{
$this->expectException('\Laminas\Tag\Exception\InvalidArgumentException');
$this->expectExceptionMessage('Title was not set');
$tag = new Tag\Item(['weight' => 1]);
}
public function testMissingWeight()
{
$this->expectException('\Laminas\Tag\Exception\InvalidArgumentException');
$this->expectExceptionMessage('Weight was not set');
$tag = new Tag\Item(['title' => 'foo']);
}
/**
* This test uses ArrayObject, which will have essentially the
* same behavior as Laminas\Config\Config; the code is looking only
* for a Traversable.
*/
public function testConfigOptions()
{
$tag = new Tag\Item(new ArrayObject(['title' => 'foo', 'weight' => 1]));
$this->assertEquals($tag->getTitle(), 'foo');
$this->assertEquals($tag->getWeight(), 1);
}
public function testGetNonSetParam()
{
$tag = new Tag\Item(['title' => 'foo', 'weight' => 1]);
$this->assertNull($tag->getParam('foo'));
}
}
PK SGPvVq q $ test/Cloud/TestAsset/CloudDummy1.phpnu W+A _foo = $value;
}
public function getFoo()
{
return $this->_foo;
}
}
PK SGPp p # test/Cloud/TestAsset/CloudDummy.phpnu W+A _foo = $value;
}
public function getFoo()
{
return $this->_foo;
}
}
PK SGP\m &