' . $html,
]);
if(!$container->get('kernel')->isCLI()){
$container->get('kernel')->flash()->error( $html );
}
// $this->getAppKernel()->end();
}//!maintenance
return false;
// return false;
}//!file || !is_array || !isset
$superAdminConfig = $superAdminConfig['superadmin'];
return $superAdminConfig;
}), //'config.superadmin'
\Psr\Http\Message\ServerRequestInterface::class => (function(ContainerInterface $container){
return $container->get('request');
}),
'request'=> (function(ContainerInterface $container){
// $class = $ContainerBuilder->get(\Psr\Http\Message\ServerRequestInterface::class);
// $request = $class::fromGlobals();
$request = \GuzzleHttp\Psr7\ServerRequest::fromGlobals();
$request = $request->withUri($request->getUri()->withHost($container->has('context.host')
? $container->get('context.host')
: $container->get('kernel')->context()['host']
));
$container->get('kernel')->context([
'request' => $request,
]);
return $request;
}),
'request.host'=> [function(ContainerInterface $container, $previous = null){
return $container->get('request')->getUri()->getHost();
}, 'factory'],
'app.runtime.schemes.required' =>function($container) {
return [
'frdl',
'webfan',
'webconfig', //'webtemp',
'website',// 'webapp', 'webmaster',
'web+fat',
//'websites', 'webapps', 'webusers',
//'webcentral',
'web+cdn',
'web+cta',
];
},
'logger.default' =>[function($container, $previous = null) {
$logger =new Logger('default');
$dir = $container->get('kernel')->getAppIntentDir('frdl', 'log', true);
if(!is_dir($dir)){
mkdir($dir, 0775, true);
}
if(!file_exists($dir.'default.log')){
touch($dir.'default.log');
}
$logger->pushHandler(new LoggerStreamHandler($dir.'default.log', LogLevel::DEBUG));
return $logger;
}, 'factory'],
'config.central.domains' => [function($container) {
$file = 'webconfig://domains/central.php';
if(!file_exists($file)){
if(!is_dir(dirname($file))){
mkdir(dirname($file), 0775, true);
}
\Laminas\Config\Factory::toFile($file, [
'domains'=>[
'service'=>[
'central' => $container->get('RequestDomainFactory')->getRegistrableDomain(),
'registrable'=>[
$container->get('RequestDomainFactory')->getRegistrableDomain(),
],
'api' => $container->get('RequestDomainFactory')->getRegistrableDomain(),
'cdn' => $container->get('RequestDomainFactory')->getRegistrableDomain(),
],
],
]);
}
if(file_exists($file)){
$container->get('runtime')->configure(
require $file
);
}
return $container->get('runtime')->getConfig()->has('domains.service')
? $container->get('runtime')->getConfig()->get('domains.service')
: false;
}, 'default'],
'config.central.domain' => [function($container) {
$central = $container->get('config.central.domains');
return is_array($central) && isset($central['central']) ? $central['central'] : false;
}, 'default'],
'config.vdns.dir' => [function($container) {
return 'webconfig://vdns';
}, 'default'],
'RequestDomain.suffixFile' => [function($container) {
return $container->get('config.vdns.dir').'/registrable-suffix.txt';
}, 'default'],
'RequestDomain' => [function($container) {
return $container->get('RequestDomainFactory');
}, 'default'],
'RequestDomainDNSHash' => [function($container) {
// return array_reverse(explode('.', $container->get('request')->getHost()));
return $container->has('RequestDomain')
? $container->get('RequestDomain')->labels()
// : array_reverse(explode('.', $container->get('request')->getHost()));
: array_reverse(explode('.', $container->get('request.host')));
}, 'default'],
'config.vdns.hostsfile.current.filename' => [function($container, $previous = null) {
$path = $container->get('config.vdns.dir');
$dns = $container->get('RequestDomainDNSHash');
$file = false;
while(count($dns)>0 && (false === $file || !\file_exists($file))){
$file = $path.'/'.implode('/', $dns);
array_pop($dns);
}
return $file;
}, 'factory'],
'config.vdns.hostsfile.current' => [function($container, $previous = null) {
$file = $container->get('config.vdns.hostsfile.current.filename');
if(false === $file || !\file_exists($file)){
$file = $container->get('config.vdns.dir').'/virtual-hosting-hosts';
}
return $file;
}, 'factory'],
'config.vdns.hostsfile.saveto' => [function($container, $previous = null) {
$path = $container->get('config.vdns.dir');
$dns = $container->get('RequestDomainDNSHash');
if(count($dns)>0){
$path.='/'.$dns[0];
}
if(count($dns)>1){
$path.='/'.$dns[1];
}
if(count($dns)>2){
$path.='/'.$dns[2];
}
return $path;
}, 'factory'],
'RequestDomainFactory' => [function($container, $previous = null) {
$suffixFile = $container->get('RequestDomain.suffixFile');
// $domain =new \Pdp\Domain($container->get('request')->getHost());
$domain =new \Pdp\Domain($container->get('request.host'));
$publicSuffixList = \Pdp\Rules::createFromString(\file_exists($suffixFile) ? file_get_contents($suffixFile) : '');
$result = $publicSuffixList->resolve($domain);
//// DEPRECTAED: print_r($result->getDomain()
//// ... ->getContent());
// print_r($result->getPublicSuffix() );
// print_r($result->getSubDomain());
// print_r($result->getRegistrableDomain());
// print_r($result->labels() );
return $result;
}, 'factory'],
'Document' => [function($container, $previous = null) {
return $container->get('kernel')->Document;
}, 'factory'],
'PHP_BIN_PATH' => [function($container, $previous = null) {
return (new \Webfan\Helper\PhpBinFinder())->find();
}, 'factory'],
'kernel' => [function($container, $previous = null) use(&$me) {
return $me;
}, 'factory'],
'Maintenance' => [function($container, $previous = null) {
return $container->get(Maintenance::class);
}, 'factory'],
Maintenance::class =>[function($container, $previous = null) {
return new Maintenance($container->get('kernel'));
}, 'factory'],
KernelHelper::class => function($container) use(&$me) {
return new KernelHelper($me);
},
$configContainerId => [function($container, $previous = null) use(&$me) {
return $me->global()->getConfig();
/*
if((isset($previous) && !is_null($previous) ) && (
( is_object($previous)
&& ($previous instanceof Configuration || $previous instanceof Config)
)
|| is_array($previous)
)
){
if(is_array($previous)){
return $me->global()->getConfig()->merge(Config::fromArray($previous));
}elseif(!is_null($previous)){
return $me->global()->getConfig()->merge($previous);
}
}else{
return $me->global()->getConfig();
}
*/
}, 'factory'],
'flash' =>[function($container, $previous = null) {
return $container->get('kernel')->flash();
}, 'factory'],
], ContainerCollection::NULL_ONERROR, ContainerCollection::CALL_ID);
$this->container->factory('logger.default', function($container, $previous = null) {
$logger = $previous;
$logger->pushProcessor( (new \Monolog\Processor\WebProcessor())->addExtraField('user_agent', 'HTTP_USER_AGENT') );
$logger->pushProcessor( new \Monolog\Processor\HostnameProcessor() );
$logger->pushProcessor( new \Monolog\Processor\ProcessIdProcessor() );
$logger->pushProcessor( new \Monolog\Processor\IntrospectionProcessor('error') );
return $logger;
});
$this->container->factory('logger.default', function($container, $previous = null) {
$logger = $previous;
$dir = $container->get('kernel')->getAppIntentDir('webfan', 'log', true);
if(!is_dir($dir)){
mkdir($dir, 0775, true);
}
if(!file_exists($dir.'default.log')){
touch($dir.'default.log');
}
$logger->pushHandler(new LoggerStreamHandler($dir.'default.log', LogLevel::DEBUG));
return $logger;
});
/* */
$this->container->factory('webfan://logger.default', function( $container, $previous = null) {
return $container->get('logger.default');
});
$this->container->factory('app.runtime.stub', function( $container, $previous = null) {
return $container->get('kernel')->getStub();
});
$this->container->factory('app.runtime.stubrunner', function( $container, $previous = null) {
return !$container->has('app.runtime.stub')
|| null===$container->get('app.runtime.stub') ? $previous : $container->get('app.runtime.stub')->getRunner();
});
$this->container->factory('app.runtime.codebase', function( $container, $previous = null) {
return !$container->has('app.runtime.stub')
|| !$container->has('app.runtime.stubrunner')
|| null===$container->get('app.runtime.stubrunner')
? $previous
: $container->get('app.runtime.stubrunner')->getCodebase();
});
$this->container->factory('app.runtime.autoloader.remote', function( $container, $previous = null) {
return !$container->has('app.runtime.stub')
|| !$container->has('app.runtime.stubrunner')
|| null===$container->get('app.runtime.stub')
? $previous
: $container->get('app.runtime.stubrunner')->getRemoteAutoloader();
});
$this->container->set('files.index.php', (null !== $this->getStub() )
? ''.$this->getStub()->location
: \get_included_files()[0]
);
}//!hasContainer()
$this->global()->configure([
'app.runtime.api.url' => ($this->container->has('app.runtime.codebase')
&& null !== $this->container->get('app.runtime.codebase') )
? $this->container->get('app.runtime.codebase')->getRemoteApiBaseUrl()
: 'https://api.webfan.de/',
]);
if(!$this->container->hasContainer($contextContainerId)){
$ContextContainer = new ContextContainer( \Webfan\ArrayHelper::toDotTreeStatic($this->context, '{', '}') );
$this->container = $this->container->addContainer($ContextContainer, $contextContainerId);
}//!has $contextContainerId
if(!$this->container->hasContainer($configContainerId)){
$ConfigContainer = new ConfigContainer( $this->container->get($configContainerId) );
$this->container = $this->container->addContainer($ConfigContainer, $configContainerId);
}//! has $configContainerId
$containerId = 'console';
if(!$this->container->hasContainer($containerId)){
$containerClass = 'CompiledConsoleContainer';
$containerBuilder = new ConsoleContainer($me, $containerClass);
$containerBuilder = $containerBuilder->enableCompilation($me->getDir(self::MAIN_CONTAINER, true),
$containerClass,
\DI\Container::class);
// $containerBuilder->wrapContainer( $this->container );
$isOld = file_exists($containerBuilder->filename());
if(!$isOld){
@ini_set('max_execution_time', max(240, intval(ini_get('max_execution_time')) + 90) );
$AppBuilder = $containerBuilder->getAppBuilder();
$rewrittenContainer = true;
}
/*
$CompiledCompiledConsoleContainer = $this->main('circuit.breaker')->protect(function () use(&$me, $containerBuilder) {
try{
return $containerBuilder->build(true, $me->getContainer(), false );
}catch(\Exception $e){
$me->error($e->getMessage());
throw $e;
}
});
*/
$CompiledCompiledConsoleContainer = $containerBuilder->build(true, $this->container, false );
// unset($containerBuilder);
$this->container = $this->container->addContainer( $CompiledCompiledConsoleContainer, $containerId );
if($rewrittenContainer && !$this->isCLI() && !$isOld){
$rewrittenContainer = true;
$this->flash()->info(
'The console container was rebuild! The page reloads automatically...'
);
$this->flash()->info( $this->getFormFromRequest(
'circuit:1.3.6.1.4.1.37553.8.1.8.8.1958965301.4.7 - Resolved automatically',
null, true, 5)
);
// $this->exec('setup');
if(!$this->isCLI()){
// clearstatcache();
// $this->end();
}
// return $this->container;
}
}// if(!$this->container->hasContainer($containerId))
$containerIdGlobal = 'global';
$containerClassGlobalContainer = 'CompiledGlobalContainer';
if(!$this->container->hasContainer($containerIdGlobal)){
$containerBuilderGlobalContainer = new ContainerAppKernel($me
, $containerClassGlobalContainer);
$containerBuilderGlobalContainer = $containerBuilderGlobalContainer->enableCompilation(
$me->getDir(self::MAIN_CONTAINER, true),
$containerClassGlobalContainer,
\DI\Container::class);
// $containerBuilderGlobalContainer->wrapContainer( $this->container );
$isOld = file_exists($containerBuilderGlobalContainer->filename());
if( !$isOld){
@ini_set('max_execution_time', max(240, intval(ini_get('max_execution_time')) + 90) );
$AppBuilder = $containerBuilderGlobalContainer->getAppBuilder();
$rewrittenContainer = true;
}
// try{
$CompiledContainerKernelContainer = $containerBuilderGlobalContainer->build(true, $this->container, false );
// unset($containerBuilderGlobalContainer);
// }catch(\Exception $e){
// $this->error($e->getMessage());
// throw $e;
// }
/*
if($rewrittenContainer && !$this->isCLI() && !$isOld){
$this->flash()->info(
'The global container was rebuild! The page reloads automatically...'
);
$this->flash()->info( $this->getFormFromRequest(
'circuit:1.3.6.1.4.1.37553.8.1.8.8.1958965301.4.7 - Resolved automatically',
null, true, 5)
);
if(!$this->isCLI()){
$this->flash()->info(
$this->getFormFromRequest(
'The global container was rebuild',
null, true, 5));
// clearstatcache();
$this->end();
}
}
*/
/*
if($CompiledContainerKernelContainer instanceof ContainerInterface){
//$this->container->unregister($globalContainerFactoryServiceId, true);
$this->container = $this->container->addContainer( $CompiledContainerKernelContainer, $containerIdGlobal );
}else{
$err = 'Could not get compiled container in '.__METHOD__.' '.__LINE__;
$this->flash()->error($err);
$this->error($err);
return $this->container;
}
*/
$this->container = $this->container->addContainer( $CompiledContainerKernelContainer, $containerIdGlobal );
// if(true === $rewrittenContainer){
// $this->exec('setup', true, true);
// }
}//if(!$this->container->hasContainer($containerIdGlobal))
/*
$eventName = 'container:ready';
$event = new \Webfan\Webfat\Event($eventName);
$event->setArgument('kernel', $this);
$event->setArgument('container', $this->container);
$this->state('container', 'webfan')->emit($eventName, $event);
if($this->isMounted('website')){
$this->state('container', 'website')->emit($eventName, $event);
}
*/
return $this->container;
}
public function hasShared(string $id = null, string $appOrScheme = null) : bool {
if(!$this->isMounted($appOrScheme)){
throw new ResolvableException(
'circuit:1.3.6.1.4.1.37553.8.1.8.8.1958965301.5.5.1=Scheme '.$appOrScheme.':// is NOT MOUNTED into the app!'
.'|php:'.get_class($this).'=Thrown by the Kernel'
.'@'.$appOrScheme.':// is not mounted!'
);
}
if(null === $id){
return isset($this->appStateShare[$appOrScheme]);
}
return isset($this->appStateShare[$appOrScheme][$id]);
}
public function deleteShared(string $sharedId, string $appOrScheme){
if(!$this->hasShared( $appOrScheme, $sharedId ) ){
return;
}
if(isset($this->appStateShare[$appOrScheme][$sharedId])){
@$this->appStateShare[$appOrScheme][$sharedId]->unlock();
}
unset($this->appStateShare[$appOrScheme][$sharedId]);
unset($this->appStateStorage[$appOrScheme][$sharedId]);
unlink($this->appStateShareFiles[$appOrScheme][$sharedId]);
unset($this->appStateShareFiles[$appOrScheme][$sharedId]);
// if(0 === count($this->appStateShare[$appOrScheme]) ){
// unset($this->appStateShare[$appOrScheme]);
// }
}
public function &getShared(string $sharedId, string $ext = 'txt', string $appOrScheme = null) : SharedMemory {
if(!$this->isMounted($appOrScheme)){
throw new ResolvableException(
'circuit:1.3.6.1.4.1.37553.8.1.8.8.1958965301.5.5.1=Scheme '.$appOrScheme.':// is NOT MOUNTED into the app!'
.'|php:'.get_class($this).'=Thrown by the Kernel'
.'@'.$appOrScheme.':// is not mounted!'
);
}
$dir = null !== $appOrScheme && $this->isMounted($appOrScheme)
? StreamHandler::resolve( $this->getAppIntentDir($appOrScheme, self::MAIN_STATE_MUTEX, true) )
: $this->getDir(self::MAIN_STATE_MUTEX);
$file = $dir.'/'.preg_replace("/[^A-Za-z0-9\-\.\_]/", "-", $appOrScheme.'.'.$sharedId).'.'.$ext;
if(!is_dir($dir)){
mkdir($dir, 0775, true);
}
if(!isset($this->appStateStorage[$appOrScheme])){
$this->appStateStorage[$appOrScheme] = [];
}
if(!isset($this->appStateShare[$appOrScheme])){
$this->appStateShare[$appOrScheme] = [];
}
if(!isset($this->appStateStorage[$appOrScheme][$sharedId])){
if(!isset($this->appStateShareFiles[$appOrScheme])){
$this->appStateShareFiles[$appOrScheme] = [];
}
$this->appStateShareFiles[$appOrScheme][$sharedId] = $file;
$this->appStateStorage[$appOrScheme][$sharedId] = new StorageFile($file);
}
if(!isset($this->appStateShare[$appOrScheme][$sharedId])){
$this->appStateShare[$appOrScheme][$sharedId] =
new SharedMemory($this->appStateStorage[$appOrScheme][$sharedId] );
}
$this->appStateShare[$appOrScheme][$sharedId]->unlock();
return $this->appStateShare[$appOrScheme][$sharedId];
}
public function &getCircuitBreaker(string $appOrScheme = null, string $circuitId = null,
bool | \callable | \Closure $onSuccess = null,
bool | \callable | \Closure $onFailure = null,
bool | \callable | \Closure $onOpen = null,
bool | \callable | \Closure $onClosed = null,
bool | \callable | \Closure $onHalfopen = null,
int $max_failure = 1,
int $reset_timeout = 5,
bool $ignore_exceptions = false,
string $ext = 'txt',
array $exclude_exceptions = [],
array $allowed_exceptions = [],
bool $forceAddEventHandlers = false) : Breaker {
if(!$this->isMounted($appOrScheme)){
throw new ResolvableException(
'circuit:1.3.6.1.4.1.37553.8.1.8.8.1958965301.5.5.1=Scheme '.$appOrScheme.':// is NOT MOUNTED into the app!'
.'|php:'.get_class($this).'=Thrown by the Kernel'
.'@'.$appOrScheme.':// is not mounted!'
);
}
$me = &$this;
$dir = null !== $appOrScheme && $this->isMounted($appOrScheme)
? StreamHandler::resolve( $this->getAppIntentDir($appOrScheme, self::CIRCUIT_MAIN, true) )
: $this->getDir(self::CIRCUIT_MAIN);
if(!is_dir($dir)){
mkdir($dir, 0775, true);
}
if(!is_dir($dir)){
mkdir($dir, 0775, true);
}
if(!isset($this->circuitStorage[$appOrScheme])){
$this->circuitStorage[$appOrScheme] = [];
}
if(!isset($this->circuitStorage[$appOrScheme][$circuitId])){
$this->circuitStorage[$appOrScheme][$circuitId] = new FilesystemCache($dir,
// preg_replace("/[^A-Za-z0-9\-\.\_]/", "-", $appOrScheme.'.'.$circuitId)
preg_replace("/[^A-Za-z0-9\-\.\_]/", "-", $appOrScheme.'.'.preg_split("/\s+|\./m", $circuitId)[0]) .'.'.$ext);
}
if(!isset($this->circuit[$appOrScheme])){
$this->circuit[$appOrScheme] = [];
}
$isNew = false;
if(!isset( $this->circuit[$appOrScheme][$circuitId])){
$isNew = true;
$this->circuit[$appOrScheme][$circuitId] = new Breaker($appOrScheme.'-'.$circuitId, [
'ignore_exceptions' => $ignore_exceptions,
'max_failure' => $max_failure,
'reset_timeout' => $reset_timeout,
'exclude_exceptions' => $exclude_exceptions,
'allowed_exceptions' => $allowed_exceptions,
], $this->circuitStorage[$appOrScheme][$circuitId] );
}
if(true === $isNew || true === $forceAddEventHandlers){
if(true === $onSuccess){
$onSuccess = function ( $event) use(&$me, $circuitId) {
//// $circuit = $event->getCircuit();
//$me->debug(sprintf("Connection to service '%s$1' success!\n", $circuit->getName()));
};
}
if(true === $onFailure){
$onFailure = function ( $event) use(&$me, $circuitId) {
// $circuit = $event->getCircuit();
// $me->error(sprintf("Connection to service '%s$1' failed!\n", $circuit->getName()));
$me->error(sprintf("Connection to service '%s$1' failed!\n", $circuitId));
};
}
if(true === $onOpen){
$onOpen = function ( $event) use(&$me, $circuitId) {
// $circuit = $event->getCircuit();
$me->error(sprintf("Connection to service '%s$1' is open!\n", $circuitId));
};
}
if(true === $onClosed){
$onClosed = function ( $event) use(&$me, $circuitI) {
// $circuit = $event->getCircuit();
//$me->debug(sprintf("Connection to service '%s$1' success!\n", $circuit->getName()));
};
}
if(true === $onHalfopen){
$onHalfopen = function ( $event) use(&$me, $circuitI) {
// $circuit = $event->getCircuit();
$me->warning(sprintf("Connection to service '%s$1' is half-open!\n", $circuitId));
};
}
if(!is_null($onSuccess)){
$this->circuit[$appOrScheme][$circuitId]->addListener(CircuitEvents::SUCCESS, $onSuccess);
}
if(!is_null($onFailure)){
$this->circuit[$appOrScheme][$circuitId]->addListener(CircuitEvents::FAILURE, $onFailure);
}
if(!is_null($onOpen)){
$this->circuit[$appOrScheme][$circuitId]->addListener(CircuitEvents::OPEN, $onOpen);
}
if(!is_null($onClosed)){
$this->circuit[$appOrScheme][$circuitId]->addListener(CircuitEvents::CLOSED, $onClosed);
}
if(!is_null($onHalfopen)){
$this->circuit[$appOrScheme][$circuitId]->addListener(CircuitEvents::HALF_OPEN, $onHalfopen);
}
}
return $this->circuit[$appOrScheme][$circuitId];
}
public function hasConnection(string $id = null, string $appOrScheme = null) : bool {
if(null === $id){
return isset($this->connections[$appOrScheme]);
}
return isset($this->connections[$appOrScheme][$id]);
}
public function &getConnectionState(string $appOrScheme, string $id) : SharedMemory {
$storageId = $this->_getConnectionStorageId($appOrScheme, $id);
return $this->getShared($storageId, 'txt', $appOrScheme);
}
protected function _getConnectionStorageId(string $appOrScheme = null, string $id){
return self::MAIN_STATE_MUTEX.'.connection-state'
.'.'
.sha1($id).'.'.strlen($id)
.'.'
.preg_replace("/[^A-Za-z0-9\-\.\_]/", "-", $id);
}
public function &getConnection(string $appOrScheme = null, string $id,
int $max_failure = 1, int $reset_timeout = 5, bool $ignore_exceptions = false,
array $exclude_exceptions = [],
array $allowed_exceptions = []){
$connection = null;
if(null===$appOrScheme || !$this->isMounted($appOrScheme)){
throw new ResolvableException(
'circuit:1.3.6.1.4.1.37553.8.1.8.8.1958965301.5.5.1=Scheme '.$appOrScheme.':// is NOT MOUNTED into the app!'
.'|php:'.get_class($this).'=Thrown by the Kernel'
.'@'.$appOrScheme.':// is not mounted!'
);
}
//if(null===$appOrScheme){
// $appOrScheme = 'webfan';
//}
if(!isset($this->connections[$appOrScheme])){
$this->connections[$appOrScheme] = [];
}
if( isset($this->connections[$appOrScheme][$id])){
return $this->connections[$appOrScheme][$id];
}
$storageId = $this->_getConnectionStorageId($appOrScheme, $id);
$me = &$this;
$state = $this->getConnectionState($appOrScheme, $id);
$circuit = $this->getCircuitBreaker($appOrScheme, $storageId,
function ( $event) use( $id, &$me, &$state) {
// $circuit = $event->getCircuit();
// echo "Success:".$circuit->getFailures()."\n";
$state->main = true;
}, function ( $event) use( $id, &$me, &$state) {
// $circuit = $event->getCircuit();
$me->error(sprintf("Connection to service '%s$1' failed!", $id));
$me->flash()->error( sprintf("Connection to service '%s$1' failed!\n", $id) );
// echo "Increment failure:".$circuit->getFailures()."\n";
// $state->main = "Increment failure:".$circuit->getFailures()."\n";
$state->main = false;
}, function ( $event) use( $id, &$me, &$state) {
// $circuit = $event->getCircuit();
$me->warning(sprintf("The service '%s$1' is NOT CONNECTED correctly!", $id));
$me->flash()->error( sprintf("The service '%s$1' is NOT CONNECTED correctly!", $id) );
//$state->main = sprintf("circuit %s is open \n", $circuit->getName());
//$state->main = sprintf("The service '%s$1' is NOT CONNECTED correctly!\n", $circuit->getName());
$state->main = false;
}, function ( $event) use( $id, &$me, &$state) {
// $circuit = $event->getCircuit();
// echo sprintf("circuit %s is closed \n", $circuit->getName());
// $state->main = sprintf("circuit %s is closed \n", $circuit->getName());
$me->debug(sprintf("circuit %s is closed", $id));
$state->main = true;
}, function ( $event) use( $id, &$me, &$state) {
// $circuit = $event->getCircuit();
$me->warning(sprintf("The service '%s$1' is NOT READY!", $id));
$me->flash()->error( sprintf("The service '%s$1' is NOT READY!", $id) );
$state->main = false;
},
$max_failure,
$reset_timeout,
$ignore_exceptions,
'txt',
$exclude_exceptions,
$allowed_exceptions,
false);
$connection = $circuit->protect(function () use( $appOrScheme, $id, &$me, &$state ) {
if( !$me->getContainer()->has($id) &&
!$me->getContainer()->has($appOrScheme.'://'.$id) &&
!$me->getContainer()->has($appOrScheme.'@'.$id) &&
!$me->getContainer()->has($appOrScheme.'.'.$id)
){
throw new \Exception(sprintf('The ID# %3$s.%1$s is not registered in the Container in %2$s!',
$id, __METHOD__, $appOrScheme));
}
if($me->getContainer()->has($id)){
return $me->getContainer()->get($id);
}
if($me->getContainer()->has($appOrScheme.'://'.$id)){
return $me->getContainer()->get($appOrScheme.'://'.$id);
}
if($me->getContainer()->has($appOrScheme.'@'.$id)){
return $me->getContainer()->get($appOrScheme.'@'.$id);
}
if($me->getContainer()->has($appOrScheme.'.'.$id)){
return $me->getContainer()->get($appOrScheme.'.'.$id);
}
return $me->getContainer()->has($appOrScheme.'.'.$id)
? $me->getContainer()->get($appOrScheme.'.'.$id)
: $me->getContainer()->get($id);
});
if($connection && !is_null($connection) && true !== $connection instanceof \Exception){
$this->connections[$appOrScheme][$id] = $connection;
}
return $connection;
}
public function &flash(){
if(null===$this->mgs){
$this->session_start($this->sessionName);
$this->mgs = new \frdl\Flash();
}
return $this->mgs;
}
/**
$constructor = \Webfan\Script::create(function () {
$this->property = 1;
$this->getProperty = function () {
return $this->property;
};
});
$constructor->prototype = \Webfan\Script::create([
'getDouble' => function () {
return $this->getProperty() * 2;
},
]);
$doubleInstance = $constructor();
echo $doubleInstance->getDouble();//
*/
public function &global(){
// public function global(){
if(null === $this->GlobalObject){
$obj = call_user_func(function(){
$obj = \Webfan\Script::create(function () {
$arr = [];
$this->configuration =new Configuration($arr);
// $this->configuration = Config::fromArray($arr);
});
$obj->prototype = \Webfan\Script::create([
'getConfig' => function () {
return $this->configuration;
},
'configure' => function (array|Config|Configuration $config = null) {
if(!is_null($config) && is_array($config)){
$this->configuration = $this->getConfig()->merge(Config::fromArray($config));
}elseif(!is_null($config) && is_object($config) && $config instanceof Configuration){
$this->configuration = $this->getConfig()->merge($config);
}
return $this->getConfig();
},
]);
return $obj;
});
$this->GlobalObject = $obj( );
$arr = [];
$this->GlobalObject->configuration = new Configuration($arr);
$this->GlobalObject->page = call_user_func(function($arg = []){
$page = \Webfan\Script::create(function ( ) {
$this->languages = [];
});
return $page( );
});
$languages = []; //@ToDo: get languages
$this->GlobalObject->page->languages = $languages;
$this->GlobalObject->page->html =call_user_func(function( ){
$html = \Webfan\Script::create(function ( ) {
$this->head = '';
$this->body = '';
$this->footer = '';
});
return $html( );
});
}//null === $this->GlobalObject
return $this->GlobalObject;
}
public function dotEnvNamespaces(array $envNamespaces = []){
foreach($envNamespaces as $ns){
try{
$this->global()->configure(Config::loadEnv($ns, '_'));
}catch(\Exception $e){
throw new ResolvableException(
'circuit:1.3.6.1.4.1.37553.8.1.8.8.1958965301.4.6='.$ns.' Environment not OK?'
.'|php:'.get_class($this).'=Thrown by the Kernel Class'
.'@'.$e->getMessage()
);
}
}
$this->global()->getConfig();
}
public function loadEnvVars(array $envDirs, array $envFiles = ['.env'])
{
foreach($envDirs as $dir){
foreach($envFiles as $filename){
if(!is_dir($dir) || !is_file(rtrim($dir, '/\ '). \DIRECTORY_SEPARATOR.$filename)){
continue;
}
try{
$dotenv = \Dotenv\Dotenv::createImmutable($dir, $filename, false);
$dotenv->load();
}catch(\Exception $e){
throw new ResolvableException(
'circuit:1.3.6.1.4.1.37553.8.1.8.8.1958965301.4.6='.$filename.' is not readable correctly in '.$dir
.'|php:'.get_class($this).'=Thrown by the Kernel Class'
.'@'.$e->getMessage()
);
}
}
}
}
/*
public function loadCentral(){
}
public function loadWebsite(){
}
*/
public function setAppId(string $appId = '1.3.6.1.4.1.37553.8.1.8.8.1958965301') : ?self {
if('1.3.6.1.4.1.37553.8.1.8.8.1958965301' === $appId){
//throw new \Exception('You should not use appID #'.$appId.'!');
$appId = null;
$this->flash()->error( ( new \Webfan\Webfat\App\ResolvableLogicException(
'circuit:1.3.6.1.4.1.37553.8.1.8.8.1958965301.5.1=The (Main) Application ID must be defined'
.'|php:'.get_class($this).'=Thrown by the Codebase Class '.__METHOD__
.'@The Application ID must be defined'
))->html(-1) );
}
$this->appId =$appId;
return $this;
}
//'1.3.6.1.4.1.37553.8.1.8.8.1958965301' circuit%3A1.3.6.1.4.1.37553.8.1.8.8.1958965301.5.1
/*
throw new ResolvableException(
'circuit:1.3.6.1.4.1.37553.8.1.8.8.1958965301.4.superadmin=No superadmin installed'
.'|php:'.get_class($me).'=Thrown by the Kernel Class'
.'@Superadmin mising'
);
*/
public function getAppId() : string {
if(null === $this->appId){
throw new ResolvableLogicException(
'circuit:1.3.6.1.4.1.37553.8.1.8.8.1958965301.5.1=The (Main) Application ID must be defined'
.'|php:'.get_class($this).'=Thrown by the Kernel Class '.__METHOD__
.'@The Application ID must be defined'
);
}
return $this->appId;
}
public function isMethod(string $method, $classOrObject) : \stdclass {
if(!is_string($classOrObject)){
$class = \get_class($classOrObject);
}else{
$class = $classOrObject;
}
$result = new \stdclass;
$result->exists = \method_exists($class, $method)
|| \method_exists($classOrObject, $method);
$result->callable = \is_callable([$classOrObject, $method]) || \is_callable([$class, $method]);
try{
$refl = new \ReflectionMethod($classOrObject, $method);
$result->valid = $result->exists || $result->callable || $refl->isPublic();
$result->static = $refl->isStatic();
$result->public = $refl->isPublic();
$result->private = $refl->isPrivate();
}catch(\Exception $e){
$result->valid = false;
$result->static = false;
$result->public = false;
$result->private = false;
}
return $result;
}
public function &__get($name){
$me = &$this;
switch($name){
case 'Document' :
if(null === $this->_Document){
$this->_Document = $this->HTMLDOcument;
}
return $this->_Document;
break;
case 'HTML5DOMDocument' :
case 'HTMLDOcument' :
//$HTMLDOcument = call_user_func(function(Kernel $me){
$obj = \Webfan\Script::create(function ($arg = []) use(&$me) {
$withDocType = isset($arg['DocType']) ? $arg['DocType'] : '';
$content = isset($arg['content']) ? $arg['content'] : '';
if(is_string($withDocType) && $withDocType !== substr($content, 0, strlen($withDocType))){
$strtpl = "%s%s";
$content=sprintf($strtpl, $withDocType, $content);
}
$this->compiler = isset($arg['compiler']) ? $arg['compiler'] : $me->HTMLCompiler;
// $this->compiler =$arg['compiler'];
// $this->content =$arg['content'];
$this->dom = new HTML5DOMDocument();
$this->dom->substituteEntities = false;
$this->dom->loadHTML($content, HTML5DOMDocument::ALLOW_DUPLICATE_IDS);
});
$obj->prototype = \Webfan\Script::create([
'compile' => function (string | HTML5DOMDocument $content = '') : string {
if(!empty($content)){
$this->dom->insertHTML($content);
}
$content = $this->save();
$content = $this->compiler->process($content);
return $content;
},
'load' => function (string | HTML5DOMDocument $content = '') {
$this->dom->loadHTML($content, HTML5DOMDocument::ALLOW_DUPLICATE_IDS);
return $this;
},
'save' => function () : string {
return $this->dom->saveHTML();
},
'doc' => function () {
//return $this->document();
return $this->dom;
},
'document' => function () {
return $this->dom;
},
'write' => function (string | HTML5DOMDocument $content = '') {
$this->dom->insertHTML($content);
return $this;
},
]);
// return $obj;
// }, $this);
$obj = $obj([
'content' => '',
'compiler' => $this->HTMLComponentsCompiler,
'DocType' => '',
]);
$obj->compiler = $this->HTMLCompiler;
$obj->dom = new HTML5DOMDocument();
$obj->dom->substituteEntities = false;
$obj->dom->loadHTML('', HTML5DOMDocument::ALLOW_DUPLICATE_IDS);
return $obj;
/* new $HTMLDOcument([
'compiler' =>&$this->HTMLComponentsCompiler,
'content' => '',
]);
return $HTMLDOcument([
'compiler' =>&$this->HTMLComponentsCompiler,
'content' => '',
]);*/
break;
case HTMLServerComponentsCompiler::class :
case 'HTMLServerComponentsCompiler' :
case 'HTMLCompiler' :
case 'HTMLComponentsCompiler' :
if(null !== $this->container){
$compiler = $this->container->has(HTMLServerComponentsCompiler::class)
? $this->container->get(HTMLServerComponentsCompiler::class)
: new HTMLServerComponentsCompiler($this->container->has('website.components.paths')
? $this->container->get('website.components.paths')
: null,
$this->container->has('call')
? $this->container->get('call')
: null,
$this->container->has('require')
? $this->container->get('require')
: null,
$this->container->has('define')
? $this->container->get('define')
: null);
}else{
$compiler = new HTMLServerComponentsCompiler();
}
if(null === $compiler->getViewTemplateRenderer()
&& null !== $this->container
&& $this->container->has('app.runtime.renderer.default')
){
$compiler->setViewTemplateRenderer($this->container->get('app.runtime.renderer.default'));
}
return $compiler;
break;
case 'CommandCall' :
if(null === $this->_CommandCall){
if(!is_array($this->argv)){
$this->argv = [];
}
if ($this->isCLI() || isset($_SERVER['argv']) ) {
$this->argv = array_merge($this->argv, isset($_SERVER['argv']) ? $_SERVER['argv'] : []);
}
$this->_CommandCall = new \Webfan\Webfat\Console\CommandCall($this->argv);
}
return $this->_CommandCall;
break;
case 'Console' :
case 'console' :
if($this->hasContainer()
// && $this->getContainer()->hasContainer('console')
&& $this->getContainer()->has('Console')){
return $this->getContainer()->get('Console');
}else{
return new Console([
'BIN_PATH.PHP'=>(new \Webfan\Helper\PhpBinFinder())->find(),
// 'app_path' => [
// __DIR__ . '/app/Command',
// '@minicli/command-help'
// ],
'debug' => true,
], $this->getContainer() );
}
break;
default:
if($this->hasContainer() && $this->getContainer()->has($name)){
return $this->getContainer()->get($name);
}
if(isset($this->{$name})){
return $this->{$name};
}
// throw new \InvalidArgumentException('Cannot magically __get('.$name.') in '.__METHOD__);
return null;
break;
}
}
public static function __callStatic($method, $params){
$callable = false;
if($this->isMethod($method, KernelFunctions::class)->static
&& ($this->isMethod($method, KernelFunctions::class)->valid || $this->isMethod($method, KernelFunctions::class)->public)){
$callable = [KernelFunctions::class, $method];
}
if(!\is_callable($callable) ){
if( 'static' === strtolower(substr($method, 0, strlen('static')))){
$method = substr($method, strlen('static'), strlen($method));
}elseif( 'static' === strtolower(substr($method, strlen($method)-strlen('Static'), strlen($method)))){
$method = substr($method, 0, strlen($method)-strlen('Static') );
}
if(!is_callable($callable)){
$callable = [self::mutex(), $method];
}
}
if(is_callable($callable)){
return call_user_func_array($callable, $params);
}
throw new \Exception($method .' is not callable in '.__METHOD__);
}
public function __call($method, $params){
// if(false===$this->isBooted){
// $this->boot();
// }
$callable = false;
switch($method){
case 'error' :
case 'warning' :
case 'notice' :
case 'debug' :
case 'info' :
case 'critical' :
case 'alert' :
case 'emergency' :
array_unshift($params, $method);
if(count($params) < 3){
$params[] = [];
}
if(count($params) < 4){
$params[] = 'default';
}
// return \call_user_func_array([$this, 'log'], $params);
//log(string $type, string $message, array $context = [], string $loggerName = 'default')
$callable = [$this, 'log'];
break;
default :
//continue...
$callable = false;
break;
}
if(false === $callable
&& $this->hasContainer() && $this->getContainer()->has(KernelHelper::class)
&& (true === $this->isMethod($method, $this->getContainer()->get(KernelHelper::class))->valid
|| true === $this->isMethod($method, $this->getContainer()->get(KernelHelper::class))->public )){
$callable = [$this->getContainer()->get(KernelHelper::class), $method];
}elseif(false === $callable
&& ($this->isMethod($method, KernelHelper::class)->valid || $this->isMethod($method, KernelHelper::class)->public )){
$callable = [new KernelHelper($this), $method];
}
if(false === $callable
&& ($this->isMethod($method, KernelFunctions::class)->valid || $this->isMethod($method, KernelFunctions::class)->public )){
$callable = [new KernelFunctions($this), $method];
}
if(false === $callable){
if($this->hasContainer() && $this->getContainer()->has(Maintenance::class)
&& ( true === $this->isMethod($method, $this->getContainer()->get(Maintenance::class))->valid
|| true === $this->isMethod($method, $this->getContainer()->get(Maintenance::class))->public )){
$callable = [$this->getContainer()->get(Maintenance::class), $method];
}elseif($this->isMethod($method, Maintenance::class)->valid || $this->isMethod($method, Maintenance::class)->public ){
$callable = [new Maintenance($this), $method];
}
}
if(is_callable($callable)){
return call_user_func_array($callable, $params);
}
throw new \Exception($method .' is not callable in '.__METHOD__);
}
public static function mutex(): AppInterface{
foreach(self::$instances as $dir => $envs){
foreach($envs as $instance){
return $instance;
}
}
return self::getInstance();
}
public static function getInstance(string $env = null, string $dir = null): self
{
$class = self::class;
if(null ===$env){
$env = 'dev';
}
$dir = (new $class($env, $dir))->findAppDir($dir, false);
if(!isset(self::$instances[$dir])){
self::$instances[$dir] = [];
}
if(!isset(self::$instances[$dir][$env])){
self::$instances[$dir][$env] = new $class($env, $dir);
self::$instances[$dir][$env]->findAppDir(self::$instances[$dir][$env]->getDir('app', true), true);
}
// $res = &self::$instances[$dir][$env];
// return $res;
return self::$instances[$dir][$env];
}
public function getWebUriBase() : string | bool {
return $this->webUriBase;
}
public function getEnvFlag() : string {
return $this->env;
}
public function getSources(string $userdir = null, $create = false) : array
{
if(null === $this->sources){
$this->findAppDir($userdir, $create);
}
return $this->sources;
}
public function findAppDir(string $userdir = null, $create = false)
{
if(null===$userdir){
// if(substr(getcwd(), 0, strlen($_SERVER['DOCUMENT_ROOT']) ) !== $_SERVER['DOCUMENT_ROOT']){
// trigger_error('Unexpected working directory in '.__METHOD__, \E_USER_WARNING);
// }
$userdir = getcwd();
}
$dir = $this->FRDL_WORKSPACE;
$pathFinderStageOneApp = \Phpactor\PathFinder\PathFinder::fromAbsoluteDestinations($userdir, [
'source' =>'/',
'legacy' => $_SERVER['DOCUMENT_ROOT'].'/..///../..',
'blue' => $dir.'/apps/'.urlencode($this->getAppId()).'/deployments/blue//',
'green' => $dir.'/apps/'.urlencode($this->getAppId()).'/deployments/green//',
]);
$pathFinderStageOneAppSuggestions = $pathFinderStageOneApp->destinationsFor('deploy/app');
$pathFinderStageOneAppSuggestions['legacy' ] = $_SERVER['DOCUMENT_ROOT'].'/..';
$pathFinder = \Phpactor\PathFinder\PathFinder::fromAbsoluteDestinations($userdir, [
'source' => 'config//.php',
'dir' => $dir.'/config/',
'file' => $dir.'/config//.php',
]);
$targetsAdmin = $pathFinder->destinationsFor('config/superadmin/superadmin.php');
$this->sources['superadmin'] = $targetsAdmin;
// $domains = $pathFinder->destinationsFor('config/domains/domains.php');
// $this->sources['domains'] = $domains;
$pathFinderWebrootDir = \Phpactor\PathFinder\PathFinder::fromAbsoluteDestinations($userdir, [
'source' => '1.3.6.1.4.1.37553.8.1.8.8.11.6'.'/'. ''.'/'.'.php',
'dir' => $dir.'/'. '1.3.6.1.4.1.37553.8.1.8.8.11.6'.'/'. '',
'file' => $dir.'/'. '1.3.6.1.4.1.37553.8.1.8.8.11.6'.'/'.''.'/'.'.php',
]);
$targetsWebrootDir = $pathFinderWebrootDir->destinationsFor(
'1.3.6.1.4.1.37553.8.1.8.8.11.6'.'/'.sha1(str_replace(getenv('HOME'), '', $_SERVER['DOCUMENT_ROOT'])).'/'.'app.php');
$this->sources['webrootconfig'] = $targetsWebrootDir;
$data = [
'VERSION'=> sha1_file(__FILE__),
'DOCUMENT_ROOT'=>[
'relative'=> str_replace(getenv('HOME'), '', $_SERVER['DOCUMENT_ROOT']),
'absolute'=> $_SERVER['DOCUMENT_ROOT'],
],
'app' => [
//'initial' =>$this->getAppId(),
//'main' => null,
//'api'=>null,
//'cdn'=>null,
//'central'=>null,
//'global'=>null,
],
'apps' => [
//$this->getAppId() => [
//
//],
],
'stage'=>'blue',
'stages'=>$pathFinderStageOneAppSuggestions,
];
if(true === $create && !is_dir($this->sources['webrootconfig']['dir'])){
mkdir($this->sources['webrootconfig']['dir'], 0775, true);
}
$webrootconfig = file_exists($this->sources['webrootconfig']['file'])
? require $this->sources['webrootconfig']['file']
: [
'VERSION'=> false,//sha1_file(__FILE__),
];
if(true === $create &&
(
!file_exists($this->sources['webrootconfig']['file'])
|| $webrootconfig['VERSION'] !== $data['VERSION']
)
){
// $data = array_merge_recursive($webrootconfig, $data);
$data = array_merge($webrootconfig, $data);
if(!isset($data['app']['initial'])){
$data['app']['initial'] = $this->getAppId();
}
if(!isset($data['apps'][$this->getAppId()])){
$data['apps'][$this->getAppId()] = [];
}
$exp = var_export($data, true);
$code = 'sources['webrootconfig']['file'], $code);
}
$webrootconfig = file_exists($this->sources['webrootconfig']['file'])
? require $this->sources['webrootconfig']['file']
: $data;
$this->sources['@runtime/webrootconfig'] = $webrootconfig;
$stage = isset($this->context['stage']) && is_string($this->context['stage']) ? $this->context['stage'] : $webrootconfig['stage'];
return $webrootconfig['stages'][$stage];
}
public function setStub(?StubHelperInterface $stubHelper = null) : self
{
$this->stubHelper=$stubHelper;
return $this;
}
public function getStub(): ?StubHelperInterface
{
return $this->stubHelper;
}
public function getFile(string $path, string $type = null) : string
{
$dir = $this->getDir( $type, false );
return rtrim($dir, '/\ ').\DIRECTORY_SEPARATOR
.ltrim(str_replace(['/', '\\'], [\DIRECTORY_SEPARATOR,\DIRECTORY_SEPARATOR], $path), '/\ ');
}
public function scheme(string $appOrScheme) : string
{
switch($appOrScheme){
case 'frdl' :
case 'workspace' :
$appOrScheme = 'frdl';
break;
case 'web+fan' :
case 'webfan' :
case 'global' :
case 'web+app' :
case 'app' :
case 'main' :
$appOrScheme = 'webfan';
break;
case 'web+site' :
case 'website' :
case 'site' :
$appOrScheme = 'website';
break;
case 'web+vhost' :
case 'web+domain' :
case 'vhost' :
case 'domain' :
case 'webhost' :
case 'web+host' :
case 'host' :
$appOrScheme = 'webhost';
break;
case 'webuser' :
case 'user' :
$appOrScheme = 'webuser';
break;
case 'config' :
case 'webconfig' :
$appOrScheme = 'webconfig';
break;
default :
throw new \Exception('Protocol '.$appOrScheme.' is not available!');
break;
}
return $appOrScheme;
}
public function getAppIntentDir(string $appOrScheme, string $intent = null, $create = false) : string
{
$type = $intent;
$appOrScheme = $this->scheme($appOrScheme);
switch($type){
case 'DOCUMENT_ROOT' :
case 'app.config.webroot' :
case 'app.config.DOCUMENT_ROOT' :
case 'app.config.www' :
case 'app.config.httpdocs' :
case 'app.config.web' :
$sources = $this->getSources($this->dir, $create);
$dir = $sources['webrootconfig']['dir'];
break;
case self::GLOBAL :
$dir = 'webfan://';
break;
case self::USERDATA :
case 'app.config.userdata' :
case 'var' :
case 'data.users' :
$dir = $appOrScheme.'://userland/userdata/';
break;
case self::WEBSITES :
case 'userdata.sites' :
case 'vhosts' :
case 'userdata.vhosts' :
case 'app.config.websites' :
$dir = $appOrScheme.'://userland/websites/';
break;
case self::DOMAINS :
case 'userdata.domains' :
case 'vhosts.domains' :
case 'config.domains' :
case 'config.domains' :
case 'hosts' :
case 'app.config.hosts' :
$dir = $appOrScheme.'://userland/domains/hosts/';
break;
case '~' :
case 'HOME' :
$dir = getenv('HOME');
break;
case 'WORKSPACE' :
case 'WS' :
case 'workspace' :
case 'frdl' :
$dir = 'frdl://';
break;
case 'modules' :
$dir = $appOrScheme.'://modules/';
break;
case 'app.public' :
case 'app.www' :
case 'app.httpdocs' :
case 'app.web' :
$dir = $appOrScheme.'://public/';
break;
/*
case 'public' :
case 'www' :
case 'httpdocs' :
case 'web' :
return rtrim($this->dir, '/\ ').\DIRECTORY_SEPARATOR
.'public'.\DIRECTORY_SEPARATOR;
break;
*/
case 'assets' :
case 'public.assets' :
case 'app.public.assets' :
case 'www.assets' :
case 'httpdocs.assets' :
case 'web.assets' :
case 'app.web.assets' :
case 'data.assets' :
case 'web.files' :
case 'files.static' :
$dir = $appOrScheme.'://public/assets/';
break;
case 'runtime' :
$dir = $appOrScheme.'://runtime/';
break;
case 'config' :
// case 'runtime.config' :
$dir = $appOrScheme.'://config/';
break;
case self::MAIN_STATE_MUTEX :
case 'runtime.state' :
$dir = $appOrScheme.'://runtime/state/';
break;
case self::MAIN_CONTAINER :
case 'runtime.container' :
case 'container' :
$dir = $appOrScheme.'://runtime/container/';
break;
case 'runtime.cache' :
case 'cache' :
$dir = $appOrScheme.'://runtime/cache/';
break;
case self::MAIN_EVENTS :
case 'runtime.events' :
$dir = $appOrScheme.'://runtime/events/';
break;
case 'runtime.temp' :
case 'temp' :
case 'tmp' :
$dir = $appOrScheme.'://runtime/tmp/';
break;
case self::CIRCUIT_MAIN :
case 'runtime.circuit' :
$dir = $appOrScheme.'://runtime/circuit/';
break;
case 'app':
$dir = $appOrScheme.'://';
break;
case 'logging' :
case 'logs' :
case 'log' :
$dir = $appOrScheme.'://logs/';
break;
default:
// $dir = $appOrScheme.'://'.$type.'/';
$dir = $appOrScheme.'://';
break;
}
if(true === $create && !is_dir($dir)){
mkdir($dir, 0775, true);
}
return $dir;
}
public function getDir(string $type = null, $create = true) : string
{
if(null === $this->dir){
$d = $this->findAppDir();
$this->dir = $d['dir'];
}
switch($type){
case 'config' :
case 'webconfig' :
return rtrim($this->FRDL_WORKSPACE, '/\ ').\DIRECTORY_SEPARATOR
.'config'.\DIRECTORY_SEPARATOR
.$this->getAppId().\DIRECTORY_SEPARATOR;
break;
case 'app.config.webroot' :
case 'app.config.DOCUMENT_ROOT' :
case 'app.config.www' :
case 'app.config.httpdocs' :
case 'app.config.web' :
$sources = $this->getSources($this->dir, $create);
return $sources['webrootconfig']['dir'];
break;
case self::GLOBAL :
return rtrim($this->FRDL_WORKSPACE, '/\ ').\DIRECTORY_SEPARATOR
.'global'.\DIRECTORY_SEPARATOR
.'app'.\DIRECTORY_SEPARATOR;
break;
case self::USERDATA :
case 'app.config.userdata' :
case 'var' :
case 'data.users' :
return rtrim($this->FRDL_WORKSPACE, '/\ ').\DIRECTORY_SEPARATOR
.'.userdata'.\DIRECTORY_SEPARATOR
.'data'.\DIRECTORY_SEPARATOR;
break;
case self::WEBSITES :
case 'userdata.sites' :
case 'vhosts' :
case 'userdata.vhosts' :
case 'app.config.websites' :
return rtrim($this->FRDL_WORKSPACE, '/\ ').\DIRECTORY_SEPARATOR
.'.websites'.\DIRECTORY_SEPARATOR
.'sites'.\DIRECTORY_SEPARATOR;
break;
case self::DOMAINS :
case 'userdata.domains' :
case 'vhosts.domains' :
case 'config.domains' :
case 'config.domains' :
case 'hosts' :
case 'app.config.hosts' :
return rtrim($this->FRDL_WORKSPACE, '/\ ').\DIRECTORY_SEPARATOR
.'.domains'.\DIRECTORY_SEPARATOR
.'hosts'.\DIRECTORY_SEPARATOR;
break;
case '~' :
case 'HOME' :
return getenv('HOME');
break;
case 'WORKSPACE' :
case 'WS' :
case 'workspace' :
return $this->FRDL_WORKSPACE;
break;
case 'modules' :
return rtrim($this->dir, '/\ ').\DIRECTORY_SEPARATOR
.'modules'.\DIRECTORY_SEPARATOR;
break;
case 'app.public' :
case 'app.www' :
case 'app.httpdocs' :
case 'app.web' :
return rtrim($this->dir, '/\ ').\DIRECTORY_SEPARATOR
.'public'.\DIRECTORY_SEPARATOR;
break;
/*
case 'public' :
case 'www' :
case 'httpdocs' :
case 'web' :
return rtrim($this->dir, '/\ ').\DIRECTORY_SEPARATOR
.'public'.\DIRECTORY_SEPARATOR;
break;
*/
case 'assets' :
case 'public.assets' :
case 'app.public.assets' :
case 'www.assets' :
case 'httpdocs.assets' :
case 'web.assets' :
case 'app.web.assets' :
case 'data.assets' :
case 'web.files' :
case 'files.static' :
return rtrim($this->dir, '/\ ').\DIRECTORY_SEPARATOR
.'public'.\DIRECTORY_SEPARATOR
.'assets'.\DIRECTORY_SEPARATOR;
break;
case 'runtime' :
return rtrim($this->dir, '/\ ').\DIRECTORY_SEPARATOR
.'runtime'.\DIRECTORY_SEPARATOR;
break;
case 'runtime.config' :
return rtrim($this->dir, '/\ ').\DIRECTORY_SEPARATOR
.'runtime'.\DIRECTORY_SEPARATOR
.'config'.\DIRECTORY_SEPARATOR;
break;
case self::MAIN_STATE_MUTEX :
case 'runtime.state' :
$dir = rtrim($this->dir, '/\ ').\DIRECTORY_SEPARATOR
.'runtime'.\DIRECTORY_SEPARATOR
.'state'.\DIRECTORY_SEPARATOR;
if(true === $create && !is_dir($dir)){
mkdir($dir, 0775, true);
}
return $dir;
break;
case self::MAIN_CONTAINER :
case 'runtime.container' :
case 'container' :
return rtrim($this->dir, '/\ ').\DIRECTORY_SEPARATOR
.'runtime'.\DIRECTORY_SEPARATOR
.'container'.\DIRECTORY_SEPARATOR;
break;
case 'runtime.cache' :
case 'cache' :
$cacheDir = rtrim($this->dir, '/\ ').\DIRECTORY_SEPARATOR
.'runtime'.\DIRECTORY_SEPARATOR
.'cache'.\DIRECTORY_SEPARATOR;
$_ENV['FRDL_HPS_CACHE_DIR']=$cacheDir;
@putenv("FRDL_HPS_CACHE_DIR=".$cacheDir);
return $cacheDir;
break;
case self::MAIN_EVENTS :
case 'runtime.events' :
return rtrim($this->dir, '/\ ').\DIRECTORY_SEPARATOR
.'runtime'.\DIRECTORY_SEPARATOR
.'events'.\DIRECTORY_SEPARATOR;
break;
case 'runtime.temp' :
case 'temp' :
return rtrim($this->dir, '/\ ').\DIRECTORY_SEPARATOR
.'runtime'.\DIRECTORY_SEPARATOR
.'tmp'.\DIRECTORY_SEPARATOR;
break;
case self::CIRCUIT_MAIN :
case 'runtime.circuit' :
return rtrim($this->dir, '/\ ').\DIRECTORY_SEPARATOR
.'runtime'.\DIRECTORY_SEPARATOR
.'circuit'.\DIRECTORY_SEPARATOR;
break;
case 'app':
return $this->dir;
break;
default:
return $this->dir;
break;
}
}
public function log(string $type, string $message, array $context = [], string $loggerName = 'default'){
$serviceId = 'logger.'.$loggerName;
$context = array_merge($this->context, $context);
$type = Logger::toMonologLevel($type);
/*
if($this->hasContainer() && $this->getContainer()->has($serviceId) ){
$this->getContainer()->get($serviceId)->log($type, $message, $context);
}
*/
if($this->isMounted('frdl')
&& !LoggerRegistry::hasLogger($loggerName) && $this->hasContainer() && $this->getContainer()->has($serviceId) ){
LoggerRegistry::addLogger($this->getConnection('frdl', $serviceId), $loggerName, false);
}
if($this->isMounted('webfan')
&& !LoggerRegistry::hasLogger('webfan://'.$loggerName)
&& $this->hasContainer() && $this->getContainer()->has('webfan://'.$serviceId) ){
LoggerRegistry::addLogger($this->getConnection('webfan', 'webfan://'.$serviceId), 'webfan://'.$loggerName, false);
}
if($this->isMounted('website')
&& !LoggerRegistry::hasLogger('website://'.$loggerName)
&& $this->hasContainer() && $this->getContainer()->has('website://'.$serviceId) ){
LoggerRegistry::addLogger($this->getConnection('website', 'website://'.$serviceId), 'website://'.$loggerName, false);
}
$type = Logger::toMonologLevel($type);
if(LoggerRegistry::hasLogger($loggerName)){
$logger = LoggerRegistry::getInstance($loggerName);
$logger->log($type, $message, $context);
}
if(LoggerRegistry::hasLogger('webfan://'.$loggerName)){
$logger = LoggerRegistry::getInstance('webfan://'.$loggerName);
$logger->log($type, $message, $context);
}
if(LoggerRegistry::hasLogger('website://'.$loggerName)){
$logger = LoggerRegistry::getInstance('website://'.$loggerName);
$logger->log($type, $message, $context);
}
//if($type > LogLevel::Notice && 'debug' !== $type){
// $this->devlog($message, $context);
//}
}
public function devlog(string $message, $data = []){
$file = $this->devlogfile;
$data = array_merge($this->context, $data);
if(!file_exists($file)){
// touch($file);
file_put_contents($file, "Log started: ".date("d.m.Y g:i A")."\n");
}
$fp = fopen($file, 'a');
fwrite($fp, sprintf('%1$s %2$s %3$s %4$s %5$s'.\PHP_EOL,
date("d.m.Y g:i A"),
$_SERVER['REMOTE_ADDR'],
$_SERVER['SERVER_NAME'],
$message,
json_encode($data)));
fclose($fp);
// $this->log('debug', $message, $data, 'default');
/*
$ShutdownTasks = \frdlweb\Thread\ShutdownTasks::mutex();
$ShutdownTasks(function($text, $logfile){
$fp = fopen($logfile, 'a');
fwrite($fp, $text);
fclose($fp);
}, sprintf('%1$s %2$s %3$s %4$s %5$s'.\PHP_EOL,
date("g:i A"),
$_SERVER['REMOTE_ADDR'],
$_SERVER['SERVER_NAME'],
$message,
json_encode($data)),
$file);
*/
/*
$ShutdownTasks(function($message, $data, $logfile){
$fp = fopen($logfile, 'a');
fwrite($fp, sprintf('%1$s %2$s %3$s %4$s %5$s'.\PHP_EOL,
date("g:i A"),
$_SERVER['REMOTE_ADDR'],
$_SERVER['SERVER_NAME'],
$message,
json_encode($data)));
fclose($fp);
}, $message, $data, $this->devlogfile);
*/
}
public function getPatchHtmlBodyAppend()
{
$html = '';
if(isset($_GET['errorinfo']) && isset($_GET['instance'])){
$html.="";
}
//frdl-fade-speed="100"
$footer = (null !== $this->container && $this->container->has('website.pageview.footer'))
? $this->container->get('website.pageview.footer')
: '
This is ALPHA Version of the installer! If you get this as your default-Template and want to install or use another system on this host, please delete this (index.php, webroot files and/or .frdl directory). If you want to continue to use this, we will guide you step by step. Just use the wizards on the next pages or contact the support if you need help further!
Dies ist die ALPHA-Version des Installers! Wenn Sie dies als Standard-Template erhalten und ein anderes System auf diesem Host installieren oder verwenden möchten, löschen Sie dieses bitte (index.php, Webroot-Dateien und/oder .frdl-Verzeichnis). Wenn Sie dies weiterhin verwenden möchten, werden wir Sie Schritt für Schritt anleiten. Verwenden Sie einfach die Assistenten auf den nächsten Seiten oder wenden Sie sich an den Support, wenn Sie weitere Hilfe benötigen!