Exemplo n.º 1
0
 public function requestCacheStore($module, $componentName)
 {
     if (!strlen($componentName) || !IoUtils::hasStrictSpecialChars($componentName)) {
         throw new \InvalidArgumentException('Component name is empty or contains strict special chars: ' . $componentName);
     }
     return new FileCacheStore($this->varStore->requestDirFsPath(VarStore::CATEGORY_TMP, $module, $componentName), $this->dirPerm, $this->filePerm);
 }
Exemplo n.º 2
0
Arquivo: VarStore.php Projeto: n2n/n2n
 private function validatePathPart($pathPart)
 {
     if (!IoUtils::hasSpecialChars($pathPart)) {
         return;
     }
     throw new \InvalidArgumentException('Path part contains invalid chars: ' . $pathPart);
 }
Exemplo n.º 3
0
Arquivo: N2nVars.php Projeto: n2n/n2n
 public function __construct($filePath)
 {
     $mimeTypesStr = IoUtils::getContents($filePath);
     foreach (explode("\n", str_replace("\r", '', $mimeTypesStr)) as $line) {
         $lineParts = preg_split('/\\s+/', $line);
         if (!sizeof($lineParts)) {
             continue;
         }
         $mimeType = array_shift($lineParts);
         foreach ($lineParts as $extension) {
             $this->extMimeTypeMappings[$extension] = $mimeType;
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Logs the passed Exception. This includes a mail and error info file if it is enabled in 
  * the app.ini. A log entry is also sent to log4php. If logging failed this method must throw 
  * any exceptions. Exceptions must be registered in the 
  * {@link ExceptionHandler::$pendingLogExceptions} property.
  * 
  * @param \Throwable $e
  */
 private function log(\Throwable $e)
 {
     if ($e instanceof StatusException && (!$this->logStatusExceptionsEnabled || in_array($e->getStatus(), $this->logExcludedHttpStatus))) {
         return;
     }
     $simpleMessage = $this->createSimpleLogMessage($e);
     error_log($simpleMessage, 0);
     if (isset($this->logDetailDirPath) || isset($this->logMailRecipient)) {
         $detailMessage = $this->createDetailLogMessage($e);
         if (isset($this->logMailRecipient)) {
             // @todo validate email
             $subject = 'An ' . get_class($e) . ' occurred';
             $header = 'From: ' . $this->logMailAddresser . "\r\n" . 'Reply-To: ' . $this->logMailAddresser . "\r\n" . 'X-Mailer: PHP/' . phpversion();
             @mail($this->logMailRecipient, $subject, $detailMessage, $header);
         }
         if (isset($this->logDetailDirPath)) {
             $defLogBasePath = $this->logDetailDirPath . DIRECTORY_SEPARATOR . date('Y-m-d_His') . str_replace('\\', '_', get_class($e));
             $ext = '';
             for ($i = 0; is_file($defLogBasePath . $ext . self::LOG_FILE_EXTENSION); $i++) {
                 $ext = '_' . $i;
             }
             $defLogPath = $defLogBasePath . $ext . self::LOG_FILE_EXTENSION;
             try {
                 IoUtils::putContents($defLogPath, $detailMessage);
                 IoUtils::chmod($defLogPath, $this->logDetailFilePerm);
             } catch (\Exception $e) {
                 $logE = $this->createLoggingFailedException($e);
                 $this->pendingLogException[spl_object_hash($logE)] = $logE;
             }
         }
     }
     // cannot log deprecated exception because class loader cant be called anymore if
     // "Deprecated: Call-time pass-by-reference has been deprecated"-Warning occoures.
     if (isset($this->logger) && $this->stable) {
         try {
             $this->logger->error($simpleMessage, $e);
         } catch (\Exception $e) {
             $logE = $this->createLoggingFailedException($e);
             $this->pendingLogException[spl_object_hash($logE)] = $logE;
         }
     }
 }
Exemplo n.º 5
0
 public static function createCodeInfo(string $fileName, int $line = null, int $startLineNo = null, int $endLineNo = null, string $message = null)
 {
     if ($line == 0) {
         $line = null;
         if ($startLineNo === null) {
             $startLineNo = 1;
         }
         if ($endLineNo === null) {
             $endLineNo = 4;
         }
     }
     $codeInfo = new CodeInfo($fileName, $line, $message);
     if ($line !== null) {
         if ($startLineNo === null) {
             $startLineNo = $line <= 2 ? 1 : $line - 2;
         }
         if ($endLineNo === null) {
             $endLineNo = $line + 2;
         }
     }
     if ($startLineNo === null || $endLineNo === null) {
         return $codeInfo;
     }
     $codeInfo->setStartLineNo($startLineNo);
     $codeInfo->setEndLineNo($endLineNo);
     $fileLines = null;
     try {
         $fileLines = IoUtils::file($fileName);
     } catch (IoException $e) {
         return $codeInfo;
     }
     $numLines = sizeof($fileLines);
     $startIndex = $startLineNo - 1;
     $endIndex = $endLineNo - 1;
     $snippetLines = array();
     for ($i = $startIndex; $i < $numLines && $i <= $endIndex; $i++) {
         $snippetLines[$i + 1] = $fileLines[$i];
     }
     $codeInfo->setSnippetLines($snippetLines);
     return $codeInfo;
 }
Exemplo n.º 6
0
 public function getNoIoStrictSpecialCharsString(string $attributeName, bool $mandatory, $defaultValue = null)
 {
     $def = $this->findAttributesDef($attributeName, $mandatory);
     if ($def === null) {
         return $defaultValue;
     }
     $str = null;
     try {
         $str = $def->getAttributes()->getString($attributeName);
     } catch (AttributesException $e) {
         throw $this->createInvalidAttributeException($attributeName, $def, $e);
     }
     if (IoUtils::hasStrictSpecialChars($str)) {
         throw $this->createInvalidAttributeException($attributeName, $def, new InvalidAttributeException('String must not contain any special chars.'));
     }
     return $defaultValue;
 }
Exemplo n.º 7
0
Arquivo: N2N.php Projeto: n2n/n2n
 /**
  * @param string $publicDirPath
  * @param string $varDirPath
  * @param array $moduleDirPaths
  */
 public static function initialize(string $publicDirPath, string $varDirPath, N2nCache $n2nCache, ModuleFactory $moduleFactory = null)
 {
     mb_internal_encoding(self::CHARSET);
     // 		ini_set('default_charset', self::CHARSET);
     self::$exceptionHandler = new ExceptionHandler(N2N::isDevelopmentModeOn());
     register_shutdown_function(array('n2n\\core\\N2N', 'shutdown'));
     self::$n2n = new N2N(new FsPath(IoUtils::realpath($publicDirPath)), new FsPath(IoUtils::realpath($varDirPath)));
     if ($moduleFactory === null) {
         $moduleFactory = new EtcModuleFactory();
     }
     self::$n2n->initModules($moduleFactory);
     self::$n2n->init($n2nCache);
     self::$initialized = true;
     self::initLogging(self::$n2n);
     self::$exceptionHandler->checkForStartupErrors();
 }
Exemplo n.º 8
0
Arquivo: Sync.php Projeto: n2n/n2n
 public function release()
 {
     IoUtils::flock($this->resource, LOCK_UN);
     if (!$this->exclusive && !flock($this->resource, LOCK_EX | LOCK_NB)) {
         fclose($this->resource);
         return;
     }
     fclose($this->resource);
     IoUtils::unlink($this->fileName);
 }