Publish assets
@param string $appname App name
@param string $env Environment
@return Renderer
@throws \Exception
177527
public function publishActivity(string $appname, string $env):Renderer
    {
        $this->publish($appname, $env);
        return ((new Renderer())->jsonRenderer(array("code" => 200, "msg" => "OK")));
    }
629822
public function editActivity(string $servicename):Renderer
    {
        $status = $this->get("request")->get("status");
        $namespace = $this->get("request")->get("namespace");

        if ($status == "" || !in_array($status, array("enabled", "disabled"))) {
            return ((new Renderer())->jsonRenderer(array("code" => 500, "msg" => "Undefined status : $status")));
        }

        if ($namespace == "") {
            return ((new Renderer())->jsonRenderer(array("code" => 500, "msg" => "Undefined namespace : $namespace")));
        }


        $f = json_decode(file_get_contents(FEnv::get("framework.config.core.services.file")));

        foreach ($f as $one => $val) {
            if ($one == $servicename) {
                $val->namespace = trim(($namespace));
                $val->status = trim($status);
                break;
            }
        }
        $f = json_encode($f, JSON_PRETTY_PRINT);
        file_put_contents(FEnv::get("framework.config.core.services.file"), $f);

        return ((new Renderer())->jsonRenderer(array("code" => 200, "msg" => "OK")));
    }
1247502
private function callDelCreaServer(string $env)
    {
        Server::delete(FEnvFcm::get("framework.cache").$env, 'directory');
        Server::create(FEnvFcm::get("framework.cache").$env, 'directory');
    }
883138
public function publish($name, $source)
	{
		$destination = $this->publishPath."/packages/{$name}";

		$success = $this->files->copyDirectory($source, $destination);

		if ( ! $success)
		{
			throw new \RuntimeException("Unable to publish assets.");
		}

		return $success;
	}
845584
public function editActivity(string $appname):Renderer
    {
        $prefix = $this->get("request")->get("prefix");
        $enable = $this->get("request")->get("enabled");


        // Advanced options
        $vdev = $this->get("request")->get("vdev");
        $vprod = $this->get("request")->get("vprod");

        $hostsdeva = $this->get("request")->get("hostsdeva");
        $hostsdevd = $this->get("request")->get("hostsdevd");
        $hostsproda = $this->get("request")->get("hostsproda");
        $hostsprodd = $this->get("request")->get("hostsprodd");

        if ($prefix != "" && $this->checkPrefix($prefix) == -1) {
            return ((new Renderer())->jsonRenderer(array("code" => 500, "msg" =>
                "Error on app prefix. (App prefix must be a string without special character exepted [ _ & numbers])"))
            );
        }

        if (!in_array($enable, array("yes", "no"))) {
            return ((new Renderer())->jsonRenderer(array("code" => 500, "msg" => "App name already exist")));
        }

        if (!in_array($vdev, array("null", "false", "true"))) {
            return ((new Renderer())->jsonRenderer(array("code" => 500,
                "msg" => "Cannot set visibility on dev environment : Undefined value $vdev")));
        }

        if (!in_array($vprod, array("null", "false", "true"))) {
            return ((new Renderer())->jsonRenderer(array("code" => 500,
                "msg" => "Cannot set visibility on prod environment : Undefined value $vdev")));
        }

        $f = json_decode(file_get_contents(
            FEnv::get("framework.root")."elements/config_files/core/apps.json"
        ));

        foreach ($f as $one => $val) {
            if ($val->name == $appname) {
                $val->prefix = trim(stripslashes($prefix));
                $val->enabled = trim($enable);
                $val->update = new \DateTime('UTC');
                break;
            }
        }
        $f = json_encode($f, JSON_PRETTY_PRINT);
        file_put_contents(FEnv::get("framework.root")."elements/config_files/core/apps.json", $f);


        if ("null" === $vdev) {
            $vdev = null;
        } elseif ("false" === $vdev) {
            $vdev = false;
        } elseif ("true" === $vdev) {
            $vdev = true;
        } else {
            $vdev = null;
        }

        if ("null" === $vprod) {
            $vprod = null;
        } elseif ("false" === $vprod) {
            $vprod = false;
        } elseif ("true" === $vprod) {
            $vprod = true;
        } else {
            $vprod = null;
        }

        $hostsdeva  = (("" === trim($hostsdeva))? null : array_map(
            'trim',
            (explode(";", $hostsdeva))
        ));
        $hostsdevd  = (("" === trim($hostsdevd))? null : array_map(
            'trim',
            (explode(";", $hostsdevd))
        ));
        $hostsproda = (("" === trim($hostsproda))? null : array_map(
            'trim',
            (explode(";", $hostsproda))
        ));
        $hostsprodd = (("" === trim($hostsprodd))? null : array_map(
            'trim',
            (explode(";", $hostsprodd))
        ));




        if (JsonListener::exists(FEnv::get("app.config.file", $appname))) {
            $a = json_decode(file_get_contents(
                FEnv::get("app.config.file", $appname)
            ));
        } else {
            $a = new \stdClass();
        }

        $a->visibility_dev  = $vdev;
        $a->visibility_prod = $vprod;

        $a->hosts_allowed_dev   = $hostsdeva;
        $a->hosts_denied_dev    = $hostsdevd;
        $a->hosts_allowed_prod  = $hostsproda;
        $a->hosts_denied_prod   = $hostsprodd;

        $a = json_encode($a, JSON_PRETTY_PRINT);
        file_put_contents(FEnv::get("app.config.file", $appname), $a);

        return ((new Renderer())->jsonRenderer(array("code" => 200, "msg" => "OK")));
    }
