本文整理汇总了PHP中spl_object_hash函数的典型用法代码示例。如果您正苦于以下问题:PHP spl_object_hash函数的具体用法?PHP spl_object_hash怎么用?PHP spl_object_hash使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了spl_object_hash函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getMulti
/**
* easier to program for a list of keys passed in and returned, than the overloaded interface
* of the normal get method.
*/
protected function getMulti(array $request)
{
$map = array();
$shards = array();
foreach ($request as $k) {
$shard = $this->shard($k);
$hash = spl_object_hash($shard);
$shards[$hash] = $shard;
if (!isset($map[$hash])) {
$map[$hash] = array();
}
$map[$hash][] = $k;
}
$rows = array();
$rows = array_fill_keys($request, NULL);
foreach ($map as $hash => $keys) {
$shard = $shards[$hash];
foreach ($shard->get($keys) as $k => $v) {
$rows[$k] = $v;
}
}
foreach ($rows as $k => $v) {
if ($v === NULL) {
unset($rows[$k]);
}
}
return $rows;
}
示例2: memoize
/**
* Memoizes callbacks and returns their value instead of calling them
*
* @param callable $callback Callable closure or function
* @param array $arguments Arguments
* @param array|string $key Optional memoize key to override the auto calculated hash
* @return mixed
*/
function memoize($callback, array $arguments = array(), $key = null)
{
static $storage = array();
if ($callback === null) {
$storage = array();
return null;
}
InvalidArgumentException::assertCallback($callback, __FUNCTION__, 1);
static $keyGenerator = null;
if (!$keyGenerator) {
$keyGenerator = function ($value) use(&$keyGenerator) {
$type = gettype($value);
if ($type === 'array') {
$key = join(':', map($value, $keyGenerator));
} elseif ($type === 'object') {
$key = get_class($value) . ':' . spl_object_hash($value);
} else {
$key = (string) $value;
}
return $key;
};
}
if ($key === null) {
$key = $keyGenerator(array_merge(array($callback), $arguments));
} else {
$key = $keyGenerator($key);
}
if (!isset($storage[$key]) && !array_key_exists($key, $storage)) {
$storage[$key] = call_user_func_array($callback, $arguments);
}
return $storage[$key];
}
示例3: it_wraps_non_token_arguments_into_ExactValueToken
/**
* @param \stdClass $object
*/
function it_wraps_non_token_arguments_into_ExactValueToken($object)
{
$this->beConstructedWith(array(42, 'zet', $object));
$class = get_class($object->getWrappedObject());
$hash = spl_object_hash($object->getWrappedObject());
$this->__toString()->shouldReturn("exact(42), exact(\"zet\"), exact({$class}:{$hash} Object (\n 'objectProphecy' => Prophecy\\Prophecy\\ObjectProphecy Object (*Prophecy*)\n))");
}
示例4: syn
/**
* Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote
* server.
*
* @throws TeamSpeak3_Adapter_Exception
* @return void
*/
public function syn()
{
$this->initTransport($this->options);
$this->transport->setAdapter($this);
TeamSpeak3_Helper_Profiler::init(spl_object_hash($this));
TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferConnected", $this);
}
示例5: stringify
/**
* Stringifies any provided value.
*
* @param mixed $value
* @param boolean $exportObject
*
* @return string
*/
public function stringify($value, $exportObject = true)
{
if (is_array($value)) {
if (range(0, count($value) - 1) === array_keys($value)) {
return '[' . implode(', ', array_map(array($this, __FUNCTION__), $value)) . ']';
}
$stringify = array($this, __FUNCTION__);
return '[' . implode(', ', array_map(function ($item, $key) use($stringify) {
return (is_integer($key) ? $key : '"' . $key . '"') . ' => ' . call_user_func($stringify, $item);
}, $value, array_keys($value))) . ']';
}
if (is_resource($value)) {
return get_resource_type($value) . ':' . $value;
}
if (is_object($value)) {
return $exportObject ? ExportUtil::export($value) : sprintf('%s:%s', get_class($value), spl_object_hash($value));
}
if (true === $value || false === $value) {
return $value ? 'true' : 'false';
}
if (is_string($value)) {
$str = sprintf('"%s"', str_replace("\n", '\\n', $value));
if (50 <= strlen($str)) {
return substr($str, 0, 50) . '"...';
}
return $str;
}
if (null === $value) {
return 'null';
}
return (string) $value;
}
示例6: detachShared
public function detachShared(SharedEventManagerInterface $events)
{
foreach ($this->listeners[\spl_object_hash($events)] as $listener) {
$events->detach($this->identity, $listener);
}
return __METHOD__;
}
示例7: hash
/**
* Creates a string hash for a value
*
* @param mixed $value The value
* @param string $algo The hash algorithm
*
* @return string
*/
public static function hash($value, string $algo = 'fnv1a32') : string
{
$type = gettype($value);
switch ($type) {
case 'object':
if (Validate::isEquatable($value)) {
$string = sprintf('e_%s', $value->hashValue());
} else {
$string = sprintf('o_%s', spl_object_hash($value));
}
break;
case 'string':
$string = sprintf('s_%s', $value);
break;
case 'integer':
$string = sprintf('i_%d', $value);
break;
case 'double':
$string = sprintf('f_%.14F', $value);
break;
case 'boolean':
$string = sprintf('b_%d', (int) $value);
break;
case 'resource':
$string = sprintf('r_%d', (int) $value);
break;
case 'array':
$string = sprintf('a_%s', serialize($value));
break;
default:
$string = '0';
break;
}
return hash($algo, $string);
}
示例8: endTest
public function endTest(\PHPUnit_Framework_Test $test, $time)
{
if (!in_array(spl_object_hash($test), $this->unsuccessfulTests)) {
$this->fire(Events::TEST_SUCCESS, new TestEvent($test));
}
$this->dispatcher->dispatch(Events::TEST_END, new TestEvent($test, $time));
}
示例9: validate
/**
* @param Contact $entity
* @param array $options
* @return \Devture\Component\Form\Validator\ViolationsList
*/
public function validate($entity, array $options = array())
{
$violations = parent::validate($entity, $options);
$name = $entity->getName();
if (strlen($name) < 3 || !preg_match("/^[a-z][a-z0-9_\\-\\.]+\$/", $name)) {
$violations->add('name', 'Invalid name.');
} else {
try {
$ent = $this->repository->findOneBy(array('name' => $name));
if (spl_object_hash($ent) !== spl_object_hash($entity)) {
$violations->add('name', 'The name is already in use.');
}
} catch (NotFound $e) {
}
}
if (!$entity->getTimePeriod() instanceof TimePeriod) {
$violations->add('timePeriod', 'The time period is not valid.');
}
if (!$entity->getServiceNotificationCommand() instanceof Command) {
$violations->add('serviceNotificationCommand', 'The service notification command is not valid.');
}
if ($this->isEmpty($entity->getEmail()) && count($entity->getAddresses()) === 0) {
$violations->add('__other__', 'An email address or other addresses need to be entered.');
}
foreach ($entity->getAddresses() as $slot => $address) {
$slot = (int) $slot;
if ($slot < 1 || $slot > Contact::ADDRESS_SLOTS_COUNT) {
$violations->add('addresses', 'Slot %slot% is not allowed.', array('%slot%' => $slot));
}
}
return $violations;
}
示例10: hash
/**
* Returns a string representing the supplied value's identity.
*
* @param mixed $value
*
* @return string
*/
public static function hash($value)
{
$typeIdentifier = gettype($value)[0];
switch ($typeIdentifier) {
case 's':
//string
return 's' . (strlen($value) > 32 ? md5($value) : $value);
case 'i':
//integer
//integer
case 'b':
//boolean
//boolean
case 'd':
//double
//double
case 'r':
//resource
//resource
case 'u':
//unknown type
return $typeIdentifier . $value;
case 'N':
//NULL
return 'N';
case 'o':
//object
return 'o' . spl_object_hash($value);
case 'a':
//array
return self::arrayHash($value);
}
}
示例11: valuesProvider
public function valuesProvider()
{
$obj2 = new \stdClass();
$obj2->foo = 'bar';
$obj3 = (object) array(1, 2, "Test\r\n", 4, 5, 6, 7, 8);
$obj = new \stdClass();
// @codingStandardsIgnoreStart
$obj->null = null;
// @codingStandardsIgnoreEnd
$obj->boolean = true;
$obj->integer = 1;
$obj->double = 1.2;
$obj->string = '1';
$obj->text = "this\nis\na\nvery\nvery\nvery\nvery\nvery\nvery\rlong\n\rtext";
$obj->object = $obj2;
$obj->objectagain = $obj2;
$obj->array = array('foo' => 'bar');
$obj->array2 = array(1, 2, 3, 4, 5, 6);
$obj->array3 = array($obj, $obj2, $obj3);
$obj->self = $obj;
$storage = new \SplObjectStorage();
$storage->attach($obj2);
$storage->foo = $obj2;
return array(array($obj, spl_object_hash($obj)), array($obj2, spl_object_hash($obj2)), array($obj3, spl_object_hash($obj3)), array($storage, spl_object_hash($storage)), array($obj->array, 0), array($obj->array2, 0), array($obj->array3, 0));
}
示例12: testPartialApplication
public function testPartialApplication()
{
$callback = new Callback('\\Fatso\\Tests\\Util\\CallbackContainer::concat');
$new = $callback->partial('abcd');
$this->assertEquals('abcdEF', $new('EF'));
$this->assertNotEquals(spl_object_hash($callback), spl_object_hash($new));
}
示例13: syn
/**
* Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote
* server.
*
* @throws TeamSpeak3_Adapter_Exception
* @return void
*/
public function syn()
{
$this->initTransport($this->options);
$this->transport->setAdapter($this);
\ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\Profiler::init(spl_object_hash($this));
\ManiaLivePlugins\Standard\TeamSpeak\TeamSpeak3\Helper\Signal::getInstance()->emit("filetransferConnected", $this);
}
示例14: testPersistObjects
public function testPersistObjects()
{
$collection = new Collection($this->cursor, true);
// collect object hashes from first iterate / hydrate
$hashes = [];
foreach ($collection as $item) {
$hashes[] = spl_object_hash($item);
}
//iterate the same collection again and we should get the same exact objects back
$secondaryHashes = [];
foreach ($collection as $item) {
$secondaryHashes[] = spl_object_hash($item);
}
$this->assertEquals(count($hashes), count($secondaryHashes), 'got different number of items during second iteration of collection');
for ($c = 0; $c < count($hashes); $c++) {
$this->assertEquals($hashes[$c], $secondaryHashes[$c], 'got different object hashes the second time around');
}
// now test that NOT persisting objects results in new objects each time iterated
$collection = new Collection($this->cursor);
// collect object hashes from first iterate / hydrate
$hashes = [];
foreach ($collection as $item) {
$hashes[] = spl_object_hash($item);
}
//iterate the same collection again and we should get the NEW objects back
$secondaryHashes = [];
foreach ($collection as $item) {
$secondaryHashes[] = spl_object_hash($item);
}
$this->assertEquals(count($hashes), count($secondaryHashes), 'got different number of items during second iteration of collection');
for ($c = 0; $c < count($hashes); $c++) {
$this->assertNotEquals($hashes[$c], $secondaryHashes[$c], 'got same object hashes the second time around');
}
}
示例15: testInitServiceEvent
public function testInitServiceEvent()
{
$this->assertEquals('blah blah blah', Dummy::saySomething());
$this->appPkg->addEventListener(Event\Type\System\InitService::toType(), function ($event) {
$pkgName = $event->getCurrentNode()->getComposerName();
if ($event->getShortClassName() == 'Dummy') {
return function () use($pkgName) {
$this->pkgName = $pkgName;
$this->sentence = 'I hope it will work';
};
}
});
$ext = $this->appPkg->getExtensions()[0];
$this->assertEquals(spl_object_hash($ext), spl_object_hash($this->appPkg->getChildNodes()[0]));
// this event handler would not be triggered
$ext->addEventListener(Event\Type\System\InitService::toType(), function ($event) {
$pkgName = $event->getCurrentNode()->getComposerName();
if ($event->getShortClassName() == 'Dummy') {
return function () use($pkgName) {
$this->pkgName = $pkgName;
$this->sentence = "Wanna sleep";
};
}
});
// fire event by creating a service instance
$dummy = Dummy::create();
$this->assertEquals('I hope it will work', $dummy->saySomething());
$this->assertEquals('phpcrystal/phpcrystaltest', $dummy->getPackageName());
}