code
stringlengths
1
2.01M
language
stringclasses
1 value
<?php class Asar_Representation_Exception extends Asar_Exception {}
PHP
<?php interface Asar_Representation_Interface { function fetch($data, $method, array $options = array()); }
PHP
<?php class Asar_ResponseExporter { function exportResponse(Asar_Response $response) { $headers = $response->getHeaders(); foreach ($headers as $key => $value) { $this->header("$key: $value"); } $this->header( "HTTP/1.1 {$response->getStatus()} {$response->getStatusReasonPhrase()}" ...
PHP
<?php interface Asar_RequestFilter_Interface { function filterRequest(Asar_Request_Interface $request); }
PHP
<?php class Asar_Exception extends Exception {}
PHP
<?php class Asar_EnvironmentHelper { private $request_factory, $response_exporter, $app_factory, $server, $params, $post; function __construct($request_factory, $response_exporter, $app_factory, $server, $params, $post) { $this->request_factory = $request_factory; $this->response_exporter = $response_exp...
PHP
<?php interface Asar_Message_Interface { function setHeader($name, $value); function getHeader($name); function setHeaders(array $headers); function getHeaders(); function setContent($content); function getContent(); }
PHP
<?php class Asar_ContentNegotiator implements Asar_ContentNegotiator_Interface { function negotiateFormat($accept_header, array $available_formats) { if (empty($available_formats)) { throw new Asar_ContentNegotiator_Exception( 'Asar_ContentNegotiator::negotiateFormat(). 2nd argument '. ...
PHP
<?php require_once 'FileSearcher/Interface.php'; class Asar_FileSearcher implements Asar_FileSearcher_Interface { function find($file_path) { if ($this->isAbsolutePath($file_path)) { if (is_file($file_path)) { return $file_path; } else { return false; } } $search_path...
PHP
<?php class Asar_EnvironmentScope { private $server = array(), $get = array(), $post = array(), $files = array(), $session = array(), $cookie = array(), $env = array(), $cwd, $argv = array(); function __construct($server, $get, $post, $files, $session, $c...
PHP
<?php class Asar_RequestFactory { function createRequest($server = array(), $params = array(), $post = null) { $options = array(); $options['method'] = $this->getIfExists('REQUEST_METHOD', $server); $options['path'] = $this->getIfExists('REQUEST_URI', $server); $options['params'] = $params; if...
PHP
<?php $main_app = 'Sample';
PHP
<?php class Sample_Resource_Index extends Asar_Resource { function GET() { return array('h1' => "Hello World!"); } }
PHP
<?php class Sample_Resource_Hello extends Asar_Resource { function GET() { return "Hello there!"; } }
PHP
<?php class Sample_Application extends Asar_Application { }
PHP
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <title><?php echo isset($title) ? $title : 'Sample App'?></title> </head> <body> <?php echo $content ?> </...
PHP
<h1><?= $h1 ?></h1> <p>Blalalkajdf;jasd;</p>
PHP
<?php /* set_include_path( realpath(dirname(__FILE__) . '/../../../lib/core') . PATH_SEPARATOR . realpath(dirname(__FILE__) . '/../apps') . PATH_SEPARATOR . realpath(dirname(__FILE__) . '/../lib/vendor') . PATH_SEPARATOR . get_include_path() );*/ require_once realpath(dirname(__FILE__) . '/../../../lib/core/Asa...
PHP
<?php class RemoveSvnEntries implements \Asar\Utility\Cli\CliInterface { private $cwd; private $controller = null; function __construct() { $this->cwd = getcwd(); } function setController(\Asar\Utility\Cli $controller) { $this->controller = $controller; } function getTaskNamespace() { ...
PHP
<?php // INTERNAL HEADERS 'Asar-Internal' => array( 'original_path' => '/some/where', 'isForwarded' => true, ); // CONFIG DEFAULTS: array( 'default_classes' => array( 'application' => 'Asar_ApplicationBasic', 'config' => 'Asar_Config_Default' ), 'templates' => array( 'engines' => array...
PHP
<?php $foo = array('bar' => array('baz' => 'yo')); var_dump(isset($foo['bar']['baz']));
PHP
<?php namespace Asar\Tests; class TempFilesManager { private $temp_dir; function __construct($dir) { if (!file_exists($dir)) { throw new TempFilesManager\Exception( "The directory specified ($dir) as temporary directory " . "does not exist." ); } $this->temp_dir = $di...
PHP
<?php namespace Asar\Tests; class TestServerManager { private static $can_connect; private $test_data_path; function __construct($test_data_path) { $this->test_data_path = $test_data_path; } private function constructPath() { $args = func_get_args(); return implode(DIRECTORY_SEPARATOR, ...
PHP
<?php namespace Asar\Tests\Functional\LoggingExample\LoggingExample\Resource; class Index extends \Asar\Resource { function GET() { /** * @todo this is overly complicated. The registration code should be * refactored and rethought. */ $logger = \Asar\Logger\Registry::getLogger($this); ...
PHP
<?php namespace Asar\Tests\Functional\LoggingExample\LoggingExample; class Config extends \Asar\Config { protected $config = array( 'use_templates' => false, ); function init() { $this->config['log_file'] = \Asar::getInstance() ->getFrameworkTestsDataTempPath() . DIRECTORY_SEPARATOR . 'examp...
PHP
<?php namespace Asar\Tests\Functional\DebuggingExample\DebuggingExample\Resource; class Index extends \Asar\Resource { function GET() { return array( 'h1' => 'Debugging Tests' ); } }
PHP
<?php namespace Asar\Tests\Functional\DebuggingExample\DebuggingExample; class Config extends \Asar\Config { protected $config = array( 'mode' => 'development', ); }
PHP
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <title><?= isset($title) ? $title : 'Debugging Functional Tests'?></title> </head> <body> <?= $content ?> ...
PHP
<h1 id="the_head"><?=$h1?></h1>
PHP
<?php namespace Asar\Tests\Functional\StatusCodesExample\StatusCodesExample\Resource; class Page extends \Asar\Resource { function GET() { return array('heading' => "This is a test."); } }
PHP
<?php namespace Asar\Tests\Functional\StatusCodesExample\StatusCodesExample\Resource; class A500 extends \Asar\Resource { public function GET() { throw new \Exception('Something is wrong.'); } }
PHP
<?php namespace Asar\Tests\Functional\StatusCodesExample\StatusCodesExample\Resource; class Index extends \Asar\Resource { public function GET() { $this->setConfig('use_templates', false); return "This is a test."; } }
PHP
<?php namespace Asar\Tests\Functional\StatusCodesExample\StatusCodesExample\Resource; /** * @note due to classname limitations in PHP, we cant have classnames that * start with a number. */ class A405 extends \Asar\Resource { function GET() { return "Get request"; } function POST() { return "Po...
PHP
<?php namespace Asar\Tests\Functional\StatusCodesExample\StatusCodesExample; class Application extends \Asar\Application { protected function setUp() { $this->setMap('/', 'Index'); $this->setMap('/page', 'Page'); $this->setMap('/a500', 'A500'); } }
PHP
<html> <head> <title>A Page</title> </head> <body> <h1><?=$heading?> </body> </html>
PHP
<?php namespace Asar\Tests\Functional\ResourceTraversing\ResourceTraversing\Resource\Blog; class RtYear extends \Asar\Resource { function GET() { return $this->request->getPath() . ' GET.'; } function qualify($path) { return preg_match('/^[1-9][0-9]{3}$/' , $path['year']); } }
PHP
<?php namespace Asar\Tests\Functional\ResourceTraversing\ResourceTraversing\Resource\Blog\RtYear\RtMonth; class RtTitle extends \Asar\Resource { function GET() { $path = $this->getPathComponents(); return $path['title']; } function qualify($path) { return preg_match('/^[1-9][0-9]{3}$/' ...
PHP
<?php namespace Asar\Tests\Functional\ResourceTraversing\ResourceTraversing\Resource\Blog\RtYear; class RtMonth extends \Asar\Resource { function GET() { return $this->request->getPath() . ' GET.'; } function qualify($path) { return preg_match('/^[1-9][0-9]{3}$/' , $path['year']) && p...
PHP
<?php namespace Asar\Tests\Functional\ResourceTraversing\ResourceTraversing\Resource\AParent\Child; class GrandChild extends \Asar\Resource { function GET() { return $this->getPath() . ' GET.'; } }
PHP
<?php namespace Asar\Tests\Functional\ResourceTraversing\ResourceTraversing\Resource\AParent; class Child extends \Asar\Resource { function GET() { return '/a-parent/child GET.'; } }
PHP
<?php namespace Asar\Tests\Functional\ResourceTraversing\ResourceTraversing\Resource; class Index extends \Asar\Resource { function GET() { return '/ GET.'; } }
PHP
<?php namespace Asar\Tests\Functional\ResourceTraversing\ResourceTraversing\Resource; class ForwardToChild extends \Asar\Resource { function GET() { $this->forwardTo('AParent\Child'); } }
PHP
<?php namespace Asar\Tests\Functional\ResourceTraversing\ResourceTraversing\Resource; class Blog extends \Asar\Resource { function GET() { return '/blog GET.'; } }
PHP
<?php namespace Asar\Tests\Functional\ResourceTraversing\ResourceTraversing\Resource; class AParent extends \Asar\Resource { function GET() { return '/a-parent GET.'; } }
PHP
<?php namespace Asar\Tests\Functional\ResourceTraversing\ResourceTraversing\Resource; class RedirectOne extends \Asar\Resource { function GET() { $this->redirectTo('AParent\Child\GrandChild'); } }
PHP
<?php namespace Asar\Tests\Functional\ResourceTraversing\ResourceTraversing; class Config extends \Asar\Config { protected $config = array( 'use_templates' => false, 'site_domain' => 'asar-test.local', 'site_protocol' => 'http', ); }
PHP
<?php namespace Asar\Tests\Functional\DirectResourceMapping\Example1\Resource; class What extends \Asar\Resource { function setUp() { $this->config['use_templates'] = false; } function GET() { return "What's your name?"; } function POST() { $name = $_POST['name']; return "Hello $name!"...
PHP
<?php namespace Asar\Tests\Functional\DirectResourceMapping\Example1\Resource; class Index extends \Asar\Resource { function setUp() { $this->config['use_templates'] = false; } function GET() { return 'Hello World!'; } }
PHP
<?php namespace Asar\Tests\Functional\DirectResourceMapping\Example1; /** * Test Example1 Application Class * * This is the Application definition for the application application * named 'Example1'. This test application is used only for integration * testing. */ class Config extends \Asar\Config { protecte...
PHP
<?php namespace Asar\Tests\Functional\TemplatesExample\TemplatesExample\Resource; class Xml extends \Asar\Resource { public function GET() { return array('foo' => 'This is from Xml.php'); } }
PHP
<?php namespace Asar\Tests\Functional\TemplatesExample\TemplatesExample\Resource; class AltTemplate extends \Asar\Resource { function setUp() { // TODO: How do we set a different template engine? //$this->setConfig('template_engines.phaml', 'Asar_Template_Engines_Haml'); //var_dump($this->config_bag)...
PHP
<?php namespace Asar\Tests\Functional\TemplatesExample\TemplatesExample\Resource; class Index extends \Asar\Resource { public function GET() { return array('p' => 'This is the paragraph. Easy, no?'); } public function POST() { return array( 'h2' => 'This is the subheading for the POST templa...
PHP
<?php namespace Asar\Tests\Functional\TemplatesExample\TemplatesExample\Resource; class ContentNegotiation extends \Asar\Resource { public function GET() { return array('foo' => 'This is from ContentNegotiation.php'); } }
PHP
<?php namespace Asar\Tests\Functional\TemplatesExample\TemplatesExample\Resource; class Alternative extends \Asar\Resource { public function GET() { return array('p' => 'This is an alternative template setup.'); } }
PHP
<?php namespace Asar\Tests\Functional\TemplatesExample\TemplatesExample\Resource; class SetLayout extends \Asar\Resource { public function GET() { return array( 'p' => 'This is the paragraph from SetLayout.php' ); } }
PHP
<?php namespace Asar\Tests\Functional\TemplatesExample\TemplatesExample\Resource; class Nolayout extends \Asar\Resource { public function GET() { return array( 'h1' => 'This is the main heading.', 'p' => 'This is the paragraph. Easy, no?' ); } }
PHP
<?php namespace Asar\Tests\Functional\TemplatesExample\TemplatesExample; class Application extends \Asar\Application { protected function setUp() { $this->setMap('/', 'Index'); $this->setMap('/nolayout', 'Nolayout'); $this->setMap('/set-layout', 'SetLayout'); $this->setMap('/alternative', 'Alternat...
PHP
<?php namespace Asar\Tests\Functional\TemplatesExample\TemplatesExample; class Config extends \Asar\Config { protected $config = array( 'template_engines' => array( 'atpl' => 'Asar\Tests\Functional\TemplatesExample\TemplatesExample\AtplTemplateEngine' ) ); }
PHP
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <title><?php echo isset($title) ? $title : 'Template Functional Tests'?></title> </head> <body> <?php echo...
PHP
<h1>In ContentNegotiation/GET.html.php.</h1> <p><?= $foo ?></p>
PHP
===================================================== In ContentNegotiation/GET.txt.php. ===================================================== <?= $foo ?>
PHP
<h1>This is the main heading found in Alternative.GET.html.php.</h1> <p><?php echo $p ?></p>
PHP
<h1>This is the main heading found in Index/GET.html.php.</h1> <p><?= $p ?></p>
PHP
===================================================== This is the main heading found in Index/GET.txt.php. ===================================================== <?= $p ?>
PHP
<h1>This is the main heading found in Index/POST.html.php.</h1> <h2><?= $h2 ?></h2> <div> <p><?= $p ?></p> </div>
PHP
<bar> <foo><?= $foo ?></foo> </bar>
PHP
<?php namespace Asar\Tests\Functional\TemplatesExample\TemplatesExample; use \Asar\Template\TemplateInterface; /** * TemplatesExample_AtplTemplateEngine * * This is a super simple template engine that uses a str_replace. This * is only used for demonstrating how an alternative template engine can * be used in y...
PHP
<?php namespace Asar\Tests\Functional\RepresentationExample\RepresentationExample\Resource; class Index extends \Asar\Resource { function GET() { return array( 'h1' => 'Hello World!', 'p' => 'This is the paragraph. Easy, no?' ); } }
PHP
<?php namespace Asar\Tests\Functional\RepresentationExample\RepresentationExample; class Application extends \Asar\Application { protected function setUp() { } }
PHP
<representation> <h1><?php echo $h1 ?></h1> <p><?php echo $p ?></p> </representation>
PHP
<?php namespace Asar\Tests\Functional\RepresentationExample\RepresentationExample\Representation; class Index extends \Asar\Representation { function getHtml($data) { return '<html> <head> <title>Representation Example Index</title> </head> <body> <h1>'. $da...
PHP
<?php namespace Asar\Tests; class Exception extends \Exception {}
PHP
<?php namespace Asar\Tests; /** * A helper class to wrap common test setups in one class for easier testing. */ abstract class TestCase extends \PHPUnit_Framework_TestCase { protected function quickMock($class, array $methods = array()) { return $this->getMock($class, $methods, array(), '', false); } ...
PHP
<?php namespace Asar\Tests\TempFilesManager; use \Asar\Tests\Exception as TestsException; class Exception extends TestsException {}
PHP
<?php ini_set('error_reporting', E_ALL | E_STRICT); $lib_path = realpath(__DIR__ . '/../lib/') . '/'; require_once $lib_path . 'SplClassLoader.php'; $classLoader = new SplClassLoader('Asar\Tests', __DIR__); $classLoader->register(); $classLoader = new SplClassLoader('Asar', $lib_path . 'asar'); $classLoader->register...
PHP
<?php // This is just dummy data. // Please see tests/unit/core/Asar/Utility/Cli/TaskFileLoaderTest.php return 'foobar';
PHP
<?php // See tests/unit/core/Asar/Utility/ClassFilePeekTest.php class Asar_ClassFilePeekTest_Foo { } class Asar_ClassFilePeekTest_Bar extends Asar_ClassFilePeekTest_Foo { }
PHP
<?php var_dump($_POST); var_dump($_SERVER); var_dump($_ENV); var_dump( file_get_contents('php://input') );
PHP
<?php abstract class Asar_Model_RedBean { private $oodb, $bean; function __construct( RedBean_ObjectDatabase $oodb, RedBean_OODBBean $bean = NULL ) { $this->oodb = $oodb; if ($bean) { $this->bean = $bean; } else { $this->bean = $this->oodb->dispense(get_class($this)); } ...
PHP
<?php require_once 'Asar/Toolset.php'; /** * The Asar class. Useful for getting information about the framework * and its directories. * */ class Asar { private static $paths = array(), $instance; private $toolset; /** * @param string $key path key to store or to obtain from self::$paths cache * ...
PHP
<?php namespace Asar; use \Asar\Message; use \Asar\Request\RequestInterface; /** */ class Request extends Message implements RequestInterface { private $path = '/', $method = 'GET', $params = array(); protected $headers = array('Accept' => 'text/html'), $content; function __...
PHP
<?php namespace Asar\PathDiscover; /** */ interface PathDiscoverInterface { function getPermaPath($path_params = array()); }
PHP
<?php namespace Asar; use \Asar\FileSearcher\FileSearcherInterface; use \Asar\FileIncludeManager\FileIncludeManagerInterface; /** */ class ClassLoader { private $searcher, $includer; function __construct( FileSearcherInterface $searcher, FileIncludeManagerInterface $includer ) { $this->search...
PHP
<?php namespace Asar; use \Asar\Message\MessageInterface; /** */ class Message implements MessageInterface { protected $headers = array(), $content = ''; function __construct($options = array()) { $this->setIfExists('content', $options, 'setContent'); $this->setIfExists('headers', $options, 'setHead...
PHP
<?php namespace Asar\Router; use \Asar\Router\RouterInterface; use \Asar\Router\Exception\ResourceNotFound; use \Asar\ResourceFactory; use \Asar\ResourceLister\ResourceListerInterface; use \Asar\Debug; use \Asar\Utility\String; /** */ class DefaultRouter implements RouterInterface { private $resource_factory, $...
PHP
<?php namespace Asar\Router\Exception; use \Asar\Router\Exception; /** */ class ResourceNotFound extends Exception {}
PHP
<?php namespace Asar\Router; /** */ interface RouterInterface { function route($app_name, $path, $map); }
PHP
<?php namespace Asar\Router; /** */ class Exception extends \Asar\Exception {}
PHP
<?php namespace Asar; use \Asar\File; use \Asar\FileHelper\Exception\FileAlreadyExists; use \Asar\FileHelper\Exception\DirectoryAlreadyExists; use \Asar\FileHelper\Exception\ParentDirectoryDoesNotExist; /** */ class FileHelper { function create($filename, $contents) { try { return File::create($filenam...
PHP
<?php namespace Asar\Configurable; /** * An interface that allows classes to be configurable */ interface ConfigurableInterface { function setConfig($key, $value); function getConfig($key); }
PHP
<?php namespace Asar\MessageFilter; use \Asar\RequestFilter\RequestFilterInterface; use \Asar\ResponseFilter\ResponseFilterInterface; use \Asar\Request\RequestInterface; use \Asar\Response\ResponseInterface; use \Asar\Config\ConfigInterface; use \Asar\Debug; use \Asar\DebugPrinter\DebugPrinterInterface; use \Asar\Debu...
PHP
<?php namespace Asar\MessageFilter; use \Asar\RequestFilter\RequestFilterInterface; use \Asar\ResponseFilter\ResponseFilterInterface; use \Asar\Config\ConfigInterface; use \Asar\Request\RequestInterface; use \Asar\Response\ResponseInterface; use \Asar\Message\MessageInterface; use \Asar\Utility\String; /** */ class ...
PHP
<?php namespace Asar\Client\Exception; use \Asar\Client\Exception; /** */ class UnknownServerType extends Exception {}
PHP
<?php namespace Asar\Client; /** */ class Exception extends \Asar\Exception {}
PHP
<?php namespace Asar; use \Asar\Resource\ResourceInterface; use \Asar\Resource\Exception\NotFound; use \Asar\Resource\Exception\MethodUndefined; use \Asar\Resource\Exception\ForwardRequest; use \Asar\Resource\Exception\Redirect; use \Asar\Config\ConfigInterface; use \Asar\Config; use \Asar\PathDiscover\PathDiscoverIn...
PHP
<?php namespace Asar\FileIncludeManager; /** * A wrapper interface for including files * @todo: maybe this can be removed in favor of SplClassLoader */ interface FileIncludeManagerInterface { function requireFileOnce($file); function includeFile($file); }
PHP
<?php namespace Asar\EnvironmentHelper; use \Asar\Config\ConfigInterface; use \Asar\RequestFactory; use \Asar\ResponseExporter; use \Asar\ApplicationScope; use \Asar\ApplicationInjector; /** * Environment helper that sets up the web server environment. This is * what is mostly used in the front controller. */ class...
PHP
<?php namespace Asar\EnvironmentHelper; use \Asar\Utility\Cli as UtilityCli; use \Asar\Utility\Cli\TaskFileLoader; /** * Environment Helper for setting up the CLI interface */ class Cli { private $cli, $args, $tasklists = array(), $task_file_loader; /** * @param Asar_Utility_Cli $cli * @param array $arg...
PHP
<?php namespace Asar\EnvironmentHelper; /** * A bootstrap environment helper for setting up a class loader and registering * it. */ class Bootstrap { private $class_loader; /** * @param callback $class_loader */ function __construct($class_loader) { $this->class_loader = $class_loader; } /*...
PHP
<?php namespace Asar\Resource; use \Asar\Request\RequestInterface; /** */ interface ResourceInterface { function handleRequest(RequestInterface $request); }
PHP