Skip to content

Commit

Permalink
Added more README files and started the tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
hollodotme committed Jul 29, 2014
1 parent c8d3690 commit c0c7ce8
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 50 deletions.
60 changes: 60 additions & 0 deletions PHPExport/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# hollodotme\Helpers

## PHPExport

This is a small collection of classes that enable you to export every class or
even entire extension into PHP code or a PHP Archive (PHAR).

### Why this?

As I wrote a new class that used the PECL extension "pecl_http 2.0.x", I messed up,
because my development IDE (PphStorm) did not recognized the extension's namespace, classes, methods and so on.
And of course, no auto completion at all!

Unfortunately there was/is no PHP source code of that extension, so I started exporting it by using the Reflection classes of PHP.

In the end, I was able to export a PHAR file for the hole extension and could link that file into my IDE as an external library.

### How does this work?

There are 3 ways to export an entire extension and 2 ways to export a single class.

1: Export a PHAR for the whole extension

<?php
$extension = new \ReflectionExtension('http');
$exporter = new \hollodotme\Helpers\PHPExport\ReflectionExtension($extension);
$exporter->exportPHAR('pecl_http.phar', '/var/www/lib', true);

2: Export all files for the whole extension (including sub directories by namespace depth)

<?php
$extension = new \ReflectionExtension('http');
$exporter = new \hollodotme\Helpers\PHPExport\ReflectionExtension($extension);
$exporter->exportFiles('/var/www/lib/http');

3: Just print all classes/interfaces/traits from the extension

<?php
header('Content-type: text/plain');
$extension = new \ReflectionExtension('http');
$exporter = new \hollodotme\Helpers\PHPExport\ReflectionExtension($extension);
echo $exporter->exportCode();

4: Export a single class/interface/trait to a file

<?php
$class = new \ReflectionClass('http\\Url');
$exporter = new \hollodotme\Helpers\PHPExport\ReflectionClass($class);
$exporter->exportFile('/var/www/lib/http/Url.php');

5: Just print a single class/interface/trait

<?php
header('Content-type: text/plain');
$class = new \ReflectionClass('http\\Url');
$exporter = new \hollodotme\Helpers\PHPExport\ReflectionClass($class);
echo $exporter->exportCode();

Maybe this will help you out, too.

62 changes: 12 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,60 +1,22 @@
# hollodotme\Helpers

## PHPExport

This is a small collection of classes that enable you to export every class or
even entire extension into PHP code or a PHP Archive (PHAR).

### Why this?

As I wrote a new class that used the PECL extension "pecl_http 2.0.x", I messed up,
because my development IDE (PphStorm) did not recognized the extension's namespace, classes, methods and so on.
And of course, no auto completion at all!

Unfortunately there was/is no PHP source code of that extension, so I started exporting it by using the Reflection classes of PHP.

In the end, I was able to export a PHAR file for the hole extension and could link that file into my IDE as an external library.
## What is this?

### How does this work?
This is a collection of some handy code packages and tutorials to make developer's life easier.

There are 3 ways to export an entire extension and 2 ways to export a single class.

1: Export a PHAR for the whole extension

<?php
$extension = new \ReflectionExtension('http');
$exporter = new \hollodotme\Helpers\PHPExport\ReflectionExtension($extension);
$exporter->exportPHAR('pecl_http.phar', '/var/www/lib', true);

2: Export all files for the whole extension (including sub directories by namespace depth)

<?php
$extension = new \ReflectionExtension('http');
$exporter = new \hollodotme\Helpers\PHPExport\ReflectionExtension($extension);
$exporter->exportFiles('/var/www/lib/http');
## PHPExport

3: Just print all classes/interfaces/traits from the extension
PHPExport is a small collection of classes to export PHP extentions or classes into PHP code or even a PHAR.
This was designed to make auto completion and namespaces accessible for extentions or classes were only provided as compiled extension but not as PHP code,
e.g. pecl_http Version 2.x.

<?php
header('Content-type: text/plain');
$extension = new \ReflectionExtension('http');
$exporter = new \hollodotme\Helpers\PHPExport\ReflectionExtension($extension);
echo $exporter->exportCode();
Please read the README.md in the subfolder for more information and a "how to use".

4: Export a single class/interface/trait to a file
## Tutorials

<?php
$class = new \ReflectionClass('http\\Url');
$exporter = new \hollodotme\Helpers\PHPExport\ReflectionClass($class);
$exporter->exportFile('/var/www/lib/http/Url.php');
I often come across tool or configuration issues that can be solved by reading tons of documentation.
These tutorials shall summarize each to a single page. Please discuss this and feel free to suggest corrections and improvements!

