示例#1
0
 /**
  * Use the given host name to find it's corresponding configuration
  * in the configuration file.
  *
  * If the host is not found in the configuration, null is returned.
  *
  * Returns an associative array with the following keys:
  * @retval host string: The host name to be used for lookups in the
  *         commandmap. This is one of the following values from the
  *         configuration in that order: `host', `sld', hash key.
  * @retval sld string: Subdomain as specified in the config using `sld'.
  * @retval tld string: Topdomain as specified in the config using `tld'.
  *         If tld is not specified but the sld is, then the tld is
  *         extracted from the hostname automatically.
  * @retval path string: Path as specified in the config. Can be used to
  *         "mount" the application at the specified point. Stored in
  *         the global constants API_MOUNTPATH.
  *
  * @config <b>hosts</b> (hash): Contains all host configurations. The
  *         hash keys specify the host name.
  * @config <b>host-><em>hostname</em>->host</b> (string):
  *         Overwrite the host name from the key.
  * @config <b>host-><em>hostname</em>->sld</b> (string):
  *         Specify a sublevel domain for this host. This value can be
  *         accessed using api_request::getSld().
  * @config <b>host-><em>hostname</em>->tld</b> (string):
  *         Specify a top-level domain for this host. This value can be
  *         accessed using api_request::getTld(). If sld is specified but
  *         the value isn't, then the tld is computed automatically.
  * @config <b>host-><em>hostname</em>->path</b> (string):
  *         Path where this application is mounted on. This has
  *         implications for the routing engine (see api_routing). Defaults
  *         to "/".
  * @param $hostname: Host name to return config for.
  */
 public static function getHostConfig($hostname)
 {
     $hosts = array();
     $host = null;
     // Read config
     $cfg = api_config::getInstance();
     if ($cfg->hosts) {
         $hosts = $cfg->hosts;
         foreach ($hosts as $key => &$hostconfig) {
             $lookupName = $key;
             if (isset($hostconfig['host'])) {
                 $lookupName = $hostconfig['host'];
             } else {
                 if (isset($hostconfig['sld'])) {
                     $lookupName = $hostconfig['sld'];
                 }
             }
             $hostconfig['host'] = $lookupName;
             if ($key == $hostname) {
                 $host = $hostconfig;
                 break;
             } else {
                 if (api_helpers_string::matchWildcard($key, $hostname)) {
                     $host = $hostconfig;
                     if ($lookupName == $key) {
                         // Replace host with current hostname
                         $host['host'] = $hostname;
                     }
                     break;
                 }
             }
         }
     }
     // Host not found
     if (is_null($host)) {
         return null;
     }
     // Calculate tld from hostname if sld is set.
     if (isset($host['sld']) && !isset($host['tld'])) {
         if (strpos($hostname, $host['sld'] . '.') === 0) {
             // Hostname starts with sld
             $host['tld'] = substr($hostname, strlen($host['sld']) + 1);
         }
     }
     // Return values
     $path = !empty($host['path']) ? $host['path'] : '/';
     if ($path[0] !== '/') {
         $path = '/' . $path;
     }
     return array('host' => $host['host'], 'tld' => @$host['tld'], 'sld' => @$host['sld'], 'path' => $path);
 }
示例#2
0
 protected function generateScaffoldController($name)
 {
     $filename = '';
     $controller = '';
     //$name = $this->console->argument(1);
     if (strstr($name, '_')) {
         list($this->namespace, $name) = explode('_', $name);
     }
     $pluralized_name = api_helpers_string::plural($name);
     $filename = $pluralized_name . '.php';
     $controller = file_get_contents($this->template_dir . 'controller.php');
     if ($this->namespace != '') {
         $filename = $this->namespace . '/' . $filename;
         $controller = str_replace("namespace", $this->namespace, $controller);
     } else {
         $controller = str_replace("namespace/", "", $controller);
     }
     $controller = str_replace("nameplural", $pluralized_name, $controller);
     $controller = str_replace("name", $name, $controller);
     $this->destination_dir .= 'controllers/';
     if (!is_file($this->destination_dir . $filename)) {
         echo "create: " . $this->destination_dir . $filename . "\n";
         file_put_contents($this->destination_dir . $filename, $controller);
     } else {
         echo "exists: " . $this->destination_dir . $filename . "\n";
     }
 }
示例#3
0
 /**
  * Parses out a file name from the current path.
  * The last path component is returned if it contains an extension
  * of at least one character.
  * @param $path string: Path to parse.
  * @return string: File name
  */
 private function parseFilename($path)
 {
     preg_match("#[^\\/]*\\.[a-z0-9]{1,}\$#i", $path, $matches);
     if (isset($matches[0])) {
         return api_helpers_string::ensureUtf8(urldecode($matches[0]));
     }
     return '';
 }