382852
protected function renderApplication(Exception $e)
    {
        $response = $this->getExceptionHandler()->render($this->app['request'], $e);
        $response->send();
    }
903311
public function exportActivity(string $appname):Renderer
    {
        $appconfig = null;
        $file = JL::open(FEnv::get("framework.config.core.apps.file"));
        foreach ($file as $one => $val) {
            if ($val->name == $appname) {
                $appconfig = $val;
                break;
            }
        }
        if ($appconfig == null) {
            throw new Server500(new \ArrayObject(array("The application $appname does not exist.",
                "Please check your app configuration")));
        }
        unset($appconfig->enabled);

        try {
            $date = new \DateTime();
            $datefull = $date;
            $date = $date->format('YmdHi');
            $dirbase = FEnv::get("framework.bin").'exports/';
            $dirapp = $dirbase.($appname).'/';
            $dirappexp  = $dirapp.($appname)."_".$date.'/';
            Server::create($dirbase, 'directory');
            Server::create($dirapp, 'directory');
            Server::create($dirappexp, 'directory');
            JL::put($dirappexp."register.json", json_encode($appconfig, JSON_PRETTY_PRINT));
            $zip = new ZipEngine($dirapp.($appname)."_".$date.".zip");
            $zip->setSource(FEnv::get("framework.apps").$appname);
            $zip->addFile($dirappexp."register.json", "register.json");
            $zip->setArchiveComment("$appname - Export date :".$datefull->format('g:ia \o\n l jS F Y'));
            $zip->recursiveCompress();
            if ($zip->close()) {
                Server::delete($dirappexp, 'directory');
                return ((new Renderer())->jsonRenderer(array("code" => 200, "msg" => "OK")));
            } else {
                return ((new Renderer())->jsonRenderer(array("code" => 500,
                    "msg" => "Error on archive creation process")));
            }
        } catch (\Exception $e) {
            return ((new Renderer())->jsonRenderer(array("code" => 500,
                "msg" => "Error on archive creation process : ".$e->getMessage())));
        }
    }
494682
public function getOneActivity(string $filename, string $appname)
    {
        return ((new Renderer())->jsonRenderer(array("code" => 200, "msg" => "OK", "results" =>
            $this->getMercureContent($filename, $appname))));
    }
1119888
public function getAppInfo($appName) {
        $appClient = new AppClient($this->client);
        $response = $appClient->getById($appName);
        return $this->parseResponse($response, '获取App信息');
    }
1150781
static public function makeApp($envPath = null, array $config = [], $kernel = null)
    {
        $envPath = is_null($envPath) ? static::getRuntimePath() : $envPath;
        $kernel  = is_null($kernel)  ? static::defaultKernel()  : $kernel;
        $config  = empty($config)    ? static::defaultConfig()  : $config;

        return new static($envPath, $kernel, $config);
    }
523152
private function convertEnvVarNameToParamName($envVarName)
    {
        if (!preg_match('/^[A-Z]+(?:_{1,2}[A-Z]+)*$/', $envVarName)) {
            throw new \InvalidArgumentException("`{$envVarName}` is not a valid environment variable name.");
        }

        return (string) s($envVarName)
            ->toLowerCase()
            ->replace('__', '.')
        ;
    }
53322
public function select($filename)
  {
    $ext = substr(strrchr($filename, "."), 1);

    foreach ($this->renders as $renderer) {
      if ($renderer->can_use($ext)) {
        return $renderer;
      }
    }

    throw new \Exception('Render not available for this extension.');
  }
580627
public static function createHimSelf(string $appname):bool
    {
        if (false == JL::exists(FEnv::get("framework.root")."apps/".
            $appname."/config.json")) {
            $file = new \stdClass();
            $file->visibility_dev = null;
            $file->visibility_prod = null;
            $file->hosts_allowed_dev = null;
            $file->hosts_denied_dev = null;
            $file->hosts_allowed_prod = null;
            $file->hosts_denied_prod = null;
            $file->locale_enabled = false;
            $file->prefer_locale = null;
            $file->locale_values = null;
            $file->trans_type = null;

            JsonListener::put(
                FEnv::get("framework.root")."apps/". $appname."/config.json",
                json_encode($file, JSON_PRETTY_PRINT)
            );
            return (JL::exists(FEnv::get("framework.root")."apps/".
                $appname."/config.json"));
        }
        return (false);
    }
