The read callback will retrieve any existing session data (stored in a special serialized format) and will be unserialized and used to automatically populate the $_SESSION superglobal when the read callback returns the saved session data back to PHP session handling.php.net/manual/en/function.session-start.php
Вопрос в том, как правильно их отлавливать при использовании класса? Перехватывать базовое исключение, или лесенкой ловить каждое конкретное?
echo '[ul]';
foreach (range(0, 9) as $i)
{
if ($i > 0 && $i % 4 == 0)
{
echo '[/ul]';
echo '[ul]';
}
echo '[li]', 'Значение', '[/li]';
}
echo '[/ul]';
require 'digest/sha2'
@arHash = [
'm_shop',
'm_orderid',
'm_amount',
'm_curr',
'm_desc',
'm_key'
];
puts Digest::SHA256.hexdigest(@arHash.join(':')).upcase
include_path=".;C:\xampp\php\PEAR;C:\xampp\php\pear;C:/xampp/php/pear/PhpDocumentor"
class Set implements \ArrayAccess, \Countable, \IteratorAggregate
В \Slim\Helper\Set никаких магических методов нет имеется.
$text = '...';
$textSize = mb_strlen($text);
$paragraphsCount = 5;
$averageParagpaphSize = ceil($textSize / $paragraphsCount);
$paragraphs = [];
for ($i = 0; $i < $paragraphsCount; $i++)
{
$currentParagraph = mb_substr($text, $averageParagpaphSize * $i, $averageParagpaphSize);
$paragraphs[] = $currentParagraph;
}
for ($i = 1; $i < $paragraphsCount; $i++)
{
$currentParagraph = $paragraphs[$i - 1];
$nextParagraph = $paragraphs[$i];
if (mb_substr($currentParagraph, -1, 1) !== '.')
{
$dotPosition = mb_strpos($nextParagraph, '.') + 1;
$currentParagraph .= mb_substr($nextParagraph, 0, $dotPosition);
$nextParagraph = trim(mb_substr($nextParagraph, $dotPosition));
}
$paragraphs[$i - 1] = $currentParagraph;
$paragraphs[$i] = $nextParagraph;
}
var_dump($paragraphs);
$text = '...';
$paragraphsCount = 5;
$sentences = mb_split('\.', $text);
$paragraphs = array_chunk($sentences, ceil(count($sentences) / $paragraphsCount));
array_walk($paragraphs, function (&$paragraphSentences) {
$paragraphSentences = implode(' ', $paragraphSentences);
});
var_dump($paragraphs);
$periodString = '12:00-02:00';
$weekDay = 'Friday';
$period = [
'start' => new DateTime(),
'end' => new DateTime(),
];
$day = (int)date('d', strtotime('this '.$weekDay));
$month = (int)date('m', strtotime('this '.$weekDay));
$year = (int)date('Y', strtotime('this '.$weekDay));
foreach (array_combine(['start', 'end'], explode('-', $periodString)) as $type => $part)
{
list($hour, $minute) = explode(':', $part);
$hour = (int)$hour;
$minute = (int)$minute;
$date = $period[$type];
$date->setDate($year, $month, $day);
$date->setTime($hour, $minute);
}
if ($period['start'] > $period['end'])
{
$period['end']->add(new DateInterval('P1D'));
}
$now = new DateTime();
$isInInterval = $now >= $period['start'] && $now <= $period['end'];
var_dump($isInInterval);
class Interval
{
private $data;
private $timezone;
private $start;
private $end;
public function __construct($serialized, $timezoneName = 'UTC')
{
$this->parse($serialized);
$this->timezone = new DateTimeZone($timezoneName);
$this->makeStart();
$this->makeEnd();
}
public function contains(DateTimeInterface $date)
{
return $date >= $this->start && $date <= $this->end;
}
public function isNow()
{
$now = new DateTimeImmutable('now', $this->timezone);
return $this->contains($now);
}
private function parse($serialized)
{
$parts = explode('-', $serialized);
$this->data = [
'start' => $this->parsePart($parts[0]),
'end' => $this->parsePart($parts[1]),
];
}
private function makeStart()
{
$this->start = $this->makeDate($this->data['start']['hour'], $this->data['start']['minute']);
}
private function makeEnd()
{
$this->end = $this->makeDate($this->data['end']['hour'], $this->data['end']['minute']);
$this->ensureEndIsAfterStart();
}
private function parsePart($part)
{
list($hour, $minute) = explode(':', $part);
return [
'hour' => $hour,
'minute' => $minute,
];
}
private function makeDate($hour, $minute)
{
list($day, $month, $year) = explode('.', date('d.m.Y'));
$date = new DateTime('now', $this->timezone);
$date->setDate($year, $month, $day);
$date->setTime($hour, $minute);
return $date;
}
private function ensureEndIsAfterStart()
{
if ($this->start > $this->end)
{
$this->end->add(new DateInterval('P1D'));
}
}
}
// Примеры использования:
$interval = new Interval('11:59-02:00', 'Europe/Moscow');
var_dump($interval->isNow());
$date = new DateTime('now', new DateTimeZone('Europe/Moscow'));
$date->add(new DateInterval('PT8H'));
var_dump($interval->contains($date));