本文整理汇总了PHP中ClassInfo::class_name方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassInfo::class_name方法的具体用法?PHP ClassInfo::class_name怎么用?PHP ClassInfo::class_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ClassInfo
的用法示例。
在下文中一共展示了ClassInfo::class_name方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: assertException
/**
* @param callable $callback
* @param string $expectedException
* @param null $expectedCode
* @param null $expectedMessage
* @author VladaHejda
*/
public static function assertException(callable $callback, $expectedException = 'Exception', $expectedCode = null, $expectedMessage = null)
{
$self = new SapphireTest();
if (!ClassInfo::exists($expectedException)) {
$self->fail(sprintf('An exception of type "%s" does not exist.', $expectedException));
}
try {
$callback();
} catch (\Exception $e) {
$class = ClassInfo::class_name($e);
$message = $e->getMessage();
$code = $e->getCode();
$errorMessage = 'Failed asserting the class of exception';
if ($message && $code) {
$errorMessage .= sprintf(' (message was %s, code was %d)', $message, $code);
} elseif ($code) {
$errorMessage .= sprintf(' (code was %d)', $code);
}
$errorMessage .= '.';
$self->assertInstanceOf($expectedException, $e, $errorMessage);
if ($expectedCode !== null) {
$self->assertEquals($expectedCode, $code, sprintf('Failed asserting code of thrown %s.', $class));
}
if ($expectedMessage !== null) {
$self->assertContains($expectedMessage, $message, sprintf('Failed asserting the message of thrown %s.', $class));
}
return;
}
$errorMessage = 'Failed asserting that exception';
if (strtolower($expectedException) !== 'exception') {
$errorMessage .= sprintf(' of type %s', $expectedException);
}
$errorMessage .= ' was thrown.';
$self->fail($errorMessage);
}
示例2: testClassName
public function testClassName()
{
$this->assertEquals('ClassInfoTest', ClassInfo::class_name($this));
$this->assertEquals('ClassInfoTest', ClassInfo::class_name('ClassInfoTest'));
$this->assertEquals('ClassInfoTest', ClassInfo::class_name('CLaSsInfOTEsT'));
// This is for backwards compatiblity and will be removed in 4.0
$this->assertEquals('IAmAClassThatDoesNotExist', ClassInfo::class_name('IAmAClassThatDoesNotExist'));
}
示例3: has_own_table
/**
* Returns true if given class has its own table. Uses the rules for whether the table should exist rather than
* actually looking in the database.
*
* @param string $dataClass
* @return bool
*/
public static function has_own_table($dataClass)
{
if (!is_subclass_of($dataClass, 'DataObject')) {
return false;
}
$dataClass = ClassInfo::class_name($dataClass);
if (!isset(DataObject::$cache_has_own_table[$dataClass])) {
if (get_parent_class($dataClass) == 'DataObject') {
DataObject::$cache_has_own_table[$dataClass] = true;
} else {
DataObject::$cache_has_own_table[$dataClass] = Config::inst()->get($dataClass, 'db', Config::UNINHERITED) || Config::inst()->get($dataClass, 'has_one', Config::UNINHERITED);
}
}
return DataObject::$cache_has_own_table[$dataClass];
}
示例4: getObject
/**
* Safely get a DataObject from a client-supplied ID and ClassName, checking: argument
* validity; existence; and canView permissions.
*
* @param int $id The ID of the DataObject
* @param string $class The Class of the DataObject
* @return DataObject The referenced DataObject
* @throws SS_HTTPResponse_Exception
*/
protected function getObject($id, $class)
{
$id = (int) $id;
$class = ClassInfo::class_name($class);
if (!$class || !is_subclass_of($class, 'SilverStripe\\ORM\\DataObject') || !Object::has_extension($class, 'SilverStripe\\ORM\\Versioning\\Versioned')) {
$this->editForm->httpError(400, _t('AddToCampaign.ErrorGeneral', 'We apologise, but there was an error'));
return null;
}
$object = DataObject::get($class)->byID($id);
if (!$object) {
$this->editForm->httpError(404, _t('AddToCampaign.ErrorNotFound', 'That {Type} couldn\'t be found', '', ['Type' => $class]));
return null;
}
if (!$object->canView()) {
$this->editForm->httpError(403, _t('AddToCampaign.ErrorItemPermissionDenied', 'It seems you don\'t have the necessary permissions to add {ObjectTitle} to a campaign', '', ['ObjectTitle' => $object->Title]));
return null;
}
return $object;
}
示例5: testNonClassName
public function testNonClassName()
{
$this->setExpectedException('ReflectionException', 'Class IAmAClassThatDoesNotExist does not exist');
$this->assertEquals('IAmAClassThatDoesNotExist', ClassInfo::class_name('IAmAClassThatDoesNotExist'));
}
示例6: testGetCache
public function testGetCache()
{
$cache = CacheHelper::get_cache();
$this->assertEquals(ClassInfo::class_name($cache), 'Zend_Cache_Frontend_Function');
}
示例7: getDirectExtensions
/**
* Gets all extensions directly on this class that extend FluentExtension
*
* @param Config $config
* @param string $class
* @return array
*/
protected function getDirectExtensions($config, $class)
{
$extensions = $config->get($class, 'extensions', Config::UNINHERITED);
$found = array();
if ($extensions) {
foreach ($extensions as $extension) {
$extensionClass = ClassInfo::class_name(Extension::get_classname_without_arguments($extension));
if ($extensionClass === 'FluentExtension' || is_subclass_of($extensionClass, 'FluentExtension')) {
$found[] = $extensionClass;
}
}
}
return $found;
}