/** * Tests whether writeFile() creates parent directories. * * @return void */ public function testWriteFileCreatesParentDirectories() { $filePath = ABLERON_TEMP_DIR . '/FileUtilTest/writeFile/testWriteFileCreatesParentDirectories-' . StringUtil::getRandomString(12); $this->assertTrue(FileUtil::writeFile($filePath)); $this->assertTrue(is_file($filePath)); $this->assertTrue(is_writable(dirname($filePath))); unlink($filePath); }
/** * Initializes the entity. * * @param \Ableron\Modules\Core\Model\Entities\UserEntity $user The user belonging to the session */ public function __construct(UserEntity $user = null) { $this->id = StringUtil::getRandomString(24); $this->setCreationTime(DateUtil::getCurrentUtcDateTime()); $this->setLastActivityTime($this->getCreationTime()); $this->data = array(); // TODO if ($user !== null) { $this->setUser($user); } }
/** * Replaces all literal-tags of the given template with unique values in * order to prevent them from getting compiled. * * @param string $template The template to replace the literal tags of * @return string */ private function replaceLiteralTags($template) { return preg_replace_callback("#{literal}\n?(.*?)\n?{/literal}#s", function ($match) { // generate content key $contentKey = StringUtil::getRandomString(40); // save content $this->literalTags[$contentKey] = $match[1]; // return content key return $contentKey; }, $template); }
/** * Returns the absolute path of a temporary file. * * @param string $subDirectory Sub directory of the temp directory the file shall be located in * @param string $filePrefix Prefix of the temp file * @param string $fileName Name of the temp file * @param string $fileExtension File extension of the temp file * @return string */ public static function getTempFileName(string $subDirectory = '', string $filePrefix = '', string $fileName = '', string $fileExtension = 'tmp') { // get temp directory $tempDirectory = self::normalizePath(ABLERON_TEMP_DIR . '/' . $subDirectory); // get temp file name $tempFileName = sprintf('%s%s%s', $filePrefix, $fileName === '' ? StringUtil::getRandomString(32) : $fileName, ltrim($fileExtension, '.') === '' ? '' : '.' . ltrim($fileExtension, '.')); // return absolute path return sprintf('%s/%s', $tempDirectory, $tempFileName); }
/** * Takes care of possible CSRF attacks. * * Logs the possible attack and changes the current CSRF token. * * @return void */ private function handlePossibleCsrfAttack() { // log possible attack Application::getPersistenceManager()->getEntityManager()->persist(new CsrfAttemptEntity()); // invalidate session token by setting a new one Application::getSession()->setData($this->csrfTokensSessionKey, StringUtil::getRandomString($this->tokenLength)); }
public function getNewCacheInstance() { return new DataFileCache(ABLERON_CACHE_DIR . '/' . StringUtil::getRandomString(8)); }