/** * @ignore */ public static function onThirdPartyUpdateByPackageManager() { if (!self::isInCliMode()) { // This method can be run in CLI mode only. assert('false', vs(isset($this), get_defined_vars())); } $timeoutPause = new CTimeoutPause(); CShell::speak("Processing third-party components ..."); $tpDps = CFile::listDirectories(CFilePath::absolute($GLOBALS["PHRED_PATH_TO_THIRD_PARTY"])); $ignorePackages = CConfiguration::option("upd.thirdPartyOopWrappingIgnorePackages"); $ignorePackagesL2 = CArray::filter($ignorePackages, function ($package) { return CString::find($package, "/"); }); $newTpDps = CArray::make(); $len = CArray::length($tpDps); for ($i = 0; $i < $len; $i++) { $tpDp = $tpDps[$i]; $dirName = CFilePath::name($tpDp); if (!CArray::find($ignorePackages, $dirName)) { $dpHasL2DirsToIgnore = CArray::find($ignorePackagesL2, $dirName, function ($packageL2, $dirName) { return CString::equals(CFilePath::directory($packageL2), $dirName); }); if (!$dpHasL2DirsToIgnore) { CArray::push($newTpDps, $tpDp); } else { $tpSubDps = CFile::listDirectories($tpDp); $tpSubDps = CArray::filter($tpSubDps, function ($subDp) use($ignorePackagesL2) { return !CArray::find($ignorePackagesL2, $subDp, function ($packageL2, $subDp) { return CString::endsWith($subDp, $packageL2); }); }); CArray::pushArray($newTpDps, $tpSubDps); } } } $tpDps = $newTpDps; $wrapProtectedMethods = CConfiguration::option("upd.thirdPartyOopWrappingInProtectedMethods"); $wrapPrivateMethods = CConfiguration::option("upd.thirdPartyOopWrappingInPrivateMethods"); static $s_stdPhpTag = "<?php"; static $s_progressResolution = 0.05; $prevProgressDivR = 0; $tpDpsLen = CArray::length($tpDps); for ($i0 = 0; $i0 < $tpDpsLen; $i0++) { $tpFps = CFile::reFindFilesRecursive($tpDps[$i0], "/\\.php\\d?\\z/"); $tpFpsLen = CArray::length($tpFps); for ($i1 = 0; $i1 < $tpFpsLen; $i1++) { $fileCode = CFile::read($tpFps[$i1]); if (!CString::find($fileCode, self::$ms_thirdPartyAlreadyOopWrappedMark)) { $parser = new PhpParser\Parser(new PhpParser\Lexer()); try { // Parse the code. $statements = $parser->parse($fileCode); // Wrap the code into OOP. $traverser = new PhpParser\NodeTraverser(); $mainVisitor = new CMainVisitor($wrapProtectedMethods, $wrapPrivateMethods); $traverser->addVisitor($mainVisitor); $statements = $traverser->traverse($statements); $wrappedCode = (new PhpParser\PrettyPrinter\Standard())->prettyPrint($statements); $phpTagPos = CString::indexOf($wrappedCode, $s_stdPhpTag); if ($phpTagPos == -1) { $wrappedCode = "{$s_stdPhpTag}\n\n{$wrappedCode}"; $phpTagPos = 0; } $wrappedCode = CString::insert($wrappedCode, $phpTagPos + CString::length($s_stdPhpTag), "\n\n" . self::$ms_thirdPartyAlreadyOopWrappedMark); // Save. CFile::write($tpFps[$i1], $wrappedCode); } catch (PhpParser\Error $parserError) { CShell::say("\nPhpParser: " . $tpFps[$i1] . ", at line " . $parserError->getRawLine() . ": " . $parserError->getRawMessage()); } } $progress = (double) ($i0 / $tpDpsLen + 1 / $tpDpsLen * $i1 / $tpFpsLen); $progressDivR = CMathi::floor($progress / $s_progressResolution); if ($progressDivR != $prevProgressDivR) { $perc = CMathi::round($progressDivR * $s_progressResolution * 100); CShell::speak("{$perc}%"); } $prevProgressDivR = $progressDivR; } } CShell::speak("100%"); CShell::say("Done."); $timeoutPause->end(); }
/** * Returns the path to the directory where the running script is located. * * @return CUStringObject The path to the directory where the running script is located. */ public static function scriptDp() { return CFilePath::directory(CSystem::initScriptFp()); }
/** * Generates a CID for a file by which the file can be embedded into the body of a message. * * The same CID can be used to embed a file in more than one place. * * For example, an image for which a CID was generated and put into `$cid` variable can be embedded into a message * with HTML type of body by `<img src="' . $cid . '" alt="Title" />`. * * @param string $embedFp The path to the file to be embedded. * * @return CUStringObject The embeddable CID of the file. */ public function embeddableCidForFile($embedFp) { assert('is_cstring($embedFp)', vs(isset($this), get_defined_vars())); assert('isset($this->m_swiftMessage)', vs(isset($this), get_defined_vars())); $embedFp = CFilePath::frameworkPath($embedFp); $embeddedFile = Swift_EmbeddedFile::fromPath($embedFp); return $this->m_swiftMessage->embed($embeddedFile); }
/** * Sets the SSL options for a request. * * @param string $certificateFp The path to the certificate's file. * @param string $privateKeyFp **OPTIONAL. Default is** *none*. The path to the private key's file. * @param string $certificateFormat **OPTIONAL. Default is** "PEM". The format used by the certificate. * @param string $privateKeyFormat **OPTIONAL. Default is** "PEM". The format used by the private key. * @param string $certificatePassphrase **OPTIONAL. Default is** *none*. The passphrase used by the certificate. * @param string $privateKeyPassphrase **OPTIONAL. Default is** *none*. The passphrase used by the private key. * @param int $sslVersion **OPTIONAL. Default is** *cURL's default*. The SSL version to be used in the * communication. * @param string $cipherList **OPTIONAL. Default is** *cURL's default*. The ciphers to be used. * @param string $engine **OPTIONAL. Default is** *cURL's default*. The SSL engine identifier. * @param string $defaultEngine **OPTIONAL. Default is** *cURL's default*. The identifier of the actual crypto * engine to be used as the default engine for (asymmetric) crypto operations. * * @return void */ public function setSslOptions($certificateFp, $privateKeyFp = null, $certificateFormat = "PEM", $privateKeyFormat = "PEM", $certificatePassphrase = null, $privateKeyPassphrase = null, $sslVersion = null, $cipherList = null, $engine = null, $defaultEngine = null) { assert('is_cstring($certificateFp) && (!isset($privateKeyFp) || is_cstring($privateKeyFp)) && ' . 'is_cstring($certificateFormat) && is_cstring($privateKeyFormat) && ' . '(!isset($certificatePassphrase) || is_cstring($certificatePassphrase)) && ' . '(!isset($privateKeyPassphrase) || is_cstring($privateKeyPassphrase)) && ' . '(!isset($sslVersion) || is_int($sslVersion)) && ' . '(!isset($cipherList) || is_cstring($cipherList)) && (!isset($engine) || is_cstring($engine)) && ' . '(!isset($defaultEngine) || is_cstring($defaultEngine))', vs(isset($this), get_defined_vars())); assert('CFilePath::isAbsolute($certificateFp)', vs(isset($this), get_defined_vars())); assert('!isset($privateKeyFp) || CFilePath::isAbsolute($privateKeyFp)', vs(isset($this), get_defined_vars())); $this->m_sslCertificateFp = CFilePath::frameworkPath($certificateFp); $this->m_sslPrivateKeyFp = CFilePath::frameworkPath($privateKeyFp); $this->m_sslCertificateFormat = $certificateFormat; $this->m_sslPrivateKeyFormat = $privateKeyFormat; $this->m_sslCertificatePassphrase = $certificatePassphrase; $this->m_sslPrivateKeyPassphrase = $privateKeyPassphrase; $this->m_sslVersion = $sslVersion; $this->m_sslCipherList = $cipherList; $this->m_sslEngine = $engine; $this->m_sslDefaultEngine = $defaultEngine; }
public function testFilePath() { $filePath = CFile::createTemporary(); $file = new CFile($filePath, CFile::READ); $this->assertTrue(CFilePath::name($file->filePath())->startsWith(CFile::DEFAULT_TEMPORARY_FILE_PREFIX)); $file->done(); // only needed in these tests CFile::delete($filePath); }
/** * Computes more of the hash from a file. * * @param string $dataFp The path to the source file. * * @return void */ public function computeMoreFromFile($dataFp) { assert('is_cstring($dataFp)', vs(isset($this), get_defined_vars())); $dataFp = CFilePath::frameworkPath($dataFp); hash_update_file($this->m_hashingContext, $dataFp); }
protected static function recurseFindItems($directoryPath, $wc, $sort) { $items = self::findItems(CFilePath::add($directoryPath, $wc), $sort); $dirs = self::findDirectories(CFilePath::add($directoryPath, "*"), $sort); $dirQty = CArray::length($dirs); for ($i = 0; $i < $dirQty; $i++) { CArray::pushArray($items, self::recurseFindItems($dirs[$i], $wc, $sort)); } return $items; }
<?php require __DIR__ . "/Bootstrap/Phred.php"; echo passthru(CFilePath::frameworkPath("cd {{PHRED_PATH_TO_FRAMEWORK_ROOT}}; php ThirdParty/bin/phpunit --colors"));
/** * @ignore */ public static function initialize() { $configDp = CFilePath::add($GLOBALS["PHRED_PATH_TO_APP"], "Configuration"); $configEnvsDp = CFilePath::add($configDp, "Environments"); $configs = CArray::make(); $currEnv; if ($GLOBALS["PHRED_TESTS"]) { $currEnv = "tst"; } // Main configuration files. $configFps = CFile::findFiles(CFilePath::add($configDp, "*.json")); $numConfigs = CArray::length($configFps); for ($i = 0; $i < $numConfigs; $i++) { $configFp = $configFps[$i]; $configName = CFilePath::nameOnly($configFp); self::readAndAddConfig($configFp, $configName, $configs); if (!isset($currEnv) && CString::equals($configName, "Application")) { $config = CArray::last($configs); $currEnv = $config[self::$ms_configAliases["Application"]]["environment"]; } } assert('is_cstring($currEnv)', vs(isset($this), get_defined_vars())); // The configuration files from the current environment's directory. $currEnvDp = CFilePath::add($configEnvsDp, $currEnv); assert('CFile::exists($currEnvDp)', vs(isset($this), get_defined_vars())); $configFps = CFile::findFiles(CFilePath::add($currEnvDp, "*.json")); $numConfigs = CArray::length($configFps); for ($i = 0; $i < $numConfigs; $i++) { $configFp = $configFps[$i]; $configName = CFilePath::nameOnly($configFp); self::readAndAddConfig($configFp, $configName, $configs); } self::$ms_config = call_user_func_array("CMap::merge", CArray::toPArray($configs)); self::$ms_isInitialized = true; }
public function testFrameworkPath() { $this->assertTrue(CFilePath::absolute(CFilePath::frameworkPath("{{PHRED_PATH_TO_APP}}/Tests"))->equals(CFilePath::absolute(CFilePath::add($GLOBALS["PHRED_PATH_TO_APP"], "/Tests")))); $this->assertTrue(CFilePath::absolute(CFilePath::frameworkPath("{{PHRED_PATH_TO_FRAMEWORK_ROOT}}/Application/Tests"))->equals(CFilePath::absolute(CFilePath::add($GLOBALS["PHRED_PATH_TO_FRAMEWORK_ROOT"], "/Application/Tests")))); $this->assertTrue(CFilePath::absolute(CFilePath::frameworkPath("{{PHRED_PATH_TO_APP}}Tests"))->equals(CFilePath::absolute(CFilePath::add($GLOBALS["PHRED_PATH_TO_APP"], "/Tests")))); }