示例#1
0
 /**
  * Check and return the Id of an Identifable Element
  *
  * @param Identifiable $element Identifable element
  * @return string
  */
 public static function check(Identifiable $element)
 {
     $elementId = $element->getId();
     if (!$elementId) {
         $element->setId(new static());
         return $element->getId();
     }
     $dangerousCharacters = array(' ', '|', PHP_EOL);
     $danger = false;
     foreach ($dangerousCharacters as $dangerousCharacter) {
         if (stripos($elementId, $dangerousCharacter) !== false) {
             $danger = true;
             break;
         }
     }
     if ($danger) {
         trigger_error("Don't use special characters in IDs, they might cause problems! Stripping them for you...");
         $elementId = str_ireplace($dangerousCharacters, '', $elementId);
         $element->setId($elementId);
     }
     return $element->getId();
 }
示例#2
0
 /**
  * Get the escaped Id of the given Element
  *
  * @param Identifiable $element Element
  * @return string
  */
 public static function getId(Identifiable $element)
 {
     return static::escapeText($element->getId(), false);
 }