/** * @param string $event * @param callable|null $callback */ public function unbind($event, callable $callback = null) { $event = (string) $event; if (null === $callback) { unset($this->_callbacks[$event]); } else { $this->_callbacks[$event] = \Functional\reject($this->_callbacks[$event], function ($element) use($callback) { return $callback === $element; }); } }
/** * @return DateTimeZone|null */ public function getTimeZone() { $pointCurrent = $this->getGeoPoint(); if (null === $pointCurrent) { return null; } $timezoneNameList = \Functional\reject(DateTimeZone::listIdentifiers(), function ($timeZoneName) { return null === IntlTimeZone::fromDateTimeZone(new DateTimeZone($timeZoneName)); }); $distanceList = Functional\map($timezoneNameList, function ($timezoneName) use($pointCurrent) { $timezoneLocation = (new DateTimeZone($timezoneName))->getLocation(); $pointTimeZone = new CM_Geo_Point($timezoneLocation['latitude'], $timezoneLocation['longitude']); return ['timezoneName' => $timezoneName, 'distance' => $pointCurrent->calculateDistanceTo($pointTimeZone)]; }); $closestDistance = Functional\reduce_left($distanceList, function (array $current, $index, $collection, array $minimal) { return $current['distance'] < $minimal['distance'] ? $current : $minimal; }, $distanceList[0]); return new DateTimeZone($closestDistance['timezoneName']); }
public function testGetFormatterDateException() { $timezoneNameList = \Functional\reject(DateTimeZone::listIdentifiers(), function ($timeZoneName) { return IntlTimeZone::fromDateTimeZone(new DateTimeZone($timeZoneName)); }); if (empty($timezoneNameList)) { $this->markTestSkipped('No unsupported timezones'); } try { $timeZoneName = \Functional\first($timezoneNameList); $render = new CM_Frontend_Render(); $render->getFormatterDate(IntlDateFormatter::SHORT, IntlDateFormatter::SHORT, null, new DateTimeZone($timeZoneName)); $this->fail('Date formatter created with unsupported timezone'); } catch (CM_Exception $ex) { $this->assertSame('Cannot create date formatter', $ex->getMessage()); } }
/** * @param AbstractContext $context */ public function removeByContext(AbstractContext $context) { $this->_list = \Functional\reject($this->_list, function (Override $override) use($context) { return $override->getContext()->equals($context); }); }