/** * @return bool * @author Andreas Glaser */ public function supports() { $eehClassFullyQualified = get_called_class(); if (!StringHelper::endsWith($eehClassFullyQualified, 'EEH')) { return false; } $eehClass = substr($eehClassFullyQualified, strrpos($eehClassFullyQualified, '\\') + 1, -3); $entityClassFullyQualified = get_class($this->entity); $entityClass = substr($entityClassFullyQualified, strrpos($entityClassFullyQualified, '\\') + 1); return $eehClass === $entityClass; }
/** * @param $entityClass * * @return null|string * @throws \Exception * @author Andreas Glaser */ public static function get($entityClass) { $className = get_class($entityClass); // translate proxy classes if (StringHelper::startsWith($className, 'Proxies\\__CG__\\')) { $entityClass = substr($className, strlen('Proxies\\__CG__\\')); } $reader = new AnnotationReader(); $apiMetaAnnotation = $reader->getClassAnnotation(new \ReflectionClass(new $entityClass()), 'AndreasGlaser\\DCEventBundle\\EventHandler\\Annotations\\DCEntityEventHandler'); if (!$apiMetaAnnotation || !$apiMetaAnnotation->class) { return null; } if (!class_exists($apiMetaAnnotation->class)) { throw new \Exception(sprintf('DCEntityEventHandler class %s does not exist', $apiMetaAnnotation->class)); } return $apiMetaAnnotation->class; }
/** * Adds class. * * @param $name * * @return $this * * @author Andreas Glaser */ public function addClass($name) { $classes = StringHelper::explodeAndTrim(' ', $name); foreach ($classes as $className) { $this->classes[$className] = $className; } return $this; }
/** * Replaces values of an array. * * @param array $array * @param $value * @param $replacement * @param bool|true $recursively * @param bool|true $caseSensitive * * @return array * @author Andreas Glaser */ public static function replaceValue(array $array, $value, $replacement, $recursively = true, $caseSensitive = true) { foreach ($array as $k => $v) { if ($recursively && is_array($v)) { $array[$k] = self::replaceValue($array[$k], $value, $replacement, $recursively, $caseSensitive); } elseif (is_string($v) && StringHelper::is($v, $value, $caseSensitive)) { $array[$k] = $replacement; } } return $array; }
/** * @param $scope * * @return $this * @throws \Exception * @author Andreas Glaser * * @deprecated Not supported in HTML5. http://www.w3schools.com/tags/att_td_scope.asp */ public function setScope($scope) { $validScopes = ['col', 'row', 'colgroup', 'rowgroup']; if (!StringHelper::isOneOf($scope, $validScopes)) { throw new \Exception(sprintf('"%s" is not a valid <td> scope. Valid are: %s', $scope, implode(', ', $validScopes))); } $this->attributes->set('scope', $scope); return $this; }
/** * @author Andreas Glaser */ public function testIsBlank() { $this->assertTrue(StringHelper::isBlank(' ')); $this->assertTrue(StringHelper::isBlank(' ')); $this->assertTrue(StringHelper::isBlank(null)); $this->assertFalse(StringHelper::isBlank('a')); $this->assertFalse(StringHelper::isBlank(' a ')); $this->assertFalse(StringHelper::isBlank(0)); }