<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Do', function ($Call) { if (self::$_Performance or F::Environment() === 'Development') { $Call['Performance']['Summary']['Time'] = round((microtime(true) - Started) * 1000); $Call['Performance']['Summary']['Calls'] = array_sum(self::$_Counters['C']); arsort(self::$_Counters['T']); F::Log('Max stack size: ' . F::Get('MSS'), LOG_NOTICE, 'Performance'); F::Log('Total time: ' . round($Call['Performance']['Summary']['Time']) . ' ms', LOG_NOTICE, 'Performance'); F::Log('Total calls: ' . $Call['Performance']['Summary']['Calls'], LOG_NOTICE, 'Performance'); F::Log('Total time per call: ' . round($Call['Performance']['Summary']['Time'] / $Call['Performance']['Summary']['Calls'], 2) . ' ms', LOG_NOTICE, 'Performance'); F::Log('Memory: ' . memory_get_usage(true) / 1024 . 'Kb ', LOG_NOTICE, 'Performance'); F::Log('Peak memory: ' . memory_get_peak_usage(true) / 1024 . 'Kb', LOG_NOTICE, 'Performance'); foreach (self::$_Counters['T'] as $Key => $Value) { if (!isset(self::$_Counters['C'][$Key])) { self::$_Counters['C'][$Key] = 1; } $Class = ['ATime' => LOG_DEBUG, 'RTime' => LOG_DEBUG, 'ACalls' => LOG_DEBUG, 'RCalls' => LOG_DEBUG, 'TimePerCall' => LOG_DEBUG]; $Call['RTime'] = round($Value / $Call['Performance']['Summary']['Time'] * 100, 2); $Call['RCalls'] = round(self::$_Counters['C'][$Key] / $Call['Performance']['Summary']['Calls'] * 100, 2); $Call['ATime'] = round($Value); $Call['ACalls'] = self::$_Counters['C'][$Key]; $Call['TimePerCall'] = round($Value / self::$_Counters['C'][$Key], 2); if (isset($Call['Alerts']['Yellow'])) { foreach ($Call['Alerts']['Yellow'] as $Metric => $Limit) {
function d() { if (F::Environment() != 'Production' or PHP_SAPI == 'cli') { call_user_func_array(['F', 'Dump'], func_get_args()); } return func_get_arg(2); }
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Do', function ($Call) { if (is_array($Call['Project']['Hosts'][F::Environment()])) { $Hosts = $Call['Project']['Hosts'][F::Environment()]; } else { $Hosts = [$Call['Project']['Hosts'][F::Environment()]]; } // Select Default Host if (isset($_SERVER['HTTP_HOST'])) { if (in_array($_SERVER['HTTP_HOST'], $Hosts)) { $Call['HTTP']['Host'] = $_SERVER['HTTP_HOST']; } } if (isset($Call['HTTP']['Host'])) { F::Log('Host is determined: *' . $Call['HTTP']['Host'] . '*', LOG_INFO); } else { $Call['HTTP']['Host'] = $Hosts[0]; F::Log('Host is not determined, default selected', LOG_WARNING); } if (isset($Call['Project']['Active Hosts'][$Call['HTTP']['Host']])) { $Call = F::Merge($Call, $Call['Project']['Active Hosts'][$Call['HTTP']['Host']]); F::Log('Active host loaded: *' . $Call['HTTP']['Host'] . '*', LOG_INFO); } return $Call;
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Do', function ($Call) { F::Log('CLI Interface Started', LOG_NOTICE); $Call = F::Hook('beforeInterfaceRun', $Call); $Call['HTTP']['IP'] = F::Live($Call['HTTP']['IP'], $Call); if (isset($Call['Project']['Hosts'][F::Environment()])) { $Call['HTTP']['Host'] = $Call['Project']['Hosts'][F::Environment()]; } $Call['HTTP']['Proto'] = 'https'; $Call['HTTP']['URL'] = '/'; if (isset($Call['Skip Run'])) { F::Log('Run Skipped, because ' . $Call['Skip Run'], LOG_INFO); } else { F::Log($Call['Service'] . ':' . $Call['Method'] . ' started', LOG_NOTICE); $Call = F::Apply($Call['Service'], $Call['Method'], $Call); } $Call = F::Hook('afterInterfaceRun', $Call); if (is_array($Call) && isset($Call['Output'])) { F::Run('IO', 'Write', $Call, ['Storage' => 'Output', 'Where' => $Call['Service'] . ':' . $Call['Method'], 'Data' => $Call['Output']]); if (isset($Call['Failure']) && $Call['Failure']) { $Call['Return Code'] = 1; } } F::Log('CLI Finished', LOG_NOTICE);
<?php /* Codeine * @author bergstein@trickyplan.com * @description Exec Parslet * @package Codeine * @version 6.0 */ setFn('Parse', function ($Call) { foreach ($Call['Parsed'][2] as $IX => $Match) { $Root = simplexml_load_string('<root ' . $Call['Parsed'][1][$IX] . '></root>'); $Environment = isset($Root->attributes()->eq) ? (string) $Root->attributes()->eq : null; if ($Environment == F::Environment()) { $Outer = $Match; } else { $Outer = ''; } $NotEnvironment = isset($Root->attributes()->neq) ? (string) $Root->attributes()->neq : null; if ($NotEnvironment !== null) { if ($NotEnvironment == F::Environment()) { $Outer = ''; } else { $Outer = $Match; } } $Call['Output'] = str_replace($Call['Parsed'][0][$IX], $Outer, $Call['Output']); } return $Call; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Run', function ($Call) { $Script = F::loadOptions($Call['Run'], null, [], 'Scripts'); $VCall = $Call; $VCall['Environment'] = F::Environment(); foreach ($Script as $Run) { $VCall = F::Live($Run, $VCall); } $Call['Output']['Content'] = [$VCall]; return $Call; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Make', function ($Call) { // FIXME Templatize $Call['Options']['id'] = $Call['ID']; $Code = ''; if (isset($Call['DNT Support']) && F::Run('System.Interface.HTTP.DNT', 'Detect', $Call)) { $Code = '<!-- Do Not Track enabled. Yandex Metrics supressed. -->'; } else { if (F::Environment() == 'Production') { $Code = '<!-- Yandex.Metrika counter --><script type="text/javascript">(function (d, w, c) { (w[c] = w[c] || []).push(function() { try { w.yaCounter' . $Call['Options']['id'] . ' = new Ya.Metrika({id:' . $Call['Options']['id'] . ', webvisor:true, clickmap:true, trackLinks:true, accurateTrackBounce:true, trackHash:true}); } catch(e) { } }); var n = d.getElementsByTagName("script")[0], s = d.createElement("script"), f = function () { n.parentNode.insertBefore(s, n); }; s.type = "text/javascript"; s.async = true; s.src = (d.location.protocol == "https:" ? "https:" : "http:") + "//mc.yandex.ru/metrika/watch.js"; if (w.opera == "[object Opera]") { d.addEventListener("DOMContentLoaded", f, false); } else { f(); } })(document, window, "yandex_metrika_callbacks");</script><noscript><div><img src="//mc.yandex.ru/watch/' . $Call['Options']['id'] . '" style="position:absolute; left:-9999px;" alt="" /></div></noscript><!-- /Yandex.Metrika counter -->'; } } return $Code; });
$ID = array_pop($LocaleParts); $Asset = implode('.', $LocaleParts); $Asset = strtr($Asset, '.', '/'); $NewLocales = F::Run('IO', 'Read', ['Storage' => 'Locale', 'Scope' => $Asset . '/Locale/' . $Call['Locale'], 'Where' => $ID]); $Locales[$Locale] = []; if (is_array($NewLocales)) { $NewLocales = array_reverse($NewLocales); foreach ($NewLocales as $NewLocale) { $Locales[$Locale] = F::Merge($Locales[$Locale], $NewLocale); } } else { F::Log('Locale ' . $Locale . ' not loaded', LOG_NOTICE); } } if (($Replace = F::Dot($Locales[$Locale], $Token)) !== null) { if (is_scalar($Replace)) { $Match = $Replace; } } else { F::Log('Unresolved locale *' . $Match . '*', LOG_WARNING); if (F::Environment() === 'Development') { $Match = '<span class="nl">' . $Match . '</span>'; } else { $Match = ''; } } } $Call['Output'] = str_replace($Call['Parsed'][0], $Call['Parsed'][1], $Call['Output']); } return $Call; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Do', function ($Call) { $Call['Layouts'][] = ['Scope' => 'Server', 'ID' => 'Benchmark']; $Call = F::Hook('beforeBenchmark', $Call); $Call['Overall'] = 0; foreach ($Call['Benchmark']['Modules'] as $BenchmarkName => $BenchmarkCall) { $Rate = round(F::Run('Server.Benchmark.' . $BenchmarkName, 'Test', $BenchmarkCall) * $BenchmarkCall['Weight'], 2); $Results[] = [$BenchmarkName, $Rate]; $Call['Overall'] += $Rate; } $Call['Output']['Overall'][] = $Call['Overall']; $Call['Output']['Results'][] = ['Type' => 'Table', 'Value' => $Results]; $Call = F::Hook('afterBenchmark', $Call); return $Call; }); setFn('Send', function ($Call) { $Result = F::Run('IO', 'Write', ['Storage' => 'Web', 'Output Format' => 'Formats.JSON', 'Where' => ['ID' => 'https://codeine-framework.org/benchmarks'], 'Data' => ['Host' => $Call['HTTP']['Host'], 'Score' => $Call['Overall'], 'Environment' => F::Environment(), 'Version' => $Call['Benchmark']['Version']]])[0]; $Call['Output']['Top'][] = $Result['Your']; $Call['Output']['Total'][] = $Result['Total']; return $Call; });