Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-coyle committed Dec 9, 2014
0 parents commit b544920
Show file tree
Hide file tree
Showing 940 changed files with 98,667 additions and 0 deletions.
50 changes: 50 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Created by https://www.gitignore.io

### PhpStorm ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm

*.iml

## Directory-based project format:
.idea/
# if you remove the above rule, at least ignore the following:

# User-specific stuff:
# .idea/workspace.xml
# .idea/tasks.xml
# .idea/dictionaries

# Sensitive or high-churn files:
# .idea/dataSources.ids
# .idea/dataSources.xml
# .idea/sqlDataSources.xml
# .idea/dynamic.xml
# .idea/uiDesigner.xml

# Gradle:
# .idea/gradle.xml
# .idea/libraries

# Mongo Explorer plugin:
# .idea/mongoSettings.xml

## File-based project format:
*.ipr
*.iws

## Plugin-specific files:

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties

103 changes: 103 additions & 0 deletions src/Vhost.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php namespace Vhost;


/**
* @file
* @author Kevin Coyle
* Contains the VHost Class.
*/

class Vhost {
private $name;
private $vHostDir;
private $domain;
private $hostDir;
/**
* @return mixed
*/
public function getDomain()
{
return $this->domain;
}

public function __construct($name, $vHostDir, $hostDir) {
$name = preg_replace('/\s+/', '', $name);
$this->name = htmlspecialchars(strtolower($name));
$this->vHostDir = self::setVhostDir($vHostDir);
$this->hostDir = $hostDir;
}

/**
* Sets the Virtual Host Directory.
* @param $vHostDir
* @return mixed
*/
private function setVhostDir($vHostDir) {
if(file_exists($vHostDir)) {
return $vHostDir;
}
throw new Exception('VHost Directory Does Not Exist');
}

/**
* Lists all Vhost conf files that have been created.
* @param string $VhostDir
* @return array
*/
public function listVhosts() {
$vHostDir = $this->vHostDir;
if (!file_exists($vHostDir)) {
throw new Exception('VHost Directory Does Not Exist');
}
$files = array_diff(scandir($vHostDir), array('.', '..'));
return $files;
}

/**
* Creates the VHost File.
* @param $name
* @param $vHostDir
*/
public function createVhostFile($name, $vHostDir) {
$uniqueDomain = $this->generateUniqueDomain($name);
$hostDir = $this->hostDir;
$domain = $this->getDomain();
$output = <<<EOD
<VirtualHost *:80>
ServerName {$domain}
ServerAdmin [email protected]
ErrorLog /var/log/httpd/{$name}.err
CustomLog /var/log/httpd/{$name}.log combined
DocumentRoot {$hostDir}/{$name}
<Directory "{$hostDir}/{$name}">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
EOD;
file_put_contents("{$vHostDir}/{$name}.conf", $output . PHP_EOL);
}

/**
* Generates a unique name that can be used for the domain name.
* @return string
*/
private function generateUniqueDomain($name) {
$this->domain = uniqid($name . '-') . '.192.168.99.56.xip.io';
return $this->domain;
}
/**
* Returns the contents of a VHost file.
* @return string
*/
public function getVhost() {
$name = $this->name;
$vHostDir = $this->vHostDir;
$vHostFileName = $vHostDir . '/' . $name . '.conf';
if (!file_exists($vHostFileName)) {
throw new Exception('VHost File Does Not Exist');
}
return file_get_contents($vHostDir . '/' . $name . '.conf');
}

}
15 changes: 15 additions & 0 deletions src/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "coyledesign/centos-vhost-generator",
"description": "Creates a new vhost on centos",
"require-dev": {
"phpunit/phpunit": "~4.4"
},
"license": "MIT",
"authors": [
{
"name": "kevincoyle",
"email": "[email protected]"
}
],
"require": {}
}
Loading

0 comments on commit b544920

Please sign in to comment.