210398
public function renderTable(\Twig_Environment $env, $args = array()) {
        $array = array();
        $config = $this->fillModel($array);
        $array['deleteUrl'] = $this->fetchUrl($args, 'delete', $config->getDeleteRoute());
        $array['tableId'] = $config->getId();
        $array['transScope'] = $config->getTransScope();
        $array['views'] = $config->getViews();
        $array['frontendFramework'] = $config->getFrontendFramework();
        $array['frontendFrameworkName'] = FrontendFramework::toString($config->getFrontendFramework());
        return $this->render($env, 'twentystepsAutoTablesBundle:AutoTablesExtension:autoTable.html.twig', $array);
    }
1143581
protected function renderBody(&$env, $exception)
    {
        $title = 'Slim Application Error';
        $code = $exception->getCode();
        $message = $exception->getMessage();
        $file = $exception->getFile();
        $line = $exception->getLine();
        $trace = $exception->getTraceAsString();
        $html = sprintf('<h1>%s</h1>', $title);
        $html .= '<p>The application could not run because of the following error:</p>';
        $html .= '<h2>Details</h2>';
        $html .= sprintf('<div><strong>Type:</strong> %s</div>', get_class($exception));
        if ($code) {
            $html .= sprintf('<div><strong>Code:</strong> %s</div>', $code);
        }
        if ($message) {
            $html .= sprintf('<div><strong>Message:</strong> %s</div>', $message);
        }
        if ($file) {
            $html .= sprintf('<div><strong>File:</strong> %s</div>', $file);
        }
        if ($line) {
            $html .= sprintf('<div><strong>Line:</strong> %s</div>', $line);
        }
        if ($trace) {
            $html .= '<h2>Trace</h2>';
            $html .= sprintf('<pre>%s</pre>', $trace);
        }

        return sprintf("<html><head><title>%s</title><style>body{margin:0;padding:30px;font:12px/1.5 Helvetica,Arial,Verdana,sans-serif;}h1{margin:0;font-size:48px;font-weight:normal;line-height:48px;}strong{display:inline-block;width:65px;}</style></head><body>%s</body></html>", $title, $html);
    }
1258407
public function copyAssets(array $options)
    {

        $appname = '#none';
        $symlink = false;

        if (in_array("--symlink", $options["options"])) {
            $symlink = true;
        }
        if ($this->strlikeInArray("--appname", $options["options"]) != null) {
            $ch = $this->strlikeInArray("--appname", $options["options"]);
            $e = explode("=", $ch);
            $appname = $e[1];
            if (strpos($appname, "App") == false) {
                Output::displayAsRed("The app name is invalid");
            }

            if (!is_dir(FEnvFcm::get("framework.root")."/apps/".$appname)) {
                Output::displayAsRed("Assets Manager Error: App $appname doesn't exist.", "yes", false);
            }
        }

        $env = ($this->strlikeInArray("--env=", $options["options"]));
        if ($env != null) {
            $nenv = explode("=", $env);
            $env = strtolower($nenv[1]);
            if (!in_array($env, array("dev", "prod", "all"))) {
                if (!in_array("--quiet", $options["options"])) {
                    Output::displayAsRed(" The environment ".
                        strtoupper($env)." does not exist.\n", "yes");
                } else {
                    return (null);
                }
            }
        }
        Output::displayAsGreen("Hey, I'll copy ".(($appname != '#none')? $appname." assets (" :
                'all assets (').(($env != null && $env !== "all")? strtoupper($env)." environment)" :
                "all environments)")." in web folder".(($symlink == true)? ' with symlink option' : ''), "none");
        $this->callDelCreaServer($appname, $env);
        $this->copy($symlink, $appname, $env);
        if ($this-> strlikeInArray("--noexit", $options["options"]) != null) {
            Output::displayAsGreen("The copy of the assets".(($appname == '#none')? '' :
                    ' for '.$appname)." has been done.", "none", false);
        } else {
            Output::displayAsGreen("The copy of the assets".(($appname == '#none')? '' :
                    ' for '.$appname)." has been done.", "yes", false);
        }
    }
403157
public function logsdetailsActivity(string $uidie, string $env):Renderer
    {
        if (!in_array($env, array("dev", "prod"))) {
            throw new Server500(new \ArrayObject(array("explain" => "Bad environment name $env",
                "solution" => "Environment must be 'dev' or 'prod' ")));
        }
        $onelogs = AbstractServer::getLogs($env, 0, $uidie);

        if (empty($onelogs)) {
            throw new Server404(new \ArrayObject(array("explain" => "The error with uidie [".$uidie."] does not exist",
                "solution" => "Check the Uidie")));
        }
        return($this->render("logsdetails", array("details" => $onelogs, "selected" =>
            "logsmanager", "env" => strtolower($env), "loader_msg" => "Log with Uidie : $uidie")));
    }