$now = new \DateTime();
$now->add(new \DateInterval('PT3H2M30S'));
echo $now->format('H:i:s');
$from = new \DateTime('2018-05-03 00:00:00');
$to = new \DateTime('2018-05-03 23:59:59');
$period = new \DatePeriod($from, new \DateInterval('PT30M'), $to);
$result = [];
foreach ($period as $dateTime) {
$dinner = clone $dateTime;
$dinner->add(new \DateInterval('PT30M'));
$result[] = $dateTime->format('H:i') . ' - ' . $dinner->format('H:i');
}
var_dump($result);
Использованный алгоритм, стоимость и соль будут возвращены как часть хеша. Таким образом, информация необходимая для проверки хеша будет в него включена. Это позволит функции password_verify() проверять хеш без необходимости отдельного хранения информации о соли и алгоритме.
<?php
class base {
public function getParent(){
return ['base'];
}
public function getParentAlt(){
$class = static::class;
$classes = [
$class
];
while ($parent = get_parent_class($class)) {
$class = $parent;
$classes[] = $class;
}
return $classes;
}
}
class class1 extends base {
public function getParent(){
return array_merge(['class1'], parent::getParent());
}
}
class class2 extends class1 {
public function getParent(){
return array_merge(['class2'], parent::getParent());
}
}
class class3 extends class2 {
public function getParent(){
return array_merge(['class3'], parent::getParent());
}
}
$new = new class3();
print_r ($new->getParent());
print_r ($new->getParentAlt());
<div class="panel-body">
<?php $longString = $key['question'];
$longString = wordwrap($longString, 50, "<br/>", true);
?>
<a href="http://color-school.dev/question.php?question_id=<?php echo $key['question_id'] ?>&id=<?php echo $userid ?>">
<?php
echo $longString;
?>
</a>
</div>
"autoload": {
"files": ["src/helpers.php"]
}
interface BalanceInterface
{
public function get();
public function inc($value);
public function dec($value);
}
class Balance implements BalanceInterface
{
private $value;
public function get()
{
return $this->value;
}
public function inc($value)
{
$this->value += $value;
}
public function dec($value)
{
$this->value -= $value;
}
}
class CacheBalance implements BalanceInterface
{
/**
* @var BalanceInterface
*/
private $next;
/**
* @var \Psr\Cache\CacheItemPoolInterface
*/
private $cache;
public function __construct(BalanceInterface $next, \Psr\Cache\CacheItemPoolInterface $cache)
{
$this->next = $next;
$this->cache = $cache;
}
public function get()
{
$item = $this->cache->getItem('balance');
if ($item->isHit()) {
return $item->get();
}
$value = $this->next->get();
$item->set($value);
$this->cache->save($item);
return $value;
}
public function inc($value)
{
return $this->next->inc($value);
}
public function dec($value)
{
return $this->next->dec($value);
}
}
class LogBalance implements BalanceInterface
{
/**
* @var BalanceInterface
*/
private $next;
/**
* @var \Psr\Log\LoggerInterface
*/
private $logger;
public function __construct(BalanceInterface $next, \Psr\Log\LoggerInterface $logger)
{
$this->next = $next;
$this->logger = $logger;
}
public function get()
{
return $this->next->get();
}
public function inc($value)
{
$this->logger->info(sprintf('Increase balance by %d', $value));
return $this->next->inc($value);
}
public function dec($value)
{
$this->logger->info(sprintf('Decrease balance by %d', $value));
return $this->next->dec($value);
}
}
$initialBalance = new \Balance();
$cacheBalance = new \CacheBalance($initialBalance, $cache);
$logBalance = new \LogBalance($cacheBalance, $logger);
$balance = $logBalance;
$object = new \stdClass();
$a = new \stdClass();
$a->name = 'a';
$b = new \stdClass();
$b->name = 'b';
$c = new \stdClass();
$c->name = 'c';
$object->a = $a;
$a->b = $b;
$b->c = $c;
$path = 'a.b.c';
$propertyAccessor = \Symfony\Component\PropertyAccess\PropertyAccess::createPropertyAccessor();
var_dump($propertyAccessor->getValue($object, $path));
$data['name1']['name2']['name3'] = 'some data';
$propertyAccessor = \Symfony\Component\PropertyAccess\PropertyAccess::createPropertyAccessor();
$keys = '[name1][name2][name3]';
echo $propertyAccessor->getValue($data, $keys);
composer req seld/jsonlint
#!/usr/bin/env php
<?php
use Seld\JsonLint\JsonParser;
use Seld\JsonLint\ParsingException;
require_once __DIR__ . '/../vendor/autoload.php';
$parser = new JsonParser();
$data = file_get_contents(__DIR__ . '/../test.json');
$tries = 0;
do {
$repeat = false;
try {
$parser->parse($data);
} catch (ParsingException $e) {
$details = $e->getDetails();
$start = $details['loc']['first_column'];
$end = mb_strpos($data, ',', $start, 'utf8') - 1;
$problemString = mb_substr($data, $start, $end - $start, 'utf8');
$data = str_replace($problemString, addslashes($problemString), $data);
$repeat = true;
$tries++;
}
} while ($repeat);
echo $data;
$dateTime = new \DateTime('this friday');
echo $dateTime->format('Y-m-d');
$now = new \DateTime();
$friday = new \DateTime('this friday');
$result = new \DateTime('next monday');
if ($now->format('Y-m-d') == $friday->format('Y-m-d') &&
$now->format('H:i:s') >= '14:00:00') {
$result->add(new \DateInterval('P1W'));
} elseif ($friday < $now) {
$result->add(new \DateInterval('P1W'));
}
echo $result->format('Y-m-d');
php bin/message.php
- опрашивает БД на наличие новых записей и при наличии новой записи отправляет её клиентуphp bin/server.php
- WebSocket server, который обрабатывает соединенияclient.php - опрашивает демона на изменения БД;
php bin/message.php