public
Created

Zendcasts: PHAR out autoloading

  • Download Gist
Dates.php
PHP
1 2 3 4 5 6 7 8 9 10
<?php
namespace Zendcasts;
class Dates {
public static function next_week()
{
$datetime = new \DateTime();
$datetime->add(new \DateInterval('P7D'));
return $datetime->format('Y-m-d');
}
}
Strings.php
PHP
1 2 3 4 5 6 7 8 9 10
<?php
namespace Zendcasts;
 
class Strings
{
public function reverseMe($str)
{
return implode('',array_reverse(str_split($str)));
}
}
my_app.php
PHP
1 2 3 4 5 6 7
<?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";
pharbuilder.php
PHP
1 2 3 4 5 6
<?php
$phar = new Phar('Zendcasts.phar');
$phar->buildFromDirectory(dirname(__FILE__) . '/Zendcasts','/\.php$/');
$phar->compressFiles( Phar::GZ);
$phar->stopBuffering();
$phar->setStub($phar->createDefaultStub('stub.php'));
stub.php
PHP
1 2 3 4 5
<?php
 
function __autoload($name) {
require_once './' . str_replace('\\',DIRECTORY_SEPARATOR,$name) . '.php';
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.