annotate vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Target.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 /*
Chris@0 4 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Chris@0 5 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Chris@0 6 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Chris@0 7 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
Chris@0 8 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
Chris@0 9 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Chris@0 10 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Chris@0 11 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Chris@0 12 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Chris@0 13 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Chris@0 14 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Chris@0 15 *
Chris@0 16 * This software consists of voluntary contributions made by many individuals
Chris@0 17 * and is licensed under the MIT license. For more information, see
Chris@0 18 * <http://www.doctrine-project.org>.
Chris@0 19 */
Chris@0 20
Chris@0 21 namespace Doctrine\Common\Annotations\Annotation;
Chris@0 22
Chris@0 23 /**
Chris@0 24 * Annotation that can be used to signal to the parser
Chris@0 25 * to check the annotation target during the parsing process.
Chris@0 26 *
Chris@0 27 * @author Fabio B. Silva <fabio.bat.silva@gmail.com>
Chris@0 28 *
Chris@0 29 * @Annotation
Chris@0 30 */
Chris@0 31 final class Target
Chris@0 32 {
Chris@0 33 const TARGET_CLASS = 1;
Chris@0 34 const TARGET_METHOD = 2;
Chris@0 35 const TARGET_PROPERTY = 4;
Chris@0 36 const TARGET_ANNOTATION = 8;
Chris@0 37 const TARGET_ALL = 15;
Chris@0 38
Chris@0 39 /**
Chris@0 40 * @var array
Chris@0 41 */
Chris@0 42 private static $map = array(
Chris@0 43 'ALL' => self::TARGET_ALL,
Chris@0 44 'CLASS' => self::TARGET_CLASS,
Chris@0 45 'METHOD' => self::TARGET_METHOD,
Chris@0 46 'PROPERTY' => self::TARGET_PROPERTY,
Chris@0 47 'ANNOTATION' => self::TARGET_ANNOTATION,
Chris@0 48 );
Chris@0 49
Chris@0 50 /**
Chris@0 51 * @var array
Chris@0 52 */
Chris@0 53 public $value;
Chris@0 54
Chris@0 55 /**
Chris@0 56 * Targets as bitmask.
Chris@0 57 *
Chris@0 58 * @var integer
Chris@0 59 */
Chris@0 60 public $targets;
Chris@0 61
Chris@0 62 /**
Chris@0 63 * Literal target declaration.
Chris@0 64 *
Chris@0 65 * @var integer
Chris@0 66 */
Chris@0 67 public $literal;
Chris@0 68
Chris@0 69 /**
Chris@0 70 * Annotation constructor.
Chris@0 71 *
Chris@0 72 * @param array $values
Chris@0 73 *
Chris@0 74 * @throws \InvalidArgumentException
Chris@0 75 */
Chris@0 76 public function __construct(array $values)
Chris@0 77 {
Chris@0 78 if (!isset($values['value'])){
Chris@0 79 $values['value'] = null;
Chris@0 80 }
Chris@0 81 if (is_string($values['value'])){
Chris@0 82 $values['value'] = array($values['value']);
Chris@0 83 }
Chris@0 84 if (!is_array($values['value'])){
Chris@0 85 throw new \InvalidArgumentException(
Chris@0 86 sprintf('@Target expects either a string value, or an array of strings, "%s" given.',
Chris@0 87 is_object($values['value']) ? get_class($values['value']) : gettype($values['value'])
Chris@0 88 )
Chris@0 89 );
Chris@0 90 }
Chris@0 91
Chris@0 92 $bitmask = 0;
Chris@0 93 foreach ($values['value'] as $literal) {
Chris@0 94 if(!isset(self::$map[$literal])){
Chris@0 95 throw new \InvalidArgumentException(
Chris@0 96 sprintf('Invalid Target "%s". Available targets: [%s]',
Chris@0 97 $literal, implode(', ', array_keys(self::$map)))
Chris@0 98 );
Chris@0 99 }
Chris@0 100 $bitmask |= self::$map[$literal];
Chris@0 101 }
Chris@0 102
Chris@0 103 $this->targets = $bitmask;
Chris@0 104 $this->value = $values['value'];
Chris@0 105 $this->literal = implode(', ', $this->value);
Chris@0 106 }
Chris@0 107 }