5: Just print a single class/interface/trait

<?php
header('Content-type: text/plain');
$class = new \ReflectionClass('http\\Url');
$exporter = new \hollodotme\Helpers\PHPExport\ReflectionClass($class);
echo $exporter->exportCode();
For an overview of the tutorials please read the README.md in the subfolder.

Maybe this will help you out, too.

Happy developing!
9 changes: 9 additions & 0 deletions Tutorials/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Tutorials

## How to set up a self-hosted "vagrant cloud" with versioned, self-packaged vagrant boxes

As I dived into vagrant for a whole new project setup in my company, I was really amazed about how easy it is to get this "up and running".
But then I wanted to adopt the versioned vm service to the private network, because the official vagrant cloud was not an option for the company.
That's the point where the official documentation and support resources will lead you confused.

Read `vagrant/self-hosted-versioned-boxes.md` for a basic company solution.
87 changes: 87 additions & 0 deletions Tutorials/vagrant/self-hosted-versioned-vagrant-boxes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# How to set up a self-hosted "vagrant cloud" with versioned, self-packaged vagrant boxes

## Preamble

Before we start setting things up, I assume this is what you know / what you have:

* What vagrant is and how it basically works (obviously!)
* How to set up a webserver like nginx or apache2
* Basic knowledge about working with linux systems
* A public or private webserver where you can run/configure a webserver (nginx/apache2) and up/download files.
* A host system with a GUI (e.g. Windows, Mac OS X, etc.)

The tutorial uses an installation of [Ubuntu 14.04.1 LTS](https://wiki.ubuntu.com/TrustyTahr/ReleaseNotes)
as the guest machine, [VirtualBox](http://virtualbox.org) at version 4.3.14 as provider
and [Vagrant](http://vagrantup.com) at version 1.6.3.

## 1. Install the tools

* Download and install VirtualBox 4.3.14 at http://download.virtualbox.org/virtualbox/4.3.14/ (Choose the installer that fits your system)
* Download and install Vagrant 1.6.3 at https://dl.bintray.com/mitchellh/vagrant/ (Choose the installer that fits your system)

## 2. Prepare your virtual machine

### 2.1 Import an Ubuntu image to VirtualBox

* Download a VirtualBox image of Ubuntu 14.04.1 LTS, e.g. at http://virtualboxes.org/images/ubuntu-server/ (all the following steps refer to this image)
* Open the VirtualBox GUI and choose `File > Import appliance ...`, select the `.ova` file you downloaded before.
* Change the appliance settings to fit your needs, for now I'll only change the name of the machine from `ubuntu-14.04-server-amd64` to `devops-template`.
* Important: Make sure to activate `Reinitialize the MAC address of all network cards` checkbox!
* Click `Import` and you'll have a new virtual machine added to VirtualBox after a few minutes ready to run.

### 2.2 Setup the virtual machine

#### Before you boot the vm for the first time:

* Select the newly imported vm named `devops-template` in VirtualBox GUI and click `Settings`
* Select the tab `Network`
* Activate `Enable Network Adapter` (if not already activated) under the tab `Adapter 1`
* Select `Attached to: NAT` ([this is a requirement by Vagrant](http://docs.vagrantup.com/v2/virtualbox/boxes.html))
* Leave everything else as is.

#### Configure the guest

* Select the vm named `devops-template` in VirtualBox GUI and click `Start` (wait until you see the `ubuntu-amd64 login:`)
* Type `ubuntu` as loginname an `reverse` as password.
* First of all, update the machine. This will take a moment. Get a coffee!

```bash
$ sudo apt-get update
$ sudo apt-get dist-upgrade -y
```

* Edit the file `/root/.profile`

```bash
$ sudo nano /root/.profile
# ~/.profile: executed by Bourne-compatible login shells.

if [ "$BASH" ]; then
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
fi

mesg n # replace this line by "tty -s && mesg n"
```

Note: This avoids an annoying warning, when you vagrant up later.

* Change the hostname

```bash
$ sudo nano /etc/hostname
ubuntu-amd64 # replace this by "devops-template"
```
* Let the machine resolve its own hostname

```bash
$ sudo nano /etc/hosts
127.0.0.1 localhost
127.0.1.1 ubuntu-amd64 # replace this by "127.0.1.1 devops-template"

# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
```

0 comments on commit c0c7ce8

Please sign in to comment.