private function _setDefaultHeadersContent(ehough_shortstop_api_HttpRequest $request) { $entity = $request->getEntity(); if ($entity === null) { if ($this->_isDebugEnabled) { $this->_logger->debug('No HTTP entity in request'); } return; } $contentLength = $entity->getContentLength(); $content = $entity->getContent(); $type = $entity->getContentType(); if ($content !== null && $contentLength !== null && $type !== null) { $request->setHeader(ehough_shortstop_api_HttpMessage::HTTP_HEADER_CONTENT_LENGTH, "{$contentLength}"); $request->setHeader(ehough_shortstop_api_HttpMessage::HTTP_HEADER_CONTENT_TYPE, $type); return; } if ($contentLength === null && $this->_isDebugEnabled) { $this->_logger->warn('HTTP entity in request, but no content length set. Ignoring this entity!'); } if ($content === null && $this->_isDebugEnabled) { $this->_logger->warn('HTTP entity in request, but no content set. Ignoring this entity!'); } if ($type === null && $this->_isDebugEnabled) { $this->_logger->warn('HTTP entity in request, but no content type set. Ignoring this entity!'); } }
private function _readConfig() { $envDetector = tubepress_impl_patterns_sl_ServiceLocator::getEnvironmentDetector(); $userContentDirectory = $envDetector->getUserContentDirectory(); $configFileLocation = $userContentDirectory . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'boot.json'; if (!is_file($configFileLocation) || !is_readable($configFileLocation)) { if ($this->_shouldLog) { $this->_logger->debug(sprintf('No readable config file at %s', $configFileLocation)); } return; } if ($this->_shouldLog) { $this->_logger->debug(sprintf('Attempting to read boot config from %s', $configFileLocation)); } $contents = file_get_contents($configFileLocation); if ($contents === false) { if ($this->_shouldLog) { $this->_logger->warn(sprintf('Failed to read file contents of %s', $configFileLocation)); } return; } $decoded = @json_decode($contents, true); if ($decoded === false || !is_array($decoded)) { if ($this->_shouldLog) { $this->_logger->warn(sprintf('Failed to parse %s', $configFileLocation)); } } if ($this->_shouldLog) { $this->_logger->debug(sprintf('Successfully read boot config from %s', $configFileLocation)); } $this->_bootConfig = $decoded; }
private function _logWarning($message) { if (!$this->_shouldLog) { return; } $this->_logger->warn($message); }
/** * @param object $object The object to convert to a string for the cache. * * @return string The string representation of the object, or null if there was a problem. */ protected function toString($object) { $dumpConfig = array('class' => 'TubePressServiceContainer', 'base_class' => 'ehough_iconic_ContainerBuilder'); try { $dumper = new ehough_iconic_dumper_PhpDumper($object); return $dumper->dump($dumpConfig); } catch (Exception $e) { if ($this->_shouldLog) { $this->_logger->warn('Caught exception trying to dump IOC container: ' . $e->getMessage()); } return null; } }
/** * Register a new option descriptor for use by TubePress. * * @param tubepress_spi_options_OptionDescriptor $optionDescriptor The new option descriptor. * * @return void */ private function _registerOptionDescriptor(tubepress_spi_options_OptionDescriptor $optionDescriptor) { $name = $optionDescriptor->getName(); if (isset($this->_nameToOptionDescriptorMap[$name])) { if ($this->_shouldLog) { $this->_logger->warn($optionDescriptor->getName() . ' is already registered as an option descriptor'); } return; } $optionRegistrationEvent = new tubepress_spi_event_EventBase($optionDescriptor); $eventDispatcher = tubepress_impl_patterns_sl_ServiceLocator::getEventDispatcher(); $eventDispatcher->dispatch(tubepress_api_const_event_EventNames::OPTIONS_DESCRIPTOR_REGISTRATION, $optionRegistrationEvent); $this->_nameToOptionDescriptorMap[$name] = $optionDescriptor; }
/** * Spits back the text for this embedded player * * @param string $videoId The video ID to display * * @return string The text for this embedded player, or null if there was a problem. */ public final function getHtml($videoId) { $embeddedPlayer = $this->_getEmbeddedPlayer($videoId); if ($embeddedPlayer === null) { if ($this->_logger->isHandling(ehough_epilog_Logger::DEBUG)) { $this->_logger->warn('Could not generate the embedded player HTML for ' . $videoId); } return null; } $themeHandler = tubepress_impl_patterns_sl_ServiceLocator::getThemeHandler(); $eventDispatcherService = tubepress_impl_patterns_sl_ServiceLocator::getEventDispatcher(); $template = $embeddedPlayer->getTemplate($themeHandler); $dataUrl = $embeddedPlayer->getDataUrlForVideo($videoId); $embeddedPlayerName = $embeddedPlayer->getName(); $providerName = $embeddedPlayer->getHandledProviderName(); /** * Build the embedded template event. */ $embeddedTemplateEvent = new tubepress_spi_event_EventBase($template, array('videoId' => $videoId, 'providerName' => $providerName, 'dataUrl' => $dataUrl, 'embeddedImplementationName' => $embeddedPlayerName)); /** * Dispatch the embedded template event. */ $eventDispatcherService->dispatch(tubepress_api_const_event_EventNames::TEMPLATE_EMBEDDED, $embeddedTemplateEvent); /** * Pull the template out of the event. */ $template = $embeddedTemplateEvent->getSubject(); /** * Build the embedded HTML event. */ $embeddedHtmlEvent = new tubepress_spi_event_EventBase($template->toString(), array('videoId' => $videoId, 'providerName' => $providerName, 'dataUrl' => $dataUrl, 'embeddedImplementationName' => $embeddedPlayerName)); /** * Dispatche the embedded HTML event. */ $eventDispatcherService->dispatch(tubepress_api_const_event_EventNames::HTML_EMBEDDED, $embeddedHtmlEvent); return $embeddedHtmlEvent->getSubject(); }
private function _tryToBuildAddonFromFile(SplFileInfo $infoFile) { $manifestFilePath = realpath("{$infoFile}"); $infoFileContents = @json_decode(file_get_contents($manifestFilePath), true); $shouldLog = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG); if ($infoFileContents === null || $infoFileContents === false || empty($infoFileContents)) { if ($shouldLog) { $this->_logger->debug('Could not parse add-on manifest file at ' . $manifestFilePath); } return null; } try { return $this->_constructAddonFromArray($infoFileContents, $manifestFilePath); } catch (Exception $e) { if ($shouldLog) { $this->_logger->warn('Caught exception when parsing info file at ' . $infoFile->getRealpath() . ': ' . $e->getMessage()); } return null; } }
/** * Sets the value of an option * * @param string $optionName The name of the option * @param mixed $optionValue The option value * * @return mixed True if the option was set normally, otherwise a string error message. */ public final function set($optionName, $optionValue) { $eventDispatcherService = tubepress_impl_patterns_sl_ServiceLocator::getEventDispatcher(); $optionValidatorService = tubepress_impl_patterns_sl_ServiceLocator::getOptionValidator(); /** First run it through the filters. */ /** Run it through the filters. */ $event = new tubepress_spi_event_EventBase($optionValue, array('optionName' => $optionName)); $eventDispatcherService->dispatch(tubepress_api_const_event_EventNames::OPTIONS_NVP_PREVALIDATIONSET, $event); $filteredValue = $event->getSubject(); if ($optionValidatorService->isValid($optionName, $filteredValue)) { if ($this->_logger->isHandling(ehough_epilog_Logger::DEBUG)) { $this->_logger->debug(sprintf('Accepted valid value: %s = %s', $optionName, $this->_normalizeForStringOutput($filteredValue))); } $this->_customOptions[$optionName] = $filteredValue; return true; } $problemMessage = $optionValidatorService->getProblemMessage($optionName, $filteredValue); if ($this->_logger->isHandling(ehough_epilog_Logger::DEBUG)) { $this->_logger->warn(sprintf('Ignoring invalid value for "%s" (%s)', $optionName, $problemMessage)); } return $problemMessage; }
private function _killCacheIfNeeded(ehough_epilog_Logger $logger, $shouldLog) { $bootConfigService = tubepress_impl_patterns_sl_ServiceLocator::getBootHelperConfigService(); $shouldKillCache = $bootConfigService->isCacheKillerTurnedOn(); if (!$shouldKillCache) { return; } $elementName = $this->getBootCacheConfigElementName(); $filePath = $bootConfigService->getAbsolutePathToCacheFileForElement($elementName); if (!file_exists($filePath)) { return; } if ($shouldLog) { $logger->debug(sprintf('Attempting to delete cache file for %s at %s', $elementName, $filePath)); } $result = @unlink($filePath); if (!$shouldLog) { return; } if ($result === true) { $logger->debug(sprintf('Successfully deleted cache file for %s at %s', $elementName, $filePath)); } else { $logger->warn(sprintf('Could not delete cache file for %s at %s. Please delete it manually.', $elementName, $filePath)); } }