本文整理汇总了PHP中get_called_class函数的典型用法代码示例。如果您正苦于以下问题:PHP get_called_class函数的具体用法?PHP get_called_class怎么用?PHP get_called_class使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_called_class函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: tearDownAfterClass
public static function tearDownAfterClass()
{
if (!self::$timing) {
echo "\n";
return;
}
$class = get_called_class();
echo "Timing results : {$class}\n";
$s = sprintf("%40s %6s %9s %9s %4s\n", 'name', 'count', 'total', 'avg', '% best');
echo str_repeat('=', strlen($s)) . "\n";
echo $s;
echo str_repeat('-', strlen($s)) . "\n";
array_walk(self::$timing, function (&$value, $key) {
$value['avg'] = round($value['total'] / $value['count'] * 1000000, 3);
});
usort(self::$timing, function ($a, $b) {
$at = $a['avg'];
$bt = $b['avg'];
return $at === $bt ? 0 : ($at < $bt ? -1 : 1);
});
$best = self::$timing[0]['avg'];
foreach (self::$timing as $timing) {
printf("%40s %6d %7.3fms %7.3fus %4.1f%%\n", $timing['name'], $timing['count'], round($timing['total'] * 1000, 3), $timing['avg'], round($timing['avg'] / $best * 100, 3));
}
echo str_repeat('-', strlen($s)) . "\n\n";
printf("\nTiming compensated for avg overhead for: timeIt of %.3fus and startTimer/endTimer of %.3fus per invocation\n\n", self::$timeItOverhead * 1000000, self::$startEndOverhead * 1000000);
parent::tearDownAfterClass();
}
示例2: validateField
public function validateField(Structure $document, $fieldName, array $params)
{
$value = $document->get($fieldName);
if (!$value) {
return;
}
if (empty($params[0])) {
throw new Exception('Type not specified');
}
$requiredTypes = (array) $params[0];
$allowedTypes = array('array', 'bool', 'callable', 'double', 'float', 'int', 'integer', 'long', 'null', 'numeric', 'object', 'real', 'resource', 'scalar', 'string');
foreach ($requiredTypes as $type) {
if (!in_array($type, $allowedTypes)) {
throw new Exception('Type must be one of ' . implode(', ', $allowedTypes));
}
if (true === call_user_func('is_' . $type, $value)) {
return;
}
}
if (!isset($params['message'])) {
if (count($requiredTypes) === 1) {
$params['message'] = 'Field "' . $fieldName . '" must be of type ' . $requiredTypes[0] . ' in ' . get_called_class();
} else {
$params['message'] = 'Field "' . $fieldName . '" must be one of types ' . implode(', ', $requiredTypes) . ' in ' . get_called_class();
}
}
$document->addError($fieldName, $this->getName(), $params['message']);
}
示例3: crossover
public function crossover($partner, $options = array())
{
$a = $partner->get_data();
$b = $this->data;
$a_c = strlen($a);
$b_c = strlen($b);
$c = '';
$c_c = $a_c >= $b_c ? $a_c : $b_c;
// if it has same length, great!, use std algorithm
if ($a_c == $b_c) {
$left = mt_rand(0, 1) == 1 ? $a : $b;
$right = $left == $b ? $a : $b;
$sp = mt_rand(0, $c_c);
$c .= substr($left, 0, $sp);
$c .= substr($right, $sp);
} else {
/*
* put shorter chromosome, in longer chromosome
* example:
* a: aaaa
* b: bb
* result: aabb OR abba OR bbaa
* */
$longer = $c_c == $a_c ? 'a' : 'b';
$shorter = $longer == 'b' ? 'a' : 'b';
$sp_begin = mt_rand(0, ${$longer . '_c'} - ${$shorter . '_c'});
$tmp = substr_replace(${$longer}, ${$shorter}, -$sp_begin);
$c .= $tmp . substr(${$longer}, strlen($tmp));
}
$class_name = get_called_class();
return new $class_name($c);
}
示例4: getFieldByName
/**
* @param $name
*
* @return mixed
* @throws FieldNotFoundException
*/
public function getFieldByName($name)
{
if (!isset($this->fields[$name])) {
throw new FieldNotFoundException($name . ' doesn\'t exist in this ' . get_called_class());
}
return $this->fields[$name];
}
示例5: __construct
public function __construct(HTTPRequest $httpRequest, HTTPResponse $httpResponse, Logger $logger)
{
$this->httpRequest = $httpRequest;
$this->httpResponse = $httpResponse;
$this->logger = $logger;
$this->entity = get_called_class();
}
示例6: __construct
/**
* Constructor.
* Accepts an object, array, or JSON string.
*
* @param mixed $in -OPTIONAL
*/
public function __construct($in = null)
{
$this->_called_class = get_called_class();
$this->_class_vars = get_class_vars($this->_called_class);
// remove elements with names starting with underscore
foreach ($this->_class_vars as $k => $v) {
if ($k[0] === '_') {
unset($this->_class_vars[$k]);
} elseif (is_string($v) && 0 === stripos($v, '__class__')) {
// We must use `eval` because we want to handle
// '__class__Date' and
// '__class__DateTime("Jan 1, 2015")' with 1 or more parameters.
$this->_class_vars[$k] = eval(preg_replace('/^__class__(.*)$/iu', 'return new $1;', $v));
// Objects are always passed by reference,
// but we want a separate copy so the original stays unchanged.
$this->{$k} = clone $this->_class_vars[$k];
}
}
$this->_public_names = array_keys($this->_class_vars);
// Don't waste time with assignObject if input is one of these.
// Just return leaving the default values.
switch (gettype($in)) {
case 'NULL':
case 'null':
case 'bool':
case 'boolean':
return;
}
$this->assignObject($in);
}
示例7: getTemplateFileFormatter
/**
* @return ITemplateFileFormatter
* @throws InvalidStateException
*/
public function getTemplateFileFormatter()
{
if ($this->templateFileFormatter === NULL) {
throw new InvalidStateException(sprintf('Template file formatter was not set. Did you forget to call %s::injectTemplateFileFormatter()?', get_called_class()));
}
return $this->templateFileFormatter;
}
示例8: model
/**
* Returns the static model of the specified AR class.
*
* @param string $className
* @return YdActiveRecord the static model class
*/
public static function model($className = null)
{
if (!$className) {
$className = get_called_class();
}
return parent::model($className);
}
示例9: __callStatic
/**
* Magic method run protected/private static methods.
*
* @param string $name The called method name.
* @param array $arguments Array of arguments.
*/
public static function __callStatic($name, $arguments)
{
$class = get_called_class();
if (method_exists($class, $name)) {
return forward_static_call_array([$class, $name], $arguments);
}
}
示例10: organize
public function organize(&$baseCvmp, &$ignoreVMs = [], $isMainInteration = true)
{
$class = get_called_class();
$pareto = [];
if (count($ignoreVMs) >= $baseCvmp['nvms'] or $class::$stop) {
return $baseCvmp;
}
//Select Lower VM from the Rank
$lowVM = $this->selectLowerVm($baseCvmp, $ignoreVMs);
//generateCVMP
$cvmps = $this->generateCVMP($baseCvmp, $lowVM);
//foreach Possible CVMP
$ignoreVMs[$lowVM] = $lowVM;
foreach ($cvmps as $key => $cvmp) {
Counter::$scenarios++;
if (!$class::$stop and $this->isNonDominanted($baseCvmp, $cvmp)) {
Counter::$pareto++;
$pareto[] = $this->organize($cvmp, $ignoreVMs, false);
}
}
//Taking the lowVM putted before
array_pop($ignoreVMs);
if (empty($pareto)) {
Counter::$leaf++;
}
$pareto[] = $baseCvmp;
$sCvmp = $this->getCvmpWithMaxCostBenefit($pareto);
if ($isMainInteration) {
$class::updateIgnoreVMs($ignoreVMs, $sCvmp, $lowVM);
$sCvmp = $this->organize($sCvmp, $ignoreVMs, true);
}
return $sCvmp;
}
示例11: create
/**
* Creates and instance of the mock WebServiceApplicationWeb object.
*
* The test can implement the following overrides:
* - mockAppendBody
* - mockGetBody
* - mockPrepentBody
* - mockSetBody
*
* If any *Body methods are implemented in the test class, all should be implemented otherwise behaviour will be unreliable.
*
* @param TestCase $test A test object.
* @param array $options A set of options to configure the mock.
*
* @return PHPUnit_Framework_MockObject_MockObject
*
* @since 11.3
*/
public static function create($test, $options = array())
{
// Set expected server variables.
if (!isset($_SERVER['HTTP_HOST'])) {
$_SERVER['HTTP_HOST'] = 'localhost';
}
// Collect all the relevant methods in WebServiceApplicationWeb (work in progress).
$methods = array('allowCache', 'appendBody', 'clearHeaders', 'close', 'execute', 'get', 'getBody', 'getDocument', 'getHeaders', 'getIdentity', 'getLanguage', 'getSession', 'loadConfiguration', 'loadDispatcher', 'loadDocument', 'loadIdentity', 'loadLanguage', 'loadSession', 'prependBody', 'redirect', 'registerEvent', 'sendHeaders', 'set', 'setBody', 'setHeader', 'triggerEvent');
// Create the mock.
$mockObject = $test->getMock('WebServiceApplicationWeb', $methods, array(), '', true);
// Mock calls to JApplicationWeb::getDocument().
$mockObject->expects($test->any())->method('getDocument')->will($test->returnValue(TestMockDocument::create($test)));
// Mock calls to JApplicationWeb::getLanguage().
$mockObject->expects($test->any())->method('getLanguage')->will($test->returnValue(TestMockLanguage::create($test)));
// Mock a call to JApplicationWeb::getSession().
if (isset($options['session'])) {
$mockObject->expects($test->any())->method('getSession')->will($test->returnValue($options['session']));
} else {
$mockObject->expects($test->any())->method('getSession')->will($test->returnValue(TestMockSession::create($test)));
}
$test->assignMockCallbacks($mockObject, array('appendBody' => array(is_callable(array($test, 'mockAppendBody')) ? $test : get_called_class(), 'mockAppendBody'), 'getBody' => array(is_callable(array($test, 'mockGetBody')) ? $test : get_called_class(), 'mockGetBody'), 'prependBody' => array(is_callable(array($test, 'mockPrependBody')) ? $test : get_called_class(), 'mockPrependBody'), 'setBody' => array(is_callable(array($test, 'mockSetBody')) ? $test : get_called_class(), 'mockSetBody')));
// Reset the body storage.
self::$body = array();
return $mockObject;
}
示例12: __unset
public function __unset($name)
{
if (!$this->__isset($name)) {
Exception::error(I18n::__('Property %s->%s does not exist.', get_called_class(), $name));
}
unset($this->{$name});
}
示例13: getAbsoluteTemplatePath
protected function getAbsoluteTemplatePath($template_path)
{
$config = new \Config();
$class_name = substr(get_called_class(), strrpos(get_called_class(), '\\') + 1);
$class_name = str_replace('View_', '', $class_name);
return $config->paths->server_root . '/../Layout/Common/Client/Template/' . implode('/', explode('_', $class_name)) . '.php';
}
示例14: handleWorkflowMessage
/**
* @param WorkflowMessage $workflowMessage
* @return void
*/
public function handleWorkflowMessage(WorkflowMessage $workflowMessage)
{
if (!MessageNameUtils::isProcessingCommand($workflowMessage->messageName())) {
$this->workflowEngine->dispatch(LogMessage::logUnsupportedMessageReceived($workflowMessage));
}
try {
if ($workflowMessage->messageType() === MessageNameUtils::COLLECT_DATA) {
$processingMessage = $this->handleCollectData($workflowMessage);
if (!$processingMessage instanceof ProcessingMessage) {
throw new \RuntimeException(sprintf("%s::handleCollectData method returned %s instead of a ProcessingMessage", get_called_class(), is_object($processingMessage) ? get_class($processingMessage) : gettype($processingMessage)));
}
} else {
if ($workflowMessage->messageType() === MessageNameUtils::PROCESS_DATA) {
$processingMessage = $this->handleProcessData($workflowMessage);
if (!$processingMessage instanceof ProcessingMessage) {
throw new \RuntimeException(sprintf("%s::handleProcessData method returned %s instead of a ProcessingMessage", get_called_class(), is_object($processingMessage) ? get_class($processingMessage) : gettype($processingMessage)));
}
} else {
$this->workflowEngine->dispatch(LogMessage::logUnsupportedMessageReceived($workflowMessage));
return;
}
}
$this->workflowEngine->dispatch($processingMessage);
return;
} catch (\Exception $ex) {
$this->workflowEngine->dispatch(LogMessage::logException($ex, $workflowMessage));
return;
}
}
示例15: factory
public static function factory($config = array(), $required = array())
{
if (!defined('static::ENDPOINT')) {
throw new Exception\ServiceEndpointException('A client must have an endpoint');
}
$default = array('base_url' => '{scheme}://{domain}/' . static::ENDPOINT);
$required = array_merge(array('scheme', 'domain', 'base_url'), $required);
$config = Collection::fromConfig($config, $default, $required);
$client = new static($config->get('base_url'), $config);
$refClass = new \ReflectionClass(get_called_class());
$serviceDefinitionPath = dirname($refClass->getFileName());
$classNamePieces = explode('\\', get_called_class());
$serviceDefinitionFile = array_pop($classNamePieces) . '.json';
switch (true) {
case is_readable(dirname($serviceDefinitionPath) . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . $serviceDefinitionFile):
$serviceDefinition = $serviceDefinitionPath . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . $serviceDefinitionFile;
break;
case is_readable($serviceDefinitionPath . DIRECTORY_SEPARATOR . $serviceDefinitionFile):
$serviceDefinition = $serviceDefinitionPath . DIRECTORY_SEPARATOR . $serviceDefinitionFile;
break;
default:
throw new Exception\ClientConfigurationException('A client must have a service definition. Could not read the file "' . $serviceDefinition . '"');
}
$description = ServiceDescription::factory($serviceDefinition);
$client->setDescription($description);
return $client;
}