Skip to content

Instantly share code, notes, and snippets.

@jlebensold
Created October 10, 2011 22:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlebensold/1276774 to your computer and use it in GitHub Desktop.
Save jlebensold/1276774 to your computer and use it in GitHub Desktop.
Zendcasts: PHAR out autoloading
<?php
namespace Zendcasts;
class Dates {
public static function next_week()
{
$datetime = new \DateTime();
$datetime->add(new \DateInterval('P7D'));
return $datetime->format('Y-m-d');
}
}
<?php
require_once 'phar://Zendcasts.phar';
$str = new Zendcasts\Strings();
echo $str->reverseMe("hello world") . "\n";
echo "hello \n Next week is " . Zendcasts\Dates::next_week() . "\n";
<?php
$phar = new Phar('Zendcasts.phar');
$phar->buildFromDirectory(dirname(__FILE__) . '/Zendcasts','/\.php$/');
$phar->compressFiles( Phar::GZ);
$phar->stopBuffering();
$phar->setStub($phar->createDefaultStub('stub.php'));
<?php
namespace Zendcasts;
class Strings
{
public function reverseMe($str)
{
return implode('',array_reverse(str_split($str)));
}
}
<?php
function __autoload($name) {
require_once './' . str_replace('\\',DIRECTORY_SEPARATOR,$name) . '.php';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment