Vendorize ZF1, fix PHPUnit and configure travis

This a a rather large commit due to the nature of the stuff it is touching. To get PHPUnit up and running again I had to update some deps and I did so by vendorizing them. The vendorizing of zf1 makes sense since distros are already considering to drop it from their repos.

* [x] install vendorized zf1 with composer
* [x] load composer autoloader before zf1
* [x] Implement headAction for all Zend_Rest_Controller based controllers
* [x] switch to yml dataset to get around string only limitations of xml sets (also removed warning in readme)
* [x] use year 2044 as hardcoded date for tests since it is in the future and has the same days like previously used 2016
* [x] make tests easier to run when accessing phpunit directly
* [x] clean up test helper to always use airtime.conf
* [x] switch test dbname to libretime_test
* [x] test db username password switched to libretime/libretime
* [x] install phpunit with composer in a clear version (make tests easier to reproduce on other platforms)
* [x] remove local libs from airtime repo (most of airtime_mvc/library was not needed of in vendor already)
* [x] configure composer autoloading and use it (also removed requires that are not needed anymore)
* [x] add LibreTime prefix for FileNotFoundException (phing had a similar class and these are all pre-namespace style)
* [x] add .travis.yml file
* [x] make etc and logdir configurable with LIBRETIME_CONF_DIR and LIBRETIME_LOG_DIR env (so travis can change it)
* [x] slight cleanup in config for travis not to fail
* [x] add cloud_storage.conf for during test runs
* [x] rewrite mvc testing docs and move them to docs/ folder
* [x] don't use `static::class` in a class that does not have a parent class, use `__CLASS__` instead.
* [x] don't use `<ClassName>::class`, since we already know what class we want `"<ClassName>"` ist just fine.
* [x] fix "can't use method in write context" errors on 5.4 (also helps the optimizer)
* [x] add build status badge on main README.md

Fixes https://github.com/LibreTime/libretime/issues/4

The PHP parts of https://github.com/LibreTime/libretime/pull/10 get obsoleted by this change and it will need rebasing.

This also contains https://github.com/LibreTime/libretime/pull/8, the late static binding compat code was broken for no reason and until CentOS drops php 5.4 there is no reason I'm aware of not to support it. I inlined #8 since the test would be failing on php 5.4 without the change.

If you want to run tests you need to run `composer install` in the root directory and then `cd airtime_mvc/tests && ../../vendor/bin/phpunit`. For the tests to run the user `libretime` needs to be allowed to create the `libretime_test` database. See `docs/TESTING.md` for more info on getting set up.
This commit is contained in:
Lucas Bickel 2017-02-20 21:47:53 +01:00
parent 95ce7ef880
commit 625f92fe44
456 changed files with 3493 additions and 64496 deletions

1
.gitignore vendored
View File

@ -1,4 +1,3 @@
.*
*.*~
*.pyc
vendor/*

23
.travis.yml Normal file
View File

@ -0,0 +1,23 @@
language: php
php:
- '5.5'
- '5.4'
services:
- postgresql
- rabbitmq
env:
global:
- ENVIRONMENT=testing
- LIBRETIME_CONF_DIR=/tmp/libretime
- LIBRETIME_LOG_DIR=/tmp/log/libretime
install:
- composer install
before_script:
- psql -c 'CREATE DATABASE libretime;' -U postgres
- psql -c "CREATE USER libretime WITH PASSWORD 'libretime';" -U postgres
- psql -c 'GRANT CONNECT ON DATABASE libretime TO libretime;' -U postgres
- psql -c 'ALTER USER libretime CREATEDB;' -U postgres
- mkdir -p /tmp/libretime/testing/ /tmp/log/libretime
- cp airtime_mvc/tests/airtime.conf airtime_mvc/tests/cloud_storage.conf /tmp/libretime/testing/
script:
- cd airtime_mvc/tests && ../../vendor/bin/phpunit

View File

@ -1,5 +1,7 @@
# LibreTime
[![Build Status](https://travis-ci.org/LibreTime/libretime.svg?branch=master)](https://travis-ci.org/LibreTime/libretime)
LibreTime is a community managed fork of the AirTime project.
It is managed by a friendly inclusive community of stations

View File

@ -10,57 +10,9 @@ if (!isset($configRun) || !$configRun) {
Propel::init(CONFIG_PATH . 'airtime-conf-production.php');
}
//Composer's autoloader
require_once 'autoload.php';
require_once CONFIG_PATH . "constants.php";
/* Common */
require_once "DateHelper.php";
require_once "LocaleHelper.php";
require_once "FileDataHelper.php";
require_once "HTTPHelper.php";
require_once "FileIO.php";
require_once "OsPath.php";
require_once "Database.php";
require_once "ProvisioningHelper.php";
require_once "SecurityHelper.php";
require_once "SessionHelper.php";
require_once "GoogleAnalytics.php";
require_once "Timezone.php";
require_once "CeleryManager.php";
require_once "TaskManager.php";
require_once "PodcastManager.php";
require_once "UsabilityHints.php";
require_once __DIR__.'/models/formatters/LengthFormatter.php';
require_once __DIR__.'/common/widgets/Table.php';
/* Models */
require_once "Auth.php";
require_once 'Preference.php';
require_once 'Locale.php';
/* Enums */
require_once "Enum.php";
require_once "MediaType.php";
require_once "HttpRequestType.php";
/* Interfaces */
require_once "OAuth2.php";
require_once "OAuth2Controller.php";
require_once "Publish.php";
/* Factories */
require_once __DIR__.'/services/CeleryServiceFactory.php';
require_once __DIR__.'/services/PublishServiceFactory.php';
require_once __DIR__.'/forms/helpers/ValidationTypes.php';
require_once __DIR__.'/forms/helpers/CustomDecorators.php';
require_once __DIR__.'/controllers/plugins/PageLayoutInitPlugin.php';
require_once __DIR__.'/controllers/plugins/RabbitMqPlugin.php';
require_once __DIR__.'/controllers/plugins/Maintenance.php';
require_once __DIR__.'/controllers/plugins/ConversionTracking.php';
require_once __DIR__.'/modules/rest/controllers/ShowImageController.php';
require_once __DIR__.'/modules/rest/controllers/MediaController.php';
require_once __DIR__.'/upgrade/Upgrades.php';
require_once (APPLICATION_PATH . "/logging/Logging.php");
Logging::setLogPath('/var/log/airtime/zendphp.log');
Logging::setLogPath(LIBRETIME_LOG_DIR . '/zendphp.log');
// We need to manually route because we can't load Zend without the database being initialized first.
if (array_key_exists("REQUEST_URI", $_SERVER) && (stripos($_SERVER["REQUEST_URI"], "/provisioning/create") !== false)) {

View File

@ -48,11 +48,6 @@ set_include_path(APPLICATION_PATH . 'controllers' . PATH_SEPARATOR . get_include
//Controller plugins.
set_include_path(APPLICATION_PATH . 'controllers/plugins' . PATH_SEPARATOR . get_include_path());
//Zend framework
if (file_exists('/usr/share/php/libzend-framework-php')) {
set_include_path('/usr/share/php/libzend-framework-php' . PATH_SEPARATOR . get_include_path());
}
//Services.
set_include_path(APPLICATION_PATH . '/services/' . PATH_SEPARATOR . get_include_path());
@ -65,7 +60,8 @@ set_include_path(APPLICATION_PATH . '/upgrade/' . PATH_SEPARATOR . get_include_p
//Common directory
set_include_path(APPLICATION_PATH . '/common/' . PATH_SEPARATOR . get_include_path());
//Composer's autoloader
require_once 'autoload.php';
/** Zend_Application */
require_once 'Zend/Application.php';
@ -75,7 +71,7 @@ $application = new Zend_Application(
);
require_once(APPLICATION_PATH . "logging/Logging.php");
Logging::setLogPath('/var/log/airtime/zendphp.log');
Logging::setLogPath(LIBRETIME_LOG_DIR . '/zendphp.log');
Logging::setupParseErrorLogging();
// Create application, bootstrap, and run

View File

@ -1,8 +1,5 @@
<?php
require_once 'StorageBackend.php';
require_once 'Billing.php';
use Aws\S3\S3Client;
class Amazon_S3StorageBackend extends StorageBackend

View File

@ -1,8 +1,5 @@
<?php
require_once 'StorageBackend.php';
require_once 'FileStorageBackend.php';
require_once 'Amazon_S3StorageBackend.php';
/**
*

View File

@ -22,7 +22,7 @@ class Application_Common_FileIO
{
$fm = @fopen($filePath, 'rb');
if (!$fm) {
throw new FileNotFoundException($filePath);
throw new LibreTimeFileNotFoundException($filePath);
}
//Note that $size is allowed to be zero. If that's the case, it means we don't

View File

@ -56,7 +56,7 @@ class PodcastManager {
protected static function _findUningestedEpisodes($podcast, $service) {
$episodeList = $service->getPodcastEpisodes($podcast->getDbPodcastId());
$episodes = array();
usort($episodeList, array(static::class, "_sortByEpisodePubDate"));
usort($episodeList, array(__CLASS__, "_sortByEpisodePubDate"));
for ($i = 0; $i < sizeof($episodeList); $i++) {
$episodeData = $episodeList[$i];
$ts = $podcast->getDbAutoIngestTimestamp();

View File

@ -351,8 +351,7 @@ class TaskFactory {
*/
private static function _isTask($c) {
$reflect = new ReflectionClass($c);
$clazz = version_compare(phpversion(), '5.5.0', '<') ? "AirtimeTask" : AirtimeTask::class;
return $reflect->implementsInterface($clazz);
return $reflect->implementsInterface('AirtimeTask');
}
/**

View File

@ -1,6 +1,5 @@
<?php
require_once 'Acl_plugin.php';
$ccAcl = new Zend_Acl();

View File

@ -1,9 +1,11 @@
<?php
/* THIS FILE IS NOT MEANT FOR CUSTOMIZING.
* PLEASE EDIT THE FOLLOWING TO CHANGE YOUR CONFIG:
* /etc/airtime/airtime.conf
* LIBRETIME_CONF_DIR/airtime.conf
*/
require_once __DIR__ . '/constants.php';
class Config {
private static $CC_CONFIG = null;
private static $rootDir;
@ -12,10 +14,6 @@ class Config {
self::$rootDir = __DIR__."/../..";
$CC_CONFIG = array(
/* ================================================ storage configuration */
'soundcloud-client-id' => '2CLCxcSXYzx7QhhPVHN4A',
'soundcloud-client-secret' => 'pZ7beWmF06epXLHVUP1ufOg2oEnIt9XhE8l8xt0bBs',
"rootDir" => self::$rootDir
);
@ -23,7 +21,7 @@ class Config {
if (getenv('AIRTIME_UNIT_TEST') == '1') {
$filename = "airtime.conf";
} else {
$filename = isset($_SERVER['AIRTIME_CONF']) ? $_SERVER['AIRTIME_CONF'] : "/etc/airtime/airtime.conf";
$filename = isset($_SERVER['AIRTIME_CONF']) ? $_SERVER['AIRTIME_CONF'] : LIBRETIME_CONF_DIR . "/airtime.conf";
}
$values = parse_ini_file($filename, true);
@ -51,11 +49,11 @@ class Config {
}
// Parse separate conf file for cloud storage values
$cloudStorageConfig = "/etc/airtime-saas/".$CC_CONFIG['dev_env']."/cloud_storage.conf";
$cloudStorageConfig = LIBRETIME_CONF_DIR . '/' . $CC_CONFIG['dev_env']."/cloud_storage.conf";
if (!file_exists($cloudStorageConfig)) {
// If the dev env specific cloud_storage.conf doesn't exist default
// to the production cloud_storage.conf
$cloudStorageConfig = "/etc/airtime-saas/production/cloud_storage.conf";
$cloudStorageConfig = LIBRETIME_CONF_DIR . "/production/cloud_storage.conf";
}
$cloudStorageValues = parse_ini_file($cloudStorageConfig, true);
@ -86,11 +84,11 @@ class Config {
$CC_CONFIG['soundcloud-connection-retries'] = $values['soundcloud']['connection_retries'];
$CC_CONFIG['soundcloud-connection-wait'] = $values['soundcloud']['time_between_retries'];
$globalAirtimeConfig = "/etc/airtime-saas/".$CC_CONFIG['dev_env']."/airtime.conf";
$globalAirtimeConfig = LIBRETIME_CONF_DIR . '/' . $CC_CONFIG['dev_env']."/airtime.conf";
if (!file_exists($globalAirtimeConfig)) {
// If the dev env specific airtime.conf doesn't exist default
// to the production airtime.conf
$globalAirtimeConfig = "/etc/airtime-saas/production/airtime.conf";
$globalAirtimeConfig = LIBRETIME_CONF_DIR . "/production/airtime.conf";
}
$globalAirtimeConfigValues = parse_ini_file($globalAirtimeConfig, true);
$CC_CONFIG['soundcloud-client-id'] = $globalAirtimeConfigValues['soundcloud']['soundcloud_client_id'];

View File

@ -36,6 +36,10 @@ define('AIRTIME_API_VERSION' , '1.1');
// XXX: it's important that we upgrade this every time we add an upgrade!
define('AIRTIME_CODE_VERSION' , '2.5.16');
// grab values from env (i'll do this everywhere with a small function if we like it)
define('LIBRETIME_CONF_DIR', getenv('LIBRETIME_CONF_DIR') ? getenv('LIBRETIME_CONF_DIR') : '/etc/airtime');
define('LIBRETIME_LOG_DIR', getenv('LIBRETIME_LOG_DIR') ? getenv('LIBRETIME_LOG_DIR') : '/var/log/airtime');
// Defaults
define('DEFAULT_LOGO_PLACEHOLDER', 1);
define('DEFAULT_LOGO_FILE', 'images/airtime_logo.png');

View File

@ -1,6 +1,4 @@
<?php
require_once('WidgetHelper.php');
require_once('TuneIn.php');
class ApiController extends Zend_Controller_Action
{
@ -11,8 +9,10 @@ class ApiController extends Zend_Controller_Action
public function init()
{
if ($this->view) { // skip if already missing (ie in tests)
$this->view->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
}
//Ignore API key and session authentication for these APIs:
$ignoreAuth = array("live-info",
@ -135,8 +135,7 @@ class ApiController extends Zend_Controller_Action
*/
public function pollCeleryAction() {
$taskManager = TaskManager::getInstance();
$clazz = version_compare(phpversion(), '5.5.0', '<') ? get_class(new CeleryTask) : CeleryTask::class;
$taskManager->runTask($clazz);
$taskManager->runTask('CeleryTask');
}
/**
@ -498,7 +497,7 @@ class ApiController extends Zend_Controller_Action
// Sometimes end users may be looking at stale data - if an image is removed
// but has been cached in a client's browser this will throw an exception
Application_Common_FileIO::smartReadFile($path, filesize($path), $mime_type);
} catch(FileNotFoundException $e) {
} catch(LibreTimeFileNotFoundException $e) {
//throw new ZendActionHttpException($this, 404, "ERROR: No image found at $path");
$this->_redirect('api/station-logo');
return;

View File

@ -1,6 +1,5 @@
<?php
require_once('Billing.php');
define('VAT_RATE', 19.00);
class BillingController extends Zend_Controller_Action {

View File

@ -1,7 +1,5 @@
<?php
require_once(__DIR__.'/../common/widgets/Table.php');
class DashboardController extends Zend_Controller_Action
{

View File

@ -1,5 +1,4 @@
<?php
require_once('WidgetHelper.php');
class EmbedController extends Zend_Controller_Action
{

View File

@ -1,9 +1,5 @@
<?php
require_once 'formatters/LengthFormatter.php';
require_once 'formatters/SamplerateFormatter.php';
require_once 'formatters/BitrateFormatter.php';
class LibraryController extends Zend_Controller_Action
{

View File

@ -1,8 +1,5 @@
<?php
require_once('WhmcsLoginController.php');
require_once('CORSHelper.php');
class LoginController extends Zend_Controller_Action
{
@ -168,13 +165,16 @@ class LoginController extends Zend_Controller_Action
if ($request->isPost()) {
if ($form->isValid($request->getPost())) {
$query = CcSubjsQuery::create();
if (empty($form->username->getValue())) {
$query->filterByDbEmail($form->email->getValue());
} else if (empty($form->email->getValue())) {
$query->filterByDbLogin($form->username->getValue());
$username = $form->userName->getValue();
$email = $form->email->getValue();
if (empty($username)) {
$query->filterByDbEmail($email);
} else if (empty($email)) {
$query->filterByDbLogin($username);
} else {
$query->filterByDbEmail($form->email->getValue())
->filterByDbLogin($form->username->getValue());
$query->filterByDbEmail($email)
->filterByDbLogin($username);
}
$user = $query->findOne();

View File

@ -1,7 +1,5 @@
<?php
require_once 'ProxyStorageBackend.php';
use Aws\S3\S3Client;
class ProvisioningController extends Zend_Controller_Action

View File

@ -1,8 +1,4 @@
<?php
require_once('TuneIn.php');
$filepath = realpath (dirname(__FILE__));
require_once($filepath."/../modules/rest/controllers/MediaController.php");
class ScheduleController extends Zend_Controller_Action
{

View File

@ -1,7 +1,5 @@
<?php
require_once('CORSHelper.php');
class ShowbuilderController extends Zend_Controller_Action
{

View File

@ -1,8 +1,5 @@
<?php
require_once "ThirdPartyController.php";
require_once "ise/php-soundcloud/src/Soundcloud/Service.php";
class SoundcloudController extends ThirdPartyController implements OAuth2Controller {
/**

View File

@ -1,7 +1,5 @@
<?php
require_once("Upgrades.php");
class UpgradeController extends Zend_Controller_Action
{
public function indexAction()

View File

@ -64,8 +64,7 @@ class PageLayoutInitPlugin extends Zend_Controller_Plugin_Abstract
// We can't afford to wait 7 minutes to run an upgrade: users could
// have several minutes of database errors while waiting for a
// schema change upgrade to happen after a deployment
$clazz = version_compare(phpversion(), '5.5.0', '<') ? get_class(new UpgradeTask) : UpgradeTask::class;
$taskManager->runTask($clazz);
$taskManager->runTask('UpgradeTask');
// Piggyback the TaskManager onto API calls. This provides guaranteed consistency
// (there is at least one API call made from pypo to Airtime every 7 minutes) and

View File

@ -1,5 +1,4 @@
<?php
require_once 'customvalidators/ConditionalNotEmpty.php';
class Application_Form_AddShowLiveStream extends Zend_Form_SubForm
{

View File

@ -1,7 +1,5 @@
<?php
require_once 'customfilters/ImageSize.php';
class Application_Form_AddShowStyle extends Zend_Form_SubForm
{

View File

@ -1,5 +1,4 @@
<?php
require_once( __DIR__ . '/../validate/NotDemoValidate.php');
class Application_Form_AddUser extends Zend_Form
{

View File

@ -1,5 +1,4 @@
<?php
require_once 'Zend/Locale.php';
class Application_Form_BillingClient extends Zend_Form
{

View File

@ -1,5 +1,4 @@
<?php
require_once( __DIR__ . '/../validate/NotDemoValidate.php');
class Application_Form_EditUser extends Zend_Form
{

View File

@ -1,6 +1,4 @@
<?php
require_once 'customfilters/ImageSize.php';
<?php
class Application_Form_GeneralPreferences extends Zend_Form_SubForm
{

View File

@ -1,7 +1,5 @@
<?php
require_once 'customfilters/ImageSize.php';
class Application_Form_RegisterAirtime extends Zend_Form
{

View File

@ -1,5 +1,4 @@
<?php
require_once 'customvalidators/ConditionalNotEmpty.php';
class Application_Form_SoundcloudPreferences extends Zend_Form_SubForm
{

View File

@ -1,5 +1,4 @@
<?php
require_once 'customvalidators/ConditionalNotEmpty.php';
class Application_Form_TuneInPreferences extends Zend_Form_SubForm
{

View File

@ -42,7 +42,6 @@ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
var schedulePreLoaded = <?php
//Awful hack to speed up loading - Embed the schedule in the response so that the dashboard
//doesn't have to make a separate AJAX request to get this data.
require_once("ScheduleController.php");
ScheduleController::printCurrentPlaylistForEmbedding();
?>;
//The DOM elements that these calls depend on exist by this point:

View File

@ -1,5 +1,4 @@
<?php
require_once('SentryLogging.php');
class Logging {

View File

@ -1,7 +1,5 @@
<?php
require_once 'formatters/LengthFormatter.php';
/**
*
* @package Airtime

View File

@ -1,7 +1,5 @@
<?php
require_once 'formatters/LengthFormatter.php';
/**
*
* @package Airtime

View File

@ -1,8 +1,5 @@
<?php
require_once 'StreamSetting.php';
require_once 'Cache.php';
class Application_Model_Preference
{

View File

@ -1,6 +1,4 @@
<?php
require_once 'php-amqplib/amqp.inc';
require_once 'massivescale/celery-php/celery.php';
class Application_Model_RabbitMq
{

View File

@ -1,8 +1,5 @@
<?php
require_once 'formatters/LengthFormatter.php';
require_once 'formatters/TimeFilledFormatter.php';
class Application_Model_ShowBuilder
{
private $timezone;

View File

@ -1,7 +1,5 @@
<?php
require_once 'formatters/LengthFormatter.php';
class Application_Model_ShowInstance
{
private $_instanceId;

View File

@ -1,9 +1,5 @@
<?php
require_once 'formatters/LengthFormatter.php';
require_once 'formatters/SamplerateFormatter.php';
require_once 'formatters/BitrateFormatter.php';
/**
* Application_Model_StoredFile class
*

View File

@ -16,7 +16,7 @@ class InvalidMetadataException extends Exception
{
}
class FileNotFoundException extends Exception
class LibreTimeFileNotFoundException extends Exception
{
}
@ -67,7 +67,7 @@ class CcFiles extends BaseCcFiles {
if ($file) {
return CcFiles::sanitizeResponse($file);
} else {
throw new FileNotFoundException();
throw new LibreTimeFileNotFoundException();
}
}
@ -174,7 +174,7 @@ class CcFiles extends BaseCcFiles {
* @param $fileArray array An associative array containing metadata. Replaces those fields if they exist.
* @return array A sanitized version of the file metadata array.
* @throws Exception
* @throws FileNotFoundException
* @throws LibreTimeFileNotFoundException
* @throws PropelException
*/
public static function updateFromArray($fileId, $fileArray)
@ -196,7 +196,7 @@ class CcFiles extends BaseCcFiles {
$fileSizeBytes = $fileArray["filesize"];
if (!isset($fileSizeBytes) || $fileSizeBytes === false) {
throw new FileNotFoundException("Invalid filesize for $fileId");
throw new LibreTimeFileNotFoundException("Invalid filesize for $fileId");
}
$cloudFile = new CloudFile();
@ -219,7 +219,7 @@ class CcFiles extends BaseCcFiles {
if (isset($fileArray["full_path"])) {
$fileSizeBytes = filesize($fileArray["full_path"]);
if (!isset($fileSizeBytes) || $fileSizeBytes === false) {
throw new FileNotFoundException("Invalid filesize for $fileId");
throw new LibreTimeFileNotFoundException("Invalid filesize for $fileId");
}
Application_Model_Preference::updateDiskUsage($fileSizeBytes);
@ -235,14 +235,14 @@ class CcFiles extends BaseCcFiles {
}
}
} else {
throw new FileNotFoundException();
throw new LibreTimeFileNotFoundException();
}
$now = new DateTime("now", new DateTimeZone("UTC"));
$file->setDbMtime($now);
$file->save();
}
catch (FileNotFoundException $e)
catch (LibreTimeFileNotFoundException $e)
{
$file->setDbImportStatus(self::IMPORT_STATUS_FAILED);
$file->setDbHidden(true);
@ -258,7 +258,7 @@ class CcFiles extends BaseCcFiles {
* @throws DeleteScheduledFileException
* @throws Exception
* @throws FileNoPermissionException
* @throws FileNotFoundException
* @throws LibreTimeFileNotFoundException
* @throws PropelException
*/
public static function deleteById($id)
@ -269,7 +269,7 @@ class CcFiles extends BaseCcFiles {
$storedFile = Application_Model_StoredFile::RecallById($id, $con);
$storedFile->delete();
} else {
throw new FileNotFoundException();
throw new LibreTimeFileNotFoundException();
}
}

View File

@ -1,7 +1,5 @@
<?php
require_once 'ProxyStorageBackend.php';
/**
* Skeleton subclass for representing a row from the 'cloud_file' table.
*

View File

@ -3,11 +3,6 @@ set_include_path(get_include_path() . PATH_SEPARATOR . $path);
$WHITE_SCREEN_OF_DEATH = false;
require_once(dirname(__FILE__).'/../../configs/conf.php');
require_once('PHPUnit.php');
require_once 'StoredFileTests.php';
require_once 'SchedulerTests.php';
//require_once 'SchedulerExportTests.php';
require_once 'PlaylistTests.php';
//$suite = new PHPUnit_TestSuite("PlayListTests");
//$suite = new PHPUnit_TestSuite("SchedulerTests");

View File

@ -1,7 +1,5 @@
<?php
require_once(dirname(__FILE__)."/../Schedule.php");
class SchedulerExportTests extends PHPUnit_TestCase {
function setup() {
global $CC_CONFIG;

View File

@ -1,5 +1,4 @@
<?php
require_once(dirname(__FILE__)."/../Schedule.php");
class SchedulerTests extends PHPUnit_TestCase {

View File

@ -1,5 +1,4 @@
<?php
require_once(dirname(__FILE__).'/../StoredFile.php');
class StoredFileTest extends PHPUnit_TestCase {

View File

@ -1,25 +0,0 @@
<?php
require_once(__DIR__.'/../../3rd_party/php/propel/runtime/lib/Propel.php');
// Initialize Propel with the runtime configuration
//Example how to use PDO:
//Propel::init(__DIR__."/../propel-db/build/conf/airtime-conf.php");
//Add the generated 'classes' directory to the include path
set_include_path(__DIR__."/../propel-db/build/classes" . PATH_SEPARATOR . get_include_path());
$con = Propel::getConnection("campcaster");
$sql = "SELECT COUNT(*) FROM cc_schedule WHERE (starts >= '2010-01-01 00:00:00.000') "
." AND (ends <= (TIMESTAMP '2011-01-01 00:00:00.000' + INTERVAL '01:00:00.123456'))";
$rows1 = $con->query($sql);
var_dump($rows1->fetchAll());
$sql2 = "SELECT COUNT(*) FROM cc_playlistcontents";
$rows2 = $con->query($sql2);
var_dump($rows2->fetchAll());
$sql3 = "SELECT TIMESTAMP '2011-01-01 00:00:00.000' + INTERVAL '01:00:00.123456'";
$result3 = $con->query($sql3);
var_dump($result3->fetchAll());

View File

@ -1,7 +1,5 @@
<?php
require_once 'RouteController.php';
class Rest_Bootstrap extends Zend_Application_Module_Bootstrap
{
protected function _initRouter()

View File

@ -1,7 +1,5 @@
<?php
require_once 'ProxyStorageBackend.php';
class Rest_MediaController extends Zend_Rest_Controller
{
public function init()
@ -12,6 +10,16 @@ class Rest_MediaController extends Zend_Rest_Controller
$this->_helper->viewRenderer->setNoRender(true);
}
/**
* headAction is needed as it is defined as an abstract function in the base controller
*
* @return void
*/
public function headAction()
{
Logging::info("HEAD action received");
}
public function indexAction()
{
$totalFileCount = CcFilesQuery::create()->count();
@ -76,7 +84,7 @@ class Rest_MediaController extends Zend_Rest_Controller
}
Application_Service_MediaService::streamFileDownload($id, $inline);
}
catch (FileNotFoundException $e) {
catch (LibreTimeFileNotFoundException $e) {
$this->fileNotFoundResponse();
Logging::error($e->getMessage());
}
@ -99,7 +107,7 @@ class Rest_MediaController extends Zend_Rest_Controller
->setHttpResponseCode(200)
->appendBody(json_encode(CcFiles::getSanitizedFileById($id)));
}
catch (FileNotFoundException $e) {
catch (LibreTimeFileNotFoundException $e) {
$this->fileNotFoundResponse();
Logging::error($e->getMessage());
}
@ -160,7 +168,7 @@ class Rest_MediaController extends Zend_Rest_Controller
$this->invalidDataResponse();
Logging::error($e->getMessage());
}
catch (FileNotFoundException $e) {
catch (LibreTimeFileNotFoundException $e) {
$this->fileNotFoundResponse();
Logging::error($e->getMessage());
}
@ -181,7 +189,7 @@ class Rest_MediaController extends Zend_Rest_Controller
$this->getResponse()
->setHttpResponseCode(204);
}
catch (FileNotFoundException $e) {
catch (LibreTimeFileNotFoundException $e) {
$this->fileNotFoundResponse();
Logging::error($e->getMessage());
}

View File

@ -1,7 +1,5 @@
<?php
require_once('PodcastFactory.php');
class Rest_PodcastController extends Zend_Rest_Controller
{
@ -14,6 +12,16 @@ class Rest_PodcastController extends Zend_Rest_Controller
$this->view->setScriptPath(APPLICATION_PATH . 'views/scripts/');
}
/**
* headAction is needed as it is defined as an abstract function in the base controller
*
* @return void
*/
public function headAction()
{
Logging::info("HEAD action received");
}
public function indexAction()
{
// Check if offset and limit were sent with request.

View File

@ -17,6 +17,16 @@ class Rest_PodcastEpisodesController extends Zend_Rest_Controller
$this->_service = new Application_Service_PodcastEpisodeService();
}
/**
* headAction is needed as it is defined as an abstract function in the base controller
*
* @return void
*/
public function headAction()
{
Logging::info("HEAD action received");
}
public function indexAction()
{
// podcast ID

View File

@ -12,9 +12,6 @@
* @version 1.2.1
*/
$filepath = realpath(__DIR__);
require_once($filepath . "/../helpers/RestAuth.php");
class Rest_ShowImageController extends Zend_Rest_Controller {
public function init() {
@ -24,6 +21,16 @@ class Rest_ShowImageController extends Zend_Rest_Controller {
$this->_helper->viewRenderer->setNoRender(true);
}
/**
* headAction is needed as it is defined as an abstract function in the base controller
*
* @return void
*/
public function headAction()
{
Logging::info("HEAD action received");
}
public function indexAction() {
Logging::info("INDEX action received");
}

View File

@ -1,7 +1,5 @@
<?php
require_once 'formatters/LengthFormatter.php';
class Application_Service_HistoryService
{
private $con;

View File

@ -1,8 +1,5 @@
<?php
require_once('ProxyStorageBackend.php');
require_once("FileIO.php");
class Application_Service_MediaService
{
@ -56,13 +53,13 @@ class Application_Service_MediaService
* @param $fileId
* @param bool $inline Set the Content-Disposition header to inline to prevent a download dialog from popping up (or attachment if false)
* @throws Exception
* @throws FileNotFoundException
* @throws LibreTimeFileNotFoundException
*/
public static function streamFileDownload($fileId, $inline=false)
{
$media = Application_Model_StoredFile::RecallById($fileId);
if ($media == null) {
throw new FileNotFoundException();
throw new LibreTimeFileNotFoundException();
}
// Make sure we don't have some wrong result because of caching
clearstatcache();
@ -104,7 +101,7 @@ class Application_Service_MediaService
$mimeType = $media->getPropelOrm()->getDbMime();
Application_Common_FileIO::smartReadFile($filePath, $size, $mimeType);
break; //Break out of the loop if we successfully read the file!
} catch (FileNotFoundException $e) {
} catch (LibreTimeFileNotFoundException $e) {
//If we have no alternate filepaths left, then let the exception bubble up.
if (sizeof($filePaths) == 0) {
throw $e;
@ -116,7 +113,7 @@ class Application_Service_MediaService
exit;
} else {
throw new FileNotFoundException($filePath);
throw new LibreTimeFileNotFoundException($filePath);
}
}

View File

@ -354,7 +354,7 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir
*
* @return array array of episode data
*
* @throws CcFiles/FileNotFoundException
* @throws CcFiles/LibreTimeFileNotFoundException
*/
public function _getImportedPodcastEpisodeArray($podcast, $episodes) {
$rss = Application_Service_PodcastService::getPodcastFeed($podcast->getDbUrl());

View File

@ -72,9 +72,13 @@ class Application_Service_PodcastService
//TODO: why is this so slow?
$rss = self::getPodcastFeed($feedUrl);
if (!$rss || !empty($rss->error())) {
if (!$rss) {
throw new InvalidPodcastException();
}
$rssErr = $rss->error();
if (!empty($rssErr)) {
throw new InvalidPodcastException($rssErr);
}
// Ensure we are only creating Podcast with the given URL, and excluding
// any extra data fields that may have been POSTED
@ -87,7 +91,8 @@ class Application_Service_PodcastService
$podcastArray["language"] = htmlspecialchars($rss->get_language());
$podcastArray["copyright"] = htmlspecialchars($rss->get_copyright());
$name = empty($rss->get_author()) ? "" : $rss->get_author()->get_name();
$rssAuthor = $rss->getAuthor();
$name = empty($rssAuthor) ? "" : $rss->rssAuthor->get_name();
$podcastArray["creator"] = htmlspecialchars($name);
$categories = array();

View File

@ -1,7 +1,5 @@
<?php
require_once "ThirdPartyCeleryService.php";
/**
* Service object for dealing with SoundCloud authorization and background tasks
*

View File

@ -1,7 +1,5 @@
<?php
require_once "ThirdPartyService.php";
abstract class Application_Service_ThirdPartyCeleryService extends Application_Service_ThirdPartyService {
/**

View File

@ -1,7 +1,6 @@
<?php
define("RMQ_INI_SECTION", "rabbitmq");
require_once dirname(dirname( __DIR__)) . '/library/php-amqplib/amqp.inc';
function booleanReduce($a, $b) {
return $a && $b;

View File

@ -1,485 +0,0 @@
<?php
/**
* ZFDebug Zend Additions
*
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
* @version $Id$
*/
/**
* @see Zend_Controller_Exception
*/
require_once 'Zend/Controller/Exception.php';
/**
* @see Zend_Version
*/
require_once 'Zend/Version.php';
/**
* @see ZFDebug_Controller_Plugin_Debug_Plugin_Text
*/
require_once 'ZFDebug/Controller/Plugin/Debug/Plugin/Text.php';
/**
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
*/
class ZFDebug_Controller_Plugin_Debug extends Zend_Controller_Plugin_Abstract
{
/**
* Contains registered plugins
*
* @var array
*/
protected $_plugins = array();
/**
* Contains options to change Debug Bar behavior
*/
protected $_options = array(
'plugins' => array(
'Variables' => null,
'Time' => null,
'Memory' => null),
'z-index' => 255,
'jquery_path' => 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js',
'image_path' => null
);
/**
* Standard plugins
*
* @var array
*/
public static $standardPlugins = array('Cache', 'Html', 'Database', 'Exception', 'File', 'Memory', 'Registry', 'Time', 'Variables');
/**
* Debug Bar Version Number
* for internal use only
*
* @var string
*/
protected $_version = '1.5.4';
/**
* Creates a new instance of the Debug Bar
*
* @param array|Zend_Config $options
* @throws Zend_Controller_Exception
* @return void
*/
protected $_closingBracket = null;
public function __construct($options = null)
{
if (isset($options)) {
if ($options instanceof Zend_Config) {
$options = $options->toArray();
}
/*
* Verify that adapter parameters are in an array.
*/
if (!is_array($options)) {
throw new Zend_Exception('Debug parameters must be in an array or a Zend_Config object');
}
$this->setOptions($options);
}
/**
* Creating ZF Version Tab always shown
*/
$version = new ZFDebug_Controller_Plugin_Debug_Plugin_Text();
$version->setPanel($this->_getVersionPanel())
->setTab($this->_getVersionTab())
->setIdentifier('copyright')
->setIconData('data:image/gif;base64,R0lGODlhEAAQAPcAAPb7/ef2+VepAGKzAIC8SavSiYS9Stvt0uTx4fX6+ur1632+QMLgrGOuApDIZO738drs0Ofz5t7v2MfjtPP6+t7v12SzAcvnyX2+PaPRhH2+Qmy3H3K5LPP6+cXkwIHAR2+4JHi7NePz8YC/Rc3ozfH49XK5KXq9OrzdpNzu1YrEUqrVkdzw5uTw4d/v2dDow5zOeO3279Hq0m+4JqrUhpnMbeHw3N3w6Mflwm22HmazBODy7tfu3un06r7gsuXy4sTisIzGXvH59ny9PdPr1rXZpMzlu36/Q5bLb+Pw3tDnxNHr1Lfbm+b199/x62q1Fp3NcdjszqTPh/L599vt04/GWmazCPb7/LHZnW63I3W6MXa7MmGuAt/y7Gq1E2m0Eb7cp9frzZLJaO/489bu3HW3N7rerN/v2q7WjIjEVuLx343FVrDXj9nt0cTjvW2zIoPBSNjv4OT09IXDUpvLeeHw3dPqyNLpxs/nwHe8OIvFWrPaoGe0C5zMb83mvHm8Oen06a3Xl9XqyoC/Qr/htWe0DofDU4nFWbPYk7ndqZ/PfYPBTMPhrqHRgoLBSujz55PKadHpxfX6+6LNeqPQfNXt2pPIYH2+O7vcoHi4OOf2+PL5+NTs2N3u1mi1E7XZl4zEVJjLaZHGauby5KTShmSzBO/38s/oz3i7MtbrzMHiuYTCT4fDTtXqye327uDv3JDHXu328JnMcu738LLanvD49ZTJYpPKauX19tvv44jBWo7GWpfKZ+Dv27XcpcrluXu8ONTs16zXleT08qfUjKzUlc7pzm63HaTRfZXKZuj06HG4KavViGe0EcDfqcjmxaDQgZrNdOHz77/ep4/HYL3esnW6LobCS3S5K57OctDp0JXKbez17N7x6cbkwLTZlbXXmLrcnrvdodHr06PQe8jkt5jIa93v13m8OI7CW3O6L3a7Nb7gs6nUjmu2GqjTgZjKaKLQeZnMc4LAReL08rTbopbLbuTx4KDOdtbry7DYmrvfrrPaoXK5K5zOegAAACH5BAEAAAAALAAAAAAQABAAAAhMAAEIHEiwoMGDCBMOlCKgoUMuHghInEiggEOHAC5eJNhQ4UAuAjwIJLCR4AEBDQS2uHiAYLGOHjNqlCmgYAONApQ0jBGzp8+fQH8GBAA7');
$this->registerPlugin($version);
/**
* Loading aready defined plugins
*/
$this->_loadPlugins();
}
/**
* Sets options of the Debug Bar
*
* @param array $options
* @return ZFDebug_Controller_Plugin_Debug
*/
public function setOptions(array $options = array())
{
if (isset($options['jquery_path'])) {
$this->_options['jquery_path'] = $options['jquery_path'];
}
if (isset($options['z-index'])) {
$this->_options['z-index'] = $options['z-index'];
}
if (isset($options['image_path'])) {
$this->_options['image_path'] = $options['image_path'];
}
if (isset($options['plugins'])) {
$this->_options['plugins'] = $options['plugins'];
}
return $this;
}
/**
* Register a new plugin in the Debug Bar
*
* @param ZFDebug_Controller_Plugin_Debug_Plugin_Interface
* @return ZFDebug_Controller_Plugin_Debug
*/
public function registerPlugin(ZFDebug_Controller_Plugin_Debug_Plugin_Interface $plugin)
{
$this->_plugins[$plugin->getIdentifier()] = $plugin;
return $this;
}
/**
* Unregister a plugin in the Debug Bar
*
* @param string $plugin
* @return ZFDebug_Controller_Plugin_Debug
*/
public function unregisterPlugin($plugin)
{
if (false !== strpos($plugin, '_')) {
foreach ($this->_plugins as $key => $_plugin) {
if ($plugin == get_class($_plugin)) {
unset($this->_plugins[$key]);
}
}
} else {
$plugin = strtolower($plugin);
if (isset($this->_plugins[$plugin])) {
unset($this->_plugins[$plugin]);
}
}
return $this;
}
/**
* Get a registered plugin in the Debug Bar
*
* @param string $identifier
* @return ZFDebug_Controller_Plugin_Debug_Plugin_Interface
*/
public function getPlugin($identifier)
{
$identifier = strtolower($identifier);
if (isset($this->_plugins[$identifier])) {
return $this->_plugins[$identifier];
}
return false;
}
/**
* Defined by Zend_Controller_Plugin_Abstract
*/
public function dispatchLoopShutdown()
{
if ($this->getRequest()->isXmlHttpRequest()) {
return;
}
$disable = Zend_Controller_Front::getInstance()->getRequest()->getParam('ZFDEBUG_DISABLE');
if (isset($disable)) {
return;
}
$html = '';
/**
* Creating menu tab for all registered plugins
*/
foreach ($this->_plugins as $plugin)
{
$panel = $plugin->getPanel();
if ($panel == '') {
continue;
}
/* @var $plugin ZFDebug_Controller_Plugin_Debug_Plugin_Interface */
$html .= '<div id="ZFDebug_' . $plugin->getIdentifier()
. '" class="ZFDebug_panel">' . $panel . '</div>';
}
$html .= '<div id="ZFDebug_info">';
/**
* Creating panel content for all registered plugins
*/
foreach ($this->_plugins as $plugin)
{
$tab = $plugin->getTab();
if ($tab == '') {
continue;
}
if (null !== $this->_options['image_path'] && file_exists($this->_options['image_path'] .'/'. $plugin->getIdentifier() .'.png')) {
$plugin_icon = $this->_options['image_path'] .'/'. $plugin->getIdentifier() .'.png';
} else {
$plugin_icon = $plugin->getIconData();
}
/* @var $plugin ZFDebug_Controller_Plugin_Debug_Plugin_Interface */
$html .= '<span class="ZFDebug_span clickable" onclick="ZFDebugPanel(\'ZFDebug_' . $plugin->getIdentifier() . '\');">';
$html .= '<img src="' . $plugin_icon . '" style="vertical-align:middle" alt="' . $plugin->getIdentifier() . '" title="' . $plugin->getIdentifier() . '"'. $this->getClosingBracket() .' ';
$html .= $tab . '</span>';
}
$html .= '<span class="ZFDebug_span ZFDebug_last clickable" id="ZFDebug_toggler" onclick="ZFDebugSlideBar()">&#171;</span>';
$html .= '</div>';
$this->_output($html);
}
### INTERNAL METHODS BELOW ###
/**
* Load plugins set in config option
*
* @return void;
*/
protected function _loadPlugins()
{
foreach($this->_options['plugins'] as $plugin => $options) {
if (is_numeric($plugin)) {
# Plugin passed as array value instead of key
$plugin = $options;
$options = array();
}
// Register an instance
if (is_object($plugin) && in_array('ZFDebug_Controller_Plugin_Debug_Plugin_Interface', class_implements($plugin))) {
$this->registerPlugin($plugin);
continue;
}
if (!is_string($plugin)) {
throw new Exception("Invalid plugin name", 1);
}
$plugin = ucfirst($plugin);
// Register a classname
if (in_array($plugin, ZFDebug_Controller_Plugin_Debug::$standardPlugins)) {
// standard plugin
$pluginClass = 'ZFDebug_Controller_Plugin_Debug_Plugin_' . $plugin;
} else {
// we use a custom plugin
if (!preg_match('~^[\w]+$~D', $plugin)) {
throw new Zend_Exception("ZFDebug: Invalid plugin name [$plugin]");
}
$pluginClass = $plugin;
}
require_once str_replace('_', DIRECTORY_SEPARATOR, $pluginClass) . '.php';
$object = new $pluginClass($options);
$this->registerPlugin($object);
}
}
/**
* Return version tab
*
* @return string
*/
protected function _getVersionTab()
{
return ' ' . Zend_Version::VERSION . '/'.phpversion();
}
/**
* Returns version panel
*
* @return string
*/
protected function _getVersionPanel()
{
$panel = '<h4>ZFDebug v'.$this->_version.'</h4>' .
'<p>©2008-2009 <a href="http://jokke.dk">Joakim Nygård</a> &amp; <a href="http://www.bangal.de">Andreas Pankratz</a></p>' .
'<p>The project is hosted at <a href="http://code.google.com/p/zfdebug/">http://zfdebug.googlecode.com</a> and released under the BSD License' . $this->getLinebreak() .
'Includes images from the <a href="http://www.famfamfam.com/lab/icons/silk/">Silk Icon set</a> by Mark James</p>'.
'<p>Disable ZFDebug temporarily by sending ZFDEBUG_DISABLE as a GET/POST parameter</p>';
// $panel .= '<h4>Zend Framework '.Zend_Version::VERSION.' / PHP '.phpversion().' with extensions:</h4>';
// $extensions = get_loaded_extensions();
// natcasesort($extensions);
// $panel .= implode('<br>', $extensions);
return $panel;
}
/**
* Returns path to the specific icon
*
* @return string
*/
protected function _icon($kind)
{
switch ($kind) {
case 'database':
if (null === $this->_options['image_path'])
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAEYSURBVBgZBcHPio5hGAfg6/2+R980k6wmJgsJ5U/ZOAqbSc2GnXOwUg7BESgLUeIQ1GSjLFnMwsKGGg1qxJRmPM97/1zXFAAAAEADdlfZzr26miup2svnelq7d2aYgt3rebl585wN6+K3I1/9fJe7O/uIePP2SypJkiRJ0vMhr55FLCA3zgIAOK9uQ4MS361ZOSX+OrTvkgINSjS/HIvhjxNNFGgQsbSmabohKDNoUGLohsls6BaiQIMSs2FYmnXdUsygQYmumy3Nhi6igwalDEOJEjPKP7CA2aFNK8Bkyy3fdNCg7r9/fW3jgpVJbDmy5+PB2IYp4MXFelQ7izPrhkPHB+P5/PjhD5gCgCenx+VR/dODEwD+A3T7nqbxwf1HAAAAAElFTkSuQmCC';
return $this->_options['image_path'] . '/database.png';
break;
case 'exception':
if (null === $this->_options['image_path'])
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAJPSURBVDjLpZPLS5RhFMYfv9QJlelTQZwRb2OKlKuINuHGLlBEBEOLxAu46oL0F0QQFdWizUCrWnjBaDHgThCMoiKkhUONTqmjmDp2GZ0UnWbmfc/ztrC+GbM2dXbv4ZzfeQ7vefKMMfifyP89IbevNNCYdkN2kawkCZKfSPZTOGTf6Y/m1uflKlC3LvsNTWArr9BT2LAf+W73dn5jHclIBFZyfYWU3or7T4K7AJmbl/yG7EtX1BQXNTVCYgtgbAEAYHlqYHlrsTEVQWr63RZFuqsfDAcdQPrGRR/JF5nKGm9xUxMyr0YBAEXXHgIANq/3ADQobD2J9fAkNiMTMSFb9z8ambMAQER3JC1XttkYGGZXoyZEGyTHRuBuPgBTUu7VSnUAgAUAWutOV2MjZGkehgYUA6O5A0AlkAyRnotiX3MLlFKduYCqAtuGXpyH0XQmOj+TIURt51OzURTYZdBKV2UBSsOIcRp/TVTT4ewK6idECAihtUKOArWcjq/B8tQ6UkUR31+OYXP4sTOdisivrkMyHodWejlXwcC38Fvs8dY5xaIId89VlJy7ACpCNCFCuOp8+BJ6A631gANQSg1mVmOxxGQYRW2nHMha4B5WA3chsv22T5/B13AIicWZmNZ6cMchTXUe81Okzz54pLi0uQWp+TmkZqMwxsBV74Or3od4OISPr0e3SHa3PX0f3HXKofNH/UIG9pZ5PeUth+CyS2EMkEqs4fPEOBJLsyske48/+xD8oxcAYPzs4QaS7RR2kbLTTOTQieczfzfTv8QPldGvTGoF6/8AAAAASUVORK5CYII=';
return $this->_options['image_path'] . '/exception.png';
break;
case 'error':
if (null === $this->_options['image_path'])
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAIsSURBVDjLpVNLSJQBEP7+h6uu62vLVAJDW1KQTMrINQ1vPQzq1GOpa9EppGOHLh0kCEKL7JBEhVCHihAsESyJiE4FWShGRmauu7KYiv6Pma+DGoFrBQ7MzGFmPr5vmDFIYj1mr1WYfrHPovA9VVOqbC7e/1rS9ZlrAVDYHig5WB0oPtBI0TNrUiC5yhP9jeF4X8NPcWfopoY48XT39PjjXeF0vWkZqOjd7LJYrmGasHPCCJbHwhS9/F8M4s8baid764Xi0Ilfp5voorpJfn2wwx/r3l77TwZUvR+qajXVn8PnvocYfXYH6k2ioOaCpaIdf11ivDcayyiMVudsOYqFb60gARJYHG9DbqQFmSVNjaO3K2NpAeK90ZCqtgcrjkP9aUCXp0moetDFEeRXnYCKXhm+uTW0CkBFu4JlxzZkFlbASz4CQGQVBFeEwZm8geyiMuRVntzsL3oXV+YMkvjRsydC1U+lhwZsWXgHb+oWVAEzIwvzyVlk5igsi7DymmHlHsFQR50rjl+981Jy1Fw6Gu0ObTtnU+cgs28AKgDiy+Awpj5OACBAhZ/qh2HOo6i+NeA73jUAML4/qWux8mt6NjW1w599CS9xb0mSEqQBEDAtwqALUmBaG5FV3oYPnTHMjAwetlWksyByaukxQg2wQ9FlccaK/OXA3/uAEUDp3rNIDQ1ctSk6kHh1/jRFoaL4M4snEMeD73gQx4M4PsT1IZ5AfYH68tZY7zv/ApRMY9mnuVMvAAAAAElFTkSuQmCC';
return $this->_options['image_path'] . '/error.png';
break;
default:
if (null === $this->_options['image_path'])
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAHhSURBVDjLpZI9SJVxFMZ/r2YFflw/kcQsiJt5b1ije0tDtbQ3GtFQYwVNFbQ1ujRFa1MUJKQ4VhYqd7K4gopK3UIly+57nnMaXjHjqotnOfDnnOd/nt85SURwkDi02+ODqbsldxUlD0mvHw09ubSXQF1t8512nGJ/Uz/5lnxi0tB+E9QI3D//+EfVqhtppGxUNzCzmf0Ekojg4fS9cBeSoyzHQNuZxNyYXp5ZM5Mk1ZkZT688b6thIBenG/N4OB5B4InciYBCVyGnEBHO+/LH3SFKQuF4OEs/51ndXMXC8Ajqknrcg1O5PGa2h4CJUqVES0OO7sYevv2qoFBmJ/4gF4boaOrg6rPLYWaYiVfDo0my8w5uj12PQleB0vcp5I6HsHAUoqUhR29zH+5B4IxNTvDmxljy3x2YCYUwZVlbzXJh9UKeQY6t2m0Lt94Oh5loPdqK3EkjzZi4MM/Y9Db3MTv/mYWVxaqkw9IOATNR7B5ABHPrZQrtg9sb8XDKa1+QOwsri4zeHD9SAzE1wxBTXz9xtvMc5ZU5lirLSKIz18nJnhOZjb22YKkhd4odg5icpcoyL669TAAujlyIvmPHSWXY1ti1AmZ8mJ3ElP1ips1/YM3H300g+W+51nc95YPEX8fEbdA2ReVYAAAAAElFTkSuQmCC';
return $this->_options['image_path'] . '/unknown.png';
break;
}
}
/**
* Returns html header for the Debug Bar
*
* @return string
*/
protected function _headerOutput() {
$collapsed = isset($_COOKIE['ZFDebugCollapsed']) ? $_COOKIE['ZFDebugCollapsed'] : 0;
return ('
<style type="text/css" media="screen">
#ZFDebug_debug { font: 11px/1.4em Lucida Grande, Lucida Sans Unicode, sans-serif; position:fixed; bottom:5px; left:5px; color:#000; z-index: ' . $this->_options['z-index'] . ';}
#ZFDebug_debug ol {margin:10px 0px; padding:0 25px}
#ZFDebug_debug li {margin:0 0 10px 0;}
#ZFDebug_debug .clickable {cursor:pointer}
#ZFDebug_toggler { font-weight:bold; background:#BFBFBF; }
.ZFDebug_span { border: 1px solid #999; border-right:0px; background:#DFDFDF; padding: 5px 5px; }
.ZFDebug_last { border: 1px solid #999; }
.ZFDebug_panel { text-align:left; position:absolute;bottom:21px;width:800px; max-height:400px; overflow:auto; display:none; background:#E8E8E8; padding:5px; border: 1px solid #999; }
.ZFDebug_panel .pre {font: 11px/1.4em Monaco, Lucida Console, monospace; margin:0 0 0 22px}
#ZFDebug_exception { border:1px solid #CD0A0A;display: block; }
</style>
<script type="text/javascript">
if (typeof jQuery == "undefined") {
var scriptObj = document.createElement("script");
scriptObj.src = "'.$this->_options['jquery_path'].'";
scriptObj.type = "text/javascript";
var head=document.getElementsByTagName("head")[0];
head.insertBefore(scriptObj,head.firstChild);
jQuery.noConflict();
}
var ZFDebugLoad = window.onload;
window.onload = function(){
if (ZFDebugLoad) {
ZFDebugLoad();
}
ZFDebugCollapsed();
};
function ZFDebugCollapsed() {
if ('.$collapsed.' == 1) {
ZFDebugPanel();
jQuery("#ZFDebug_toggler").html("&#187;");
return jQuery("#ZFDebug_debug").css("left", "-"+parseInt(jQuery("#ZFDebug_debug").outerWidth()-jQuery("#ZFDebug_toggler").outerWidth()+1)+"px");
}
}
function ZFDebugPanel(name) {
jQuery(".ZFDebug_panel").each(function(i){
if(jQuery(this).css("display") == "block") {
jQuery(this).slideUp();
} else {
if (jQuery(this).attr("id") == name)
jQuery(this).slideDown();
else
jQuery(this).slideUp();
}
});
}
function ZFDebugSlideBar() {
if (jQuery("#ZFDebug_debug").position().left > 0) {
document.cookie = "ZFDebugCollapsed=1;expires=;path=/";
ZFDebugPanel();
jQuery("#ZFDebug_toggler").html("&#187;");
return jQuery("#ZFDebug_debug").animate({left:"-"+parseInt(jQuery("#ZFDebug_debug").outerWidth()-jQuery("#ZFDebug_toggler").outerWidth()+1)+"px"}, "normal", "swing");
} else {
document.cookie = "ZFDebugCollapsed=0;expires=;path=/";
jQuery("#ZFDebug_toggler").html("&#171;");
return jQuery("#ZFDebug_debug").animate({left:"5px"}, "normal", "swing");
}
}
function ZFDebugToggleElement(name, whenHidden, whenVisible){
if(jQuery(name).css("display")=="none"){
jQuery(whenVisible).show();
jQuery(whenHidden).hide();
} else {
jQuery(whenVisible).hide();
jQuery(whenHidden).show();
}
jQuery(name).slideToggle();
}
</script>');
}
/**
* Appends Debug Bar html output to the original page
*
* @param string $html
* @return void
*/
protected function _output($html)
{
$response = $this->getResponse();
$response->setBody(preg_replace('/(<\/head>)/i', $this->_headerOutput() . '$1', $response->getBody()));
$response->setBody(str_ireplace('</body>', '<div id="ZFDebug_debug">'.$html.'</div></body>', $response->getBody()));
}
public function getLinebreak()
{
return '<br'.$this->getClosingBracket();
}
public function getClosingBracket()
{
if (!$this->_closingBracket) {
if ($this->_isXhtml()) {
$this->_closingBracket = ' />';
} else {
$this->_closingBracket = '>';
}
}
return $this->_closingBracket;
}
protected function _isXhtml()
{
if ($view = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view) {
$doctype = $view->doctype();
return $doctype->isXhtml();
}
return false;
}
}

View File

@ -1,92 +0,0 @@
<?php
/**
* ZFDebug Zend Additions
*
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
* @version $Id: $
*/
/**
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
*/
class ZFDebug_Controller_Plugin_Debug_Plugin
{
protected $_closingBracket = null;
public function getLinebreak()
{
return '<br'.$this->getClosingBracket();
}
public function getIconData()
{
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAHhSURBVDjLpZI9SJVxFMZ/r2YFflw/kcQsiJt5b1ije0tDtbQ3GtFQYwVNFbQ1ujRFa1MUJKQ4VhYqd7K4gopK3UIly+57nnMaXjHjqotnOfDnnOd/nt85SURwkDi02+ODqbsldxUlD0mvHw09ubSXQF1t8512nGJ/Uz/5lnxi0tB+E9QI3D//+EfVqhtppGxUNzCzmf0Ekojg4fS9cBeSoyzHQNuZxNyYXp5ZM5Mk1ZkZT688b6thIBenG/N4OB5B4InciYBCVyGnEBHO+/LH3SFKQuF4OEs/51ndXMXC8Ajqknrcg1O5PGa2h4CJUqVES0OO7sYevv2qoFBmJ/4gF4boaOrg6rPLYWaYiVfDo0my8w5uj12PQleB0vcp5I6HsHAUoqUhR29zH+5B4IxNTvDmxljy3x2YCYUwZVlbzXJh9UKeQY6t2m0Lt94Oh5loPdqK3EkjzZi4MM/Y9Db3MTv/mYWVxaqkw9IOATNR7B5ABHPrZQrtg9sb8XDKa1+QOwsri4zeHD9SAzE1wxBTXz9xtvMc5ZU5lirLSKIz18nJnhOZjb22YKkhd4odg5icpcoyL669TAAujlyIvmPHSWXY1ti1AmZ8mJ3ElP1ips1/YM3H300g+W+51nc95YPEX8fEbdA2ReVYAAAAAElFTkSuQmCC';
}
public function getClosingBracket()
{
if (!$this->_closingBracket) {
if ($this->_isXhtml()) {
$this->_closingBracket = ' />';
} else {
$this->_closingBracket = '>';
}
}
return $this->_closingBracket;
}
protected function _isXhtml()
{
$view = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view;
$doctype = $view->doctype();
return $doctype->isXhtml();
}
/**
* Transforms data into readable format
*
* @param array $values
* @return string
*/
protected function _cleanData($values)
{
$linebreak = $this->getLinebreak();
if (is_array($values)) {
ksort($values);
}
$retVal = '<div class="pre">';
foreach ($values as $key => $value)
{
$key = htmlspecialchars($key);
if (is_numeric($value)) {
$retVal .= $key.' => '.$value.$linebreak;
}
else if (is_string($value)) {
$retVal .= $key.' => \''.htmlspecialchars($value).'\''.$linebreak;
}
else if (is_array($value))
{
$retVal .= $key.' => '.self::_cleanData($value);
}
else if (is_object($value))
{
$retVal .= $key.' => '.get_class($value).' Object()'.$linebreak;
}
else if (is_null($value))
{
$retVal .= $key.' => NULL'.$linebreak;
}
}
return $retVal.'</div>';
}
}

View File

@ -1,129 +0,0 @@
<?php
/**
* ZFDebug Zend Additions
*
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
* @version $Id: $
*/
/**
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
*/
class ZFDebug_Controller_Plugin_Debug_Plugin_Auth implements ZFDebug_Controller_Plugin_Debug_Plugin_Interface
{
/**
* Contains plugin identifier name
*
* @var string
*/
protected $_identifier = 'auth';
/**
* Contains Zend_Auth object
*
* @var Zend_Auth
*/
protected $_auth;
/**
* Contains "column name" for the username
*
* @var string
*/
protected $_user = 'user';
/**
* Contains "column name" for the role
*
* @var string
*/
protected $_role = 'role';
/**
* Contains Acls for this application
*
* @var Zend_Acl
*/
protected $_acl;
/**
* Create ZFDebug_Controller_Plugin_Debug_Plugin_Auth
*
* @var string $user
* @var string $role
* @return void
*/
public function __construct(array $options = array())
{
$this->_auth = Zend_Auth::getInstance();
if (isset($options['user'])) {
$this->_user = $options['user'];
}
if (isset($options['role'])) {
$this->_role = $options['role'];
}
}
/**
* Gets identifier for this plugin
*
* @return string
*/
public function getIdentifier()
{
return $this->_identifier;
}
/**
* Returns the base64 encoded icon
*
* @return string
**/
public function getIconData()
{
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAJ3SURBVDjLpZNtSNNRFIcNKunF1rZWBMJqKaSiX9RP1dClsjldA42slW0q5oxZiuHrlqllLayoaJa2jbm1Lc3QUZpKFmmaTMsaRp+kMgjBheSmTL2//kqMBJlFHx44XM7vOfdyuH4A/P6HFQ9zo7cpa/mM6RvCrVDzaVDy6C5JJKv6rwSnIhlFd0R0Up/GwF2KWyl01CTSkM/dQoQRzAurCjRCGnRUUE2FaoSL0HExiYVzsQwcj6RNrSqo4W5Gh6Yc4+1qDDTkIy+GhYK4nTgdz0H2PrrHUJzs71NQn86enPn+CVN9GnzruoYR63mMPbkC59gQzDl7pt7rc9f7FNyUhPY6Bx9gwt4E9zszhWWpdg6ZcS8j3O7zCTuEpnXB+3MNZkUUZu0NmHE8XsL91oSWwiiEc3MeseLrN6woYCWa/Zl8ozyQ3w3Hl2lYy0SwlCUvsVi/Gv2JwITnYPDun2Hy6jYuEzAF1jUBCVYpO6kXo+NuGMeBAgcgfwNkvgBOPgUqXgKvP7rBFvRhE1crp8Vq1noFYSlacVyqGk0D86gbART9BDk9BFnPCNJbCY5aCFL1Cyhtp0RWAp74MsKSrkq9guHyvfMTtmLc1togpZoyqYmyNoITzVTYRJCiXYBIQ3CwFqi83o3JDhX6C0M8XsGIMoQ4OyuRlq1DdZcLkmbgGDX1iIEKNxAcbgTEOqC4ZRaJ6Ub86K7CYFEo8Qo+GBQlQyXBczLZpbloaQ9k1NUz/kD2myBBKxRZpa5hVcQslalatoUxizxAVVrN3CW21bFj9F858Q9dnIRmDyeuybM71uxmH9BNBB1q6zybV7H9s1Ue4PM3/gu/AEbfqfWy2twsAAAAAElFTkSuQmCC';
}
/**
* Gets menu tab for the Debugbar
*
* @return string
*/
public function getTab()
{
$username = 'Not Authed';
$role = 'Unknown Role';
if(!$this->_auth->hasIdentity()) {
return 'Not authorized';
}
$identity = $this->_auth->getIdentity();
if (is_object($identity)) {
$username = $this->_auth->getIdentity()->{$this->_user};
$role = $this->_auth->getIdentity()->{$this->_role};
}
else {
$username = $this->_auth->getIdentity();
$role = '';
}
return $username . ' (' . $role . ')';
}
/**
* Gets content panel for the Debugbar
*
* @return string
*/
public function getPanel()
{
return '';
}
}

View File

@ -1,132 +0,0 @@
<?php
/**
* ZFDebug Zend Additions
*
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
* @version $Id$
*/
/**
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
*/
class ZFDebug_Controller_Plugin_Debug_Plugin_Cache extends ZFDebug_Controller_Plugin_Debug_Plugin implements ZFDebug_Controller_Plugin_Debug_Plugin_Interface
{
/**
* Contains plugin identifier name
*
* @var string
*/
protected $_identifier = 'cache';
/**
* @var Zend_Cache_Backend_ExtendedInterface
*/
protected $_cacheBackends = array();
/**
* Create ZFDebug_Controller_Plugin_Debug_Plugin_Cache
*
* @param array $options
* @return void
*/
public function __construct(array $options = array())
{
if (!isset($options['backend'])) {
throw new Zend_Exception("ZFDebug: Cache plugin needs 'backend' parameter");
}
is_array($options['backend']) || $options['backend'] = array($options['backend']);
foreach ($options['backend'] as $name => $backend) {
if ($backend instanceof Zend_Cache_Backend_ExtendedInterface ) {
$this->_cacheBackends[$name] = $backend;
}
}
}
/**
* Gets identifier for this plugin
*
* @return string
*/
public function getIdentifier()
{
return $this->_identifier;
}
/**
* Returns the base64 encoded icon
*
* @return string
**/
public function getIconData()
{
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAI/SURBVDjLjZPbS9NhHMYH+zNidtCSQrqwQtY5y2QtT2QGrTZf13TkoYFlzsWa/tzcoR3cSc2xYUlGJfzAaIRltY0N12H5I+jaOxG8De+evhtdOP1hu3hv3sPzPO/z4SsBIPnfuvG8cbBlWiEVO5OUItA0VS8oxi9EdhXo+6yV3V3UGHRvVXHNfNv6zRfNuBZVoiFcB/3LdnQ8U+Gk+bhPVKB3qUOuf6/muaQR/qwDkZ9BRFdCmMr5EPz6BN7lMYylLGgNNaKqt3K0SKDnQ7us690t3rNsxeyvaUz+8OJpzo/QNzd8WTtcaQ7WlBmPvxhx1V2Pg7oDziIBimwwf3qAGWESkVwQ7owNujk1ztvk+cg4NnAUTT4FrrjqUKHdF9jxBfXr1rgjaSk4OlMcLrnOrJ7latxbL1V2lgvlbG9MtMTrMw1r1PImtfyn1n5q47TlBLf90n5NmalMtUdKZoyQMkLKlIGLjMyYhFpmlz3nGEVmFJlRZNaf7pIaEndM24XIjCOzjX9mm2S2JsqdkMYIqbB1j5C6yWzVk7YRFTsGFu7l+4nveExIA9aMCcOJh6DIoMigyOh+o4UryRWQOtIjaJtoziM1FD0mpE4uZcTc72gBaUyYKEI6khgqINXO3saR7kM8IZUVCRDS0Ucf+xFbCReQhr97MZ51wpWxYnhpCD3zOrT4lTisr+AJqVx0Fiiyr4/vhP4VyyMFIUWNqRrV96vWKXKckBoIqWzXYcoPDrUslDJoopuEVEpIB0sR+AuErIiZ6OqMKAAAAABJRU5ErkJggg==';
}
/**
* Gets menu tab for the Debugbar
*
* @return string
*/
public function getTab()
{
return 'Cache';
}
/**
* Gets content panel for the Debugbar
*
* @return string
*/
public function getPanel()
{
$panel = '';
# Support for APC
if (function_exists('apc_sma_info') && ini_get('apc.enabled')) {
$mem = apc_sma_info();
$mem_size = $mem['num_seg']*$mem['seg_size'];
$mem_avail = $mem['avail_mem'];
$mem_used = $mem_size-$mem_avail;
$cache = apc_cache_info();
$panel .= '<h4>APC '.phpversion('apc').' Enabled</h4>';
$panel .= round($mem_avail/1024/1024, 1).'M available, '.round($mem_used/1024/1024, 1).'M used'.$this->getLinebreak()
. $cache['num_entries'].' Files cached ('.round($cache['mem_size']/1024/1024, 1).'M)'.$this->getLinebreak()
. $cache['num_hits'].' Hits ('.round($cache['num_hits'] * 100 / ($cache['num_hits']+$cache['num_misses']), 1).'%)'.$this->getLinebreak()
. $cache['expunges'].' Expunges (cache full count)';
}
foreach ($this->_cacheBackends as $name => $backend) {
$fillingPercentage = $backend->getFillingPercentage();
$ids = $backend->getIds();
# Print full class name, backends might be custom
$panel .= '<h4>Cache '.$name.' ('.get_class($backend).')</h4>';
$panel .= count($ids).' Entr'.(count($ids)>1?'ies':'y').''.$this->getLinebreak()
. 'Filling Percentage: '.$backend->getFillingPercentage().'%'.$this->getLinebreak();
$cacheSize = 0;
foreach ($ids as $id)
{
# Calculate valid cache size
$mem_pre = memory_get_usage();
if ($cached = $backend->load($id)) {
$mem_post = memory_get_usage();
$cacheSize += $mem_post-$mem_pre;
unset($cached);
}
}
$panel .= 'Valid Cache Size: '.round($cacheSize/1024, 1). 'K';
}
return $panel;
}
}

View File

@ -1,170 +0,0 @@
<?php
/**
* ZFDebug Zend Additions
*
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
* @version $Id$
*/
/**
* @see Zend_Db_Table_Abstract
*/
require_once 'Zend/Db/Table/Abstract.php';
/**
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
*/
class ZFDebug_Controller_Plugin_Debug_Plugin_Database extends ZFDebug_Controller_Plugin_Debug_Plugin implements ZFDebug_Controller_Plugin_Debug_Plugin_Interface
{
/**
* Contains plugin identifier name
*
* @var string
*/
protected $_identifier = 'database';
/**
* @var array
*/
protected $_db = array();
protected $_explain = false;
/**
* Create ZFDebug_Controller_Plugin_Debug_Plugin_Variables
*
* @param Zend_Db_Adapter_Abstract|array $adapters
* @return void
*/
public function __construct(array $options = array())
{
if(!isset($options['adapter']) || !count($options['adapter'])) {
if (Zend_Db_Table_Abstract::getDefaultAdapter()) {
$this->_db[0] = Zend_Db_Table_Abstract::getDefaultAdapter();
$this->_db[0]->getProfiler()->setEnabled(true);
}
} else if ($options['adapter'] instanceof Zend_Db_Adapter_Abstract ) {
$this->_db[0] = $options['adapter'];
$this->_db[0]->getProfiler()->setEnabled(true);
} else {
foreach ($options['adapter'] as $name => $adapter) {
if ($adapter instanceof Zend_Db_Adapter_Abstract) {
$adapter->getProfiler()->setEnabled(true);
$this->_db[$name] = $adapter;
}
}
}
if (isset($options['explain'])) {
$this->_explain = (bool)$options['explain'];
}
}
/**
* Gets identifier for this plugin
*
* @return string
*/
public function getIdentifier()
{
return $this->_identifier;
}
/**
* Returns the base64 encoded icon
*
* @return string
**/
public function getIconData()
{
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAEYSURBVBgZBcHPio5hGAfg6/2+R980k6wmJgsJ5U/ZOAqbSc2GnXOwUg7BESgLUeIQ1GSjLFnMwsKGGg1qxJRmPM97/1zXFAAAAEADdlfZzr26miup2svnelq7d2aYgt3rebl585wN6+K3I1/9fJe7O/uIePP2SypJkiRJ0vMhr55FLCA3zgIAOK9uQ4MS361ZOSX+OrTvkgINSjS/HIvhjxNNFGgQsbSmabohKDNoUGLohsls6BaiQIMSs2FYmnXdUsygQYmumy3Nhi6igwalDEOJEjPKP7CA2aFNK8Bkyy3fdNCg7r9/fW3jgpVJbDmy5+PB2IYp4MXFelQ7izPrhkPHB+P5/PjhD5gCgCenx+VR/dODEwD+A3T7nqbxwf1HAAAAAElFTkSuQmCC';
}
/**
* Gets menu tab for the Debugbar
*
* @return string
*/
public function getTab()
{
if (!$this->_db)
return 'No adapter';
foreach ($this->_db as $adapter) {
$profiler = $adapter->getProfiler();
$adapterInfo[] = $profiler->getTotalNumQueries().' in '.round($profiler->getTotalElapsedSecs()*1000, 2).' ms';
}
$html = implode(' / ', $adapterInfo);
return $html;
}
/**
* Gets content panel for the Debugbar
*
* @return string
*/
public function getPanel()
{
if (!$this->_db)
return '';
$html = '<h4>Database queries</h4>';
if (Zend_Db_Table_Abstract::getDefaultMetadataCache ()) {
$html .= 'Metadata cache is ENABLED';
} else {
$html .= 'Metadata cache is DISABLED';
}
# For adding quotes to query params
function add_quotes(&$value, $key) {
$value = "'".$value."'";
}
foreach ($this->_db as $name => $adapter) {
if ($profiles = $adapter->getProfiler()->getQueryProfiles()) {
$adapter->getProfiler()->setEnabled(false);
$html .= '<h4>Adapter '.$name.'</h4><ol>';
foreach ($profiles as $profile) {
$params = $profile->getQueryParams();
array_walk($params, 'add_quotes');
$paramCount = count($params);
if ($paramCount) {
$html .= '<li>'.htmlspecialchars(preg_replace(array_fill(0, $paramCount, '/\?/'), $params, $profile->getQuery(), 1));
} else {
$html .= '<li>'.htmlspecialchars($profile->getQuery());
}
$html .= '<p><strong>Time:</strong> '.round($profile->getElapsedSecs()*1000, 2).' ms'.$this->getLinebreak();
$supportedAdapter = ($adapter instanceof Zend_Db_Adapter_Mysqli
|| $adapter instanceof Zend_Db_Adapter_Pdo_Mysql);
# Run explain if enabled, supported adapter and SELECT query
if ($this->_explain && $supportedAdapter && Zend_Db_Profiler::SELECT == $profile->getQueryType()) {
$explain = $adapter->fetchRow('EXPLAIN '.$profile->getQuery());
$html .= '<strong>Type:</strong> '.strtolower($explain['select_type']).', '.$explain['type'].$this->getLinebreak()
.'<strong>Possible Keys:</strong> '.$explain['possible_keys'].$this->getLinebreak()
.'<strong>Key Used:</strong> '.$explain['key'].$this->getLinebreak()
.'<strong>Rows:</strong> '.$explain['rows'].$this->getLinebreak()
.'<strong>Extra:</strong> '.$explain['Extra'];
}
$html .= '</p></li>';
}
$html .= '</ol>';
}
}
return $html;
}
}

View File

@ -1,163 +0,0 @@
<?php
/**
* ZFDebug Zend Additions
*
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
* @version $Id$
*/
/**
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
*/
class ZFDebug_Controller_Plugin_Debug_Plugin_Exception implements ZFDebug_Controller_Plugin_Debug_Plugin_Interface
{
/**
* Contains plugin identifier name
*
* @var string
*/
protected $_identifier = 'exception';
/**
* Contains any errors
*
* @var param array
*/
static $errors = array();
/**
* Gets identifier for this plugin
*
* @return string
*/
public function getIdentifier ()
{
return $this->_identifier;
}
/**
* Returns the base64 encoded icon
*
* @return string
**/
public function getIconData()
{
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAJPSURBVDjLpZPLS5RhFMYfv9QJlelTQZwRb2OKlKuINuHGLlBEBEOLxAu46oL0F0QQFdWizUCrWnjBaDHgThCMoiKkhUONTqmjmDp2GZ0UnWbmfc/ztrC+GbM2dXbv4ZzfeQ7vefKMMfifyP89IbevNNCYdkN2kawkCZKfSPZTOGTf6Y/m1uflKlC3LvsNTWArr9BT2LAf+W73dn5jHclIBFZyfYWU3or7T4K7AJmbl/yG7EtX1BQXNTVCYgtgbAEAYHlqYHlrsTEVQWr63RZFuqsfDAcdQPrGRR/JF5nKGm9xUxMyr0YBAEXXHgIANq/3ADQobD2J9fAkNiMTMSFb9z8ambMAQER3JC1XttkYGGZXoyZEGyTHRuBuPgBTUu7VSnUAgAUAWutOV2MjZGkehgYUA6O5A0AlkAyRnotiX3MLlFKduYCqAtuGXpyH0XQmOj+TIURt51OzURTYZdBKV2UBSsOIcRp/TVTT4ewK6idECAihtUKOArWcjq/B8tQ6UkUR31+OYXP4sTOdisivrkMyHodWejlXwcC38Fvs8dY5xaIId89VlJy7ACpCNCFCuOp8+BJ6A631gANQSg1mVmOxxGQYRW2nHMha4B5WA3chsv22T5/B13AIicWZmNZ6cMchTXUe81Okzz54pLi0uQWp+TmkZqMwxsBV74Or3od4OISPr0e3SHa3PX0f3HXKofNH/UIG9pZ5PeUth+CyS2EMkEqs4fPEOBJLsyske48/+xD8oxcAYPzs4QaS7RR2kbLTTOTQieczfzfTv8QPldGvTGoF6/8AAAAASUVORK5CYII=';
}
/**
* Creates Error Plugin ans sets the Error Handler
*
* @return void
*/
public function __construct ()
{
set_error_handler(array($this , 'errorHandler'));
}
/**
* Gets menu tab for the Debugbar
*
* @return string
*/
public function getTab ()
{
$response = Zend_Controller_Front::getInstance()->getResponse();
$errorCount = count(self::$errors);
if (! $response->isException() && ! $errorCount)
return '';
$error = '';
$exception = '';
if ($errorCount)
$error = ($errorCount == 1 ? '1 Error' : $errorCount . ' Errors');
$count = count($response->getException());
//if ($this->_options['show_exceptions'] && $count)
if ($count)
$exception = ($count == 1) ? '1 Exception' : $count . ' Exceptions';
$text = $exception . ($exception == '' || $error == '' ? '' : ' - ') . $error;
return $text;
}
/**
* Gets content panel for the Debugbar
*
* @return string
*/
public function getPanel ()
{
$response = Zend_Controller_Front::getInstance()->getResponse();
$errorCount = count(self::$errors);
if (! $response->isException() && ! $errorCount)
return '';
$html = '';
foreach ($response->getException() as $e) {
$html .= '<h4>' . get_class($e) . ': ' . $e->getMessage() . '</h4><p>thrown in ' . $e->getFile() . ' on line ' . $e->getLine() . '</p>';
$html .= '<h4>Call Stack</h4><ol>';
foreach ($e->getTrace() as $t) {
$func = $t['function'] . '()';
if (isset($t['class']))
$func = $t['class'] . $t['type'] . $func;
if (! isset($t['file']))
$t['file'] = 'unknown';
if (! isset($t['line']))
$t['line'] = 'n/a';
$html .= '<li>' . $func . '<br>in ' . str_replace($_SERVER['DOCUMENT_ROOT'], '', $t['file']) . ' on line ' . $t['line'] . '</li>';
}
$html .= '</ol>';
}
if ($errorCount) {
$html .= '<h4>Errors</h4><ol>';
foreach (self::$errors as $error) {
$html .= '<li>' . sprintf("%s: %s in %s on line %d", $error['type'], $error['message'], str_replace($_SERVER['DOCUMENT_ROOT'], '', $error['file']), $error['line']) . '</li>';
}
$html .= '</ol>';
}
return $html;
}
/**
* Debug Bar php error handler
*
* @param string $level
* @param string $message
* @param string $file
* @param string $line
* @return bool
*/
public static function errorHandler ($level, $message, $file, $line)
{
if (! ($level & error_reporting()))
return false;
switch ($level) {
case E_NOTICE:
case E_USER_NOTICE:
$type = 'Notice';
break;
case E_WARNING:
case E_USER_WARNING:
$type = 'Warning';
break;
case E_ERROR:
case E_USER_ERROR:
$type = 'Fatal Error';
break;
default:
$type = 'Unknown, ' . $level;
break;
}
self::$errors[] = array('type' => $type , 'message' => $message , 'file' => $file , 'line' => $line);
if (ini_get('log_errors'))
error_log(sprintf("%s: %s in %s on line %d", $type, $message, $file, $line));
return true;
}
}

View File

@ -1,166 +0,0 @@
<?php
/**
* ZFDebug Zend Additions
*
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
* @version $Id$
*/
/**
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
*/
class ZFDebug_Controller_Plugin_Debug_Plugin_File extends ZFDebug_Controller_Plugin_Debug_Plugin implements ZFDebug_Controller_Plugin_Debug_Plugin_Interface
{
/**
* Contains plugin identifier name
*
* @var string
*/
protected $_identifier = 'file';
/**
* Base path of this application
* String is used to strip it from filenames
*
* @var string
*/
protected $_basePath;
/**
* Stores included files
*
* @var array
*/
protected $_includedFiles = null;
/**
* Stores name of own extension library
*
* @var string
*/
protected $_library;
/**
* Setting Options
*
* basePath:
* This will normally not your document root of your webserver, its your
* application root directory with /application, /library and /public
*
* library:
* Your own library extension(s)
*
* @param array $options
* @return void
*/
public function __construct(array $options = array())
{
isset($options['base_path']) || $options['base_path'] = $_SERVER['DOCUMENT_ROOT'];
isset($options['library']) || $options['library'] = null;
$this->_basePath = realpath($options['base_path']);
is_array($options['library']) || $options['library'] = array($options['library']);
$this->_library = array_merge($options['library'], array('Zend', 'ZFDebug'));
}
/**
* Gets identifier for this plugin
*
* @return string
*/
public function getIdentifier()
{
return $this->_identifier;
}
/**
* Returns the base64 encoded icon
*
* @return string
**/
public function getIconData()
{
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAADPSURBVCjPdZFNCsIwEEZHPYdSz1DaHsMzuPM6RRcewSO4caPQ3sBDKCK02p+08DmZtGkKlQ+GhHm8MBmiFQUU2ng0B7khClTdQqdBiX1Ma1qMgbDlxh0XnJHiit2JNq5HgAo3KEx7BFAM/PMI0CDB2KNvh1gjHZBi8OR448GnAkeNDEDvKZDh2Xl4cBcwtcKXkZdYLJBYwCCFPDRpMEjNyKcDPC4RbXuPiWKkNABPOuNhItegz0pGFkD+y3p0s48DDB43dU7+eLWes3gdn5Y/LD9Y6skuWXcAAAAASUVORK5CYII=';
}
/**
* Gets menu tab for the Debugbar
*
* @return string
*/
public function getTab()
{
return count($this->_getIncludedFiles()) . ' Files';
}
/**
* Gets content panel for the Debugbar
*
* @return string
*/
public function getPanel()
{
$included = $this->_getIncludedFiles();
$html = '<h4>File Information</h4>';
$html .= count($included).' Files Included'.$this->getLinebreak();
$size = 0;
foreach ($included as $file) {
$size += filesize($file);
}
$html .= 'Total Size: '. round($size/1024, 1).'K'.$this->getLinebreak();
$html .= 'Basepath: ' . $this->_basePath .$this->getLinebreak();
$libraryFiles = array();
foreach ($this->_library as $key => $value) {
if ('' != $value) {
$libraryFiles[$key] = '<h4>' . $value . ' Files</h4>';
}
}
$html .= '<h4>Application Files</h4>';
foreach ($included as $file) {
$file = str_replace($this->_basePath, '', $file);
$filePaths = explode(DIRECTORY_SEPARATOR, $file);
$inUserLib = false;
foreach ($this->_library as $key => $library)
{
if('' != $library && in_array($library, $filePaths)) {
$libraryFiles[$key] .= $file . $this->getLinebreak();
$inUserLib = TRUE;
}
}
if (!$inUserLib) {
$html .= $file .$this->getLinebreak();
}
}
$html .= implode('', $libraryFiles);
return $html;
}
/**
* Gets included files
*
* @return array
*/
protected function _getIncludedFiles()
{
if (null !== $this->_includedFiles) {
return $this->_includedFiles;
}
$this->_includedFiles = get_included_files();
sort($this->_includedFiles);
return $this->_includedFiles;
}
}

View File

@ -1,101 +0,0 @@
<?php
/**
* ZFDebug Zend Additions
*
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
* @version $Id$
*/
/**
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
*/
class ZFDebug_Controller_Plugin_Debug_Plugin_Html extends ZFDebug_Controller_Plugin_Debug_Plugin implements ZFDebug_Controller_Plugin_Debug_Plugin_Interface
{
/**
* Contains plugin identifier name
*
* @var string
*/
protected $_identifier = 'html';
/**
* Create ZFDebug_Controller_Plugin_Debug_Plugin_Html
*
* @param string $tab
* @paran string $panel
* @return void
*/
public function __construct()
{
}
/**
* Gets identifier for this plugin
*
* @return string
*/
public function getIdentifier()
{
return $this->_identifier;
}
/**
* Returns the base64 encoded icon
*
* @return string
**/
public function getIconData()
{
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAEdSURBVDjLjZIxTgNBDEXfbDZIlIgmCKWgSpMGxEk4AHehgavQcJY0KRKJJiBQLkCR7PxvmiTsbrJoLY1sy/Ibe+an9XodtqkfSUd+Op0mTlgpidFodKpGRAAwn8/pstI2AHvfbi6KAkndgHZx31iP2/CTE3Q1A0ji6fUjsiFn8fJ4k44mSCmR0sl3QhJXF2fYwftXPl5hsVg0Xr0d2yZnIwWbqrlyOZlMDtc+v33H9eUQO7ACOZAC2Ye8qqIJqCfZRtnIIBnVQH8AdQOqylTZWPBwX+zGj93ZrXU7ZLlcxj5vArYi5/Iweh+BNQCbrVl8/uAMvjvvJbBU/++6rVarGI/HB0BbI4PBgNlsRtGlsL4CK7sAfQX2L6CPwH4BZf1E9tbX5ioAAAAASUVORK5CYII=';
}
/**
* Gets menu tab for the Debugbar
*
* @return string
*/
public function getTab()
{
return 'HTML';
}
/**
* Gets content panel for the Debugbar
*
* @return string
*/
public function getPanel()
{
$body = Zend_Controller_Front::getInstance()->getResponse()->getBody();
$panel = '<h4>HTML Information</h4>';
$panel .= $this->_isXhtml().'
<script type="text/javascript">
var ZFHtmlLoad = window.onload;
window.onload = function(){
if (ZFHtmlLoad) {
ZFHtmlLoad();
}
jQuery("#ZFDebug_Html_Tagcount").html(document.getElementsByTagName("*").length);
jQuery("#ZFDebug_Html_Stylecount").html(jQuery("link[rel*=stylesheet]").length);
jQuery("#ZFDebug_Html_Scriptcount").html(jQuery("script[src]").length);
jQuery("#ZFDebug_Html_Imgcount").html(jQuery("img[src]").length);
};
</script>';
$panel .= '<span id="ZFDebug_Html_Tagcount"></span> Tags'.$this->getLinebreak()
. 'HTML Size: '.round(strlen($body)/1024, 2).'K'.$this->getLinebreak()
. '<span id="ZFDebug_Html_Stylecount"></span> Stylesheet Files'.$this->getLinebreak()
. '<span id="ZFDebug_Html_Scriptcount"></span> Javascript Files'.$this->getLinebreak()
. '<span id="ZFDebug_Html_Imgcount"></span> Images'.$this->getLinebreak()
. '<form method="post" action="http://validator.w3.org/check"><p><input type="hidden" name="fragment" value="'.htmlentities($body).'"'.$this->getClosingBracket().'<input type="submit" value="Validate With W3C"'.$this->getClosingBracket().'</p></form>';
return $panel;
}
}

View File

@ -1,50 +0,0 @@
<?php
/**
* ZFDebug Zend Additions
*
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
* @version $Id$
*/
/**
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
*/
interface ZFDebug_Controller_Plugin_Debug_Plugin_Interface
{
/**
* Has to return html code for the menu tab
*
* @return string
*/
public function getTab();
/**
* Has to return html code for the content panel
*
* @return string
*/
public function getPanel();
/**
* Has to return a unique identifier for the specific plugin
*
* @return string
*/
public function getIdentifier();
/**
* Return the path to an icon
*
* @return string
*/
public function getIconData();
}

View File

@ -1,165 +0,0 @@
<?php
/**
* ZFDebug Zend Additions
*
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
* @version $Id$
*/
/**
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
*/
class ZFDebug_Controller_Plugin_Debug_Plugin_Memory extends Zend_Controller_Plugin_Abstract implements ZFDebug_Controller_Plugin_Debug_Plugin_Interface
{
/**
* Contains plugin identifier name
*
* @var string
*/
protected $_identifier = 'memory';
/**
* @var array
*/
protected $_memory = array(
'dispatchLoopShutdown' => 0,
'dispatchLoopStartup' => 0
);
protected $_closingBracket = null;
/**
* Creating time plugin
* @return void
*/
public function __construct()
{
Zend_Controller_Front::getInstance()->registerPlugin($this);
}
/**
* Gets identifier for this plugin
*
* @return string
*/
public function getIdentifier()
{
return $this->_identifier;
}
/**
* Returns the base64 encoded icon
*
* @return string
**/
public function getIconData()
{
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAGvSURBVDjLpZO7alZREEbXiSdqJJDKYJNCkPBXYq12prHwBezSCpaidnY+graCYO0DpLRTQcR3EFLl8p+9525xgkRIJJApB2bN+gZmqCouU+NZzVef9isyUYeIRD0RTz482xouBBBNHi5u4JlkgUfx+evhxQ2aJRrJ/oFjUWysXeG45cUBy+aoJ90Sj0LGFY6anw2o1y/mK2ZS5pQ50+2XiBbdCvPk+mpw2OM/Bo92IJMhgiGCox+JeNEksIC11eLwvAhlzuAO37+BG9y9x3FTuiWTzhH61QFvdg5AdAZIB3Mw50AKsaRJYlGsX0tymTzf2y1TR9WwbogYY3ZhxR26gBmocrxMuhZNE435FtmSx1tP8QgiHEvj45d3jNlONouAKrjjzWaDv4CkmmNu/Pz9CzVh++Yd2rIz5tTnwdZmAzNymXT9F5AtMFeaTogJYkJfdsaaGpyO4E62pJ0yUCtKQFxo0hAT1JU2CWNOJ5vvP4AIcKeao17c2ljFE8SKEkVdWWxu42GYK9KE4c3O20pzSpyyoCx4v/6ECkCTCqccKorNxR5uSXgQnmQkw2Xf+Q+0iqQ9Ap64TwAAAABJRU5ErkJggg==';
}
/**
* Gets menu tab for the Debugbar
*
* @return string
*/
public function getTab()
{
if (function_exists('memory_get_peak_usage')) {
return round(memory_get_peak_usage()/1024) . 'K of '.ini_get("memory_limit");
}
return 'MemUsage n.a.';
}
/**
* Gets content panel for the Debugbar
*
* @return string
*/
public function getPanel()
{
$panel = '<h4>Memory Usage</h4>';
$panel .= 'Dispatch: ' . round(($this->_memory['dispatchLoopShutdown']-$this->_memory['dispatchLoopStartup'])/1024,2) .'K'.$this->getLinebreak();
if (isset($this->_memory['user']) && count($this->_memory['user'])) {
foreach ($this->_memory['user'] as $key => $value) {
$panel .= $key.': '.round($value/1024).'K'.$this->getLinebreak();
}
}
return $panel;
}
/**
* Sets a memory mark identified with $name
*
* @param string $name
*/
public function mark($name) {
if (!function_exists('memory_get_peak_usage')) {
return;
}
if (isset($this->_memory['user'][$name]))
$this->_memory['user'][$name] = memory_get_peak_usage()-$this->_memory['user'][$name];
else
$this->_memory['user'][$name] = memory_get_peak_usage();
}
/**
* Defined by Zend_Controller_Plugin_Abstract
*
* @param Zend_Controller_Request_Abstract
* @return void
*/
public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
{
if (function_exists('memory_get_peak_usage')) {
$this->_memory['dispatchLoopStartup'] = memory_get_peak_usage();
}
}
/**
* Defined by Zend_Controller_Plugin_Abstract
*
* @param Zend_Controller_Request_Abstract
* @return void
*/
public function dispatchLoopShutdown()
{
if (function_exists('memory_get_peak_usage')) {
$this->_memory['dispatchLoopShutdown'] = memory_get_peak_usage();
}
}
public function getLinebreak()
{
return '<br'.$this->getClosingBracket();
}
public function getClosingBracket()
{
if (!$this->_closingBracket) {
if ($this->_isXhtml()) {
$this->_closingBracket = ' />';
} else {
$this->_closingBracket = '>';
}
}
return $this->_closingBracket;
}
protected function _isXhtml()
{
$view = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view;
$doctype = $view->doctype();
return $doctype->isXhtml();
}
}

View File

@ -1,90 +0,0 @@
<?php
/**
* ZFDebug Zend Additions
*
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
* @version $Id: $
*/
/**
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
*/
class ZFDebug_Controller_Plugin_Debug_Plugin_Registry extends ZFDebug_Controller_Plugin_Debug_Plugin implements ZFDebug_Controller_Plugin_Debug_Plugin_Interface
{
/**
* Contains plugin identifier name
*
* @var string
*/
protected $_identifier = 'registry';
/**
* Contains Zend_Registry
*
* @var Zend_Registry
*/
protected $_registry;
/**
* Create ZFDebug_Controller_Plugin_Debug_Plugin_Registry
*
* @return void
*/
public function __construct()
{
$this->_registry = Zend_Registry::getInstance();
}
/**
* Gets identifier for this plugin
*
* @return string
*/
public function getIdentifier()
{
return $this->_identifier;
}
/**
* Returns the base64 encoded icon
*
* @return string
**/
public function getIconData()
{
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAH2SURBVDjLjZNLTxNRGIaJv6ZNWeBwkZFLQtGAC4l/wKULV+7YILeSYukEUhJoSASVuCI0hpAYDSUQCJBSoAaC0wbBUi4aWphpO52Zlpa+nnOqCAptJ3k3M3me73LOlAAoyZfDqQdOEvyO89/vRcGZ5HeWmySFYdWHVOQN0vE58jrLJMFJ82hewVU4+bMfqdPxP9VBn+A4D88wP59PwFqmsH7UgeTJEMlsTuIyI5uRsDfCMcmtAtoyhVmOu5kkHZuFsiNA3XuEi+QCdhxluL0D/SvpoO+vhIksiItNiPqqyXgfIL403gjfoTsIL70gQBdim3VQvz2FFnwOxf8E8kYF0rIVYqcRM70Vgf/Pe/ohwsutOJdcpBpP4Mek+jPEfbWQVzkG+7tNcNsqt68tkcLZTIzM6YZ21IbolgHq9j1o+z04nKhHRnlH2p6A32LCvFD55fIYr960VHgSSqCFVDJBEeugh+zw2jnpc0/5rthuRMBaioWBqrVrFylXOUpankIi0AjJY0DC3wD9oA9rAnc2bat+n++2UkH8XHaTZfGQlg3QdlsIbIVX4KSPAv+60L+SO/PECmJiI1lYM9SQBR7b3einfn6kEMwEIZd5Q48sQQt1Qv/xFqt2Tp5x3B8sBmYC71h926az6njdUR6hMy8O17wqFqb5Bd2o/0SFzIZrAAAAAElFTkSuQmCC';
}
/**
* Gets menu tab for the Debugbar
*
* @return string
*/
public function getTab()
{
return ' Registry (' . $this->_registry->count() . ')';
}
/**
* Gets content panel for the Debugbar
*
* @return string
*/
public function getPanel()
{
$html = '<h4>Registered Instances</h4>';
$this->_registry->ksort();
$html .= $this->_cleanData($this->_registry);
return $html;
}
}

View File

@ -1,150 +0,0 @@
<?php
/**
* ZFDebug Zend Additions
*
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
* @version $Id$
*/
/**
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
*/
class ZFDebug_Controller_Plugin_Debug_Plugin_Text implements ZFDebug_Controller_Plugin_Debug_Plugin_Interface
{
/**
* @var string
*/
protected $_tab = '';
/**
* @var string
*/
protected $_panel = '';
/**
* Contains plugin identifier name
*
* @var string
*/
protected $_identifier = 'text';
/**
* Contains plugin icon data
*
* @var string
*/
protected $_icondata = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAHhSURBVDjLpZI9SJVxFMZ/r2YFflw/kcQsiJt5b1ije0tDtbQ3GtFQYwVNFbQ1ujRFa1MUJKQ4VhYqd7K4gopK3UIly+57nnMaXjHjqotnOfDnnOd/nt85SURwkDi02+ODqbsldxUlD0mvHw09ubSXQF1t8512nGJ/Uz/5lnxi0tB+E9QI3D//+EfVqhtppGxUNzCzmf0Ekojg4fS9cBeSoyzHQNuZxNyYXp5ZM5Mk1ZkZT688b6thIBenG/N4OB5B4InciYBCVyGnEBHO+/LH3SFKQuF4OEs/51ndXMXC8Ajqknrcg1O5PGa2h4CJUqVES0OO7sYevv2qoFBmJ/4gF4boaOrg6rPLYWaYiVfDo0my8w5uj12PQleB0vcp5I6HsHAUoqUhR29zH+5B4IxNTvDmxljy3x2YCYUwZVlbzXJh9UKeQY6t2m0Lt94Oh5loPdqK3EkjzZi4MM/Y9Db3MTv/mYWVxaqkw9IOATNR7B5ABHPrZQrtg9sb8XDKa1+QOwsri4zeHD9SAzE1wxBTXz9xtvMc5ZU5lirLSKIz18nJnhOZjb22YKkhd4odg5icpcoyL669TAAujlyIvmPHSWXY1ti1AmZ8mJ3ElP1ips1/YM3H300g+W+51nc95YPEX8fEbdA2ReVYAAAAAElFTkSuQmCC';
/**
* Create ZFDebug_Controller_Plugin_Debug_Plugin_Text
*
* @param string $tab
* @paran string $panel
* @return void
*/
public function __construct(array $options = array())
{
if (isset($options['tab'])) {
$this->setTab($tab);
}
if (isset($options['panel'])) {
$this->setPanel($panel);
}
}
/**
* Gets identifier for this plugin
*
* @return string
*/
public function getIdentifier()
{
return $this->_identifier;
}
/**
* Sets identifier for this plugin
*
* @param string $name
* @return ZFDebug_Controller_Plugin_Debug_Plugin_Text Provides a fluent interface
*/
public function setIdentifier($name)
{
$this->_identifier = $name;
return $this;
}
/**
* Returns the base64 encoded icon
*
* @return string
**/
public function getIconData()
{
return $this->_icondata;
}
/**
* Sets icon data for this plugin
*
* @param string $data
* @return ZFDebug_Controller_Plugin_Debug_Plugin_Text Provides a fluent interface
*/
public function setIconData($data)
{
$this->_icondata = $data;
return $this;
}
/**
* Gets menu tab for the Debugbar
*
* @return string
*/
public function getTab()
{
return $this->_tab;
}
/**
* Gets content panel for the Debugbar
*
* @return string
*/
public function getPanel()
{
return $this->_panel;
}
/**
* Sets tab content
*
* @param string $tab
* @return ZFDebug_Controller_Plugin_Debug_Plugin_Text Provides a fluent interface
*/
public function setTab($tab)
{
$this->_tab = $tab;
return $this;
}
/**
* Sets panel content
*
* @param string $panel
* @return ZFDebug_Controller_Plugin_Debug_Plugin_Text Provides a fluent interface
*/
public function setPanel($panel)
{
$this->_panel = $panel;
return $this;
}
}

View File

@ -1,249 +0,0 @@
<?php
/**
* ZFDebug Zend Additions
*
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
* @version $Id$
*/
/**
* @see Zend_Session
*/
require_once 'Zend/Session.php';
/**
* @see Zend_Session_Namespace
*/
require_once 'Zend/Session/Namespace.php';
/**
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
*/
class ZFDebug_Controller_Plugin_Debug_Plugin_Time extends Zend_Controller_Plugin_Abstract implements ZFDebug_Controller_Plugin_Debug_Plugin_Interface
{
/**
* Contains plugin identifier name
*
* @var string
*/
protected $_identifier = 'time';
/**
* @var array
*/
protected $_timer = array(
'dispatchLoopStartup' => 0,
'dispatchLoopShutdown' => 0
);
protected $_closingBracket = null;
/**
* Creating time plugin
* @return void
*/
public function __construct()
{
Zend_Controller_Front::getInstance()->registerPlugin($this);
}
/**
* Gets identifier for this plugin
*
* @return string
*/
public function getIdentifier()
{
return $this->_identifier;
}
/**
* Returns the base64 encoded icon
*
* @return string
**/
public function getIconData()
{
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAKrSURBVDjLpdPbT9IBAMXx/qR6qNbWUy89WS5rmVtutbZalwcNgyRLLMyuoomaZpRQCt5yNRELL0TkBSXUTBT5hZSXQPwBAvor/fZGazlb6+G8nIfP0znbgG3/kz+Knsbb+xxNV63DLxVLHzqV0vCrfMluzFmw1OW8ePEwf8+WgM1UXDnapVgLePr5Nj9DJBJGFEN8+TzKqL2RzkenV4yl5ws2BXob1WVeZxXhoB+PP0xzt0Bly0fKTePozV5GphYQPA46as+gU5/K+w2w6Ev2Ol/KpNCigM01R2uPgDcQIRSJEYys4JmNoO/y0tbnY9JlxnA9M15bfHZHCnjzVN4x7TLz6fMSJqsPgLAoMvV1niSQBGIbUP3Ki93t57XhItVXjulTQHf9hfk5/xgGyzQTgQjx7xvE4nG0j3UsiiLR1VVaLN3YpkTuNLgZGzRSq8wQUoD16flkOPSF28/cLCYkwqvrrAGXC1UYWtuRX1PR5RhgTJTI1Q4wKwzwWHk4kQI6a04nQ99mUOlczMYkFhPrBMQoN+7eQ35Nhc01SvA7OEMSFzTv8c/0UXc54xfQcj/bNzNmRmNy0zctMpeEQFSio/cdvqUICz9AiEPb+DLK2gE+2MrR5qXPpoAn6mxdr1GBwz1FiclDcAPCEkTXIboByz8guA75eg8WxxDtFZloZIdNKaDu5rnt9UVHE5POep6Zh7llmsQlLBNLSMTiEm5hGXXDJ6qb3zJiLaIiJy1Zpjy587ch1ahOKJ6XHGGiv5KeQSfFun4ulb/josZOYY0di/0tw9YCquX7KZVnFW46Ze2V4wU1ivRYe1UWI1Y1vgkDvo9PGLIoabp7kIrctJXSS8eKtjyTtuDErrK8jIYHuQf8VbK0RJUsLfEg94BfIztkLMvP3v3XN/5rfgIYvAvmgKE6GAAAAABJRU5ErkJggg==';
}
/**
* Gets menu tab for the Debugbar
*
* @return string
*/
public function getTab()
{
return round($this->_timer['dispatchLoopShutdown'],2) .'/'.round($this->_timer['dispatchLoopShutdown']-$this->_timer['dispatchLoopStartup'],2). ' ms';
}
/**
* Gets content panel for the Debugbar
*
* @return string
*/
public function getPanel()
{
$html = '<h4>Custom Timers</h4>';
$html .= 'Dispatch: ' . round(($this->_timer['dispatchLoopShutdown']-$this->_timer['dispatchLoopStartup']),2) .' ms'.$this->getLinebreak();
if (isset($this->_timer['user']) && count($this->_timer['user'])) {
foreach ($this->_timer['user'] as $name => $time) {
$html .= ''.$name.': '. round($time,2).' ms'.$this->getLinebreak();
}
}
if (!Zend_Session::isStarted()){
Zend_Session::start();
}
$request = Zend_Controller_Front::getInstance()->getRequest();
$this_module = $request->getModuleName();
$this_controller = $request->getControllerName();
$this_action = $request->getActionName();
$timerNamespace = new Zend_Session_Namespace('ZFDebug_Time',false);
$timerNamespace->data[$this_module][$this_controller][$this_action][] = round($this->_timer['dispatchLoopShutdown'],2);
$html .= '<h4>Overall Timers</h4>';
foreach ($timerNamespace->data as $module => $controller)
{
if ($module != $this_module) {
continue;
}
$html .= $module . $this->getLinebreak();
$html .= '<div class="pre">';
foreach ($controller as $con => $action)
{
if ($con != $this_controller) {
continue;
}
$html .= ' ' . $con . $this->getLinebreak();
$html .= '<div class="pre">';
foreach ($action as $key => $data)
{
if ($key != $this_action) {
continue;
}
$html .= ' ' . $key . $this->getLinebreak();
$html .= '<div class="pre">';
$html .= ' Avg: ' . $this->_calcAvg($data) . ' ms / '.count($data).' requests'.$this->getLinebreak();
$html .= ' Min: ' . round(min($data), 2) . ' ms'.$this->getLinebreak();
$html .= ' Max: ' . round(max($data), 2) . ' ms'.$this->getLinebreak();
$html .= '</div>';
}
$html .= '</div>';
}
$html .= '</div>';
}
$html .= $this->getLinebreak().'Reset timers by sending ZFDEBUG_RESET as a GET/POST parameter';
return $html;
}
/**
* Sets a time mark identified with $name
*
* @param string $name
*/
public function mark($name) {
if (isset($this->_timer['user'][$name]))
$this->_timer['user'][$name] = (microtime(true)-$_SERVER['REQUEST_TIME'])*1000-$this->_timer['user'][$name];
else
$this->_timer['user'][$name] = (microtime(true)-$_SERVER['REQUEST_TIME'])*1000;
}
#public function routeStartup(Zend_Controller_Request_Abstract $request) {
# $this->timer['routeStartup'] = (microtime(true)-$_SERVER['REQUEST_TIME'])*1000;
#}
#public function routeShutdown(Zend_Controller_Request_Abstract $request) {
# $this->timer['routeShutdown'] = (microtime(true)-$_SERVER['REQUEST_TIME'])*1000;
#}
/**
* Defined by Zend_Controller_Plugin_Abstract
*
* @param Zend_Controller_Request_Abstract
* @return void
*/
public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
{
$reset = Zend_Controller_Front::getInstance()->getRequest()->getParam('ZFDEBUG_RESET');
if (isset($reset)) {
if (!Zend_Session::isStarted()) {
Zend_Session::start();
}
$timerNamespace = new Zend_Session_Namespace('ZFDebug_Time',false);
$timerNamespace->unsetAll();
}
$this->_timer['dispatchLoopStartup'] = (microtime(true)-$_SERVER['REQUEST_TIME'])*1000;
}
/**
* Defined by Zend_Controller_Plugin_Abstract
*
* @param Zend_Controller_Request_Abstract
* @return void
*/
public function dispatchLoopShutdown()
{
$this->_timer['dispatchLoopShutdown'] = (microtime(true)-$_SERVER['REQUEST_TIME'])*1000;
}
/**
* Calculate average time from $array
*
* @param array $array
* @param int $precision
* @return float
*/
protected function _calcAvg(array $array, $precision=2)
{
if (!is_array($array)) {
return 'ERROR in method _calcAvg(): this is a not array';
}
foreach ($array as $value)
if (!is_numeric($value)) {
return 'ERROR in method _calcAvg(): the array contains one or more non-numeric values';
}
$cuantos=count($array);
return round(array_sum($array)/$cuantos,$precision);
}
public function getLinebreak()
{
return '<br'.$this->getClosingBracket();
}
public function getClosingBracket()
{
if (!$this->_closingBracket) {
if ($this->_isXhtml()) {
$this->_closingBracket = ' />';
} else {
$this->_closingBracket = '>';
}
}
return $this->_closingBracket;
}
protected function _isXhtml()
{
$view = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view;
$doctype = $view->doctype();
return $doctype->isXhtml();
}
}

View File

@ -1,104 +0,0 @@
<?php
/**
* ZFDebug Zend Additions
*
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
* @version $Id$
*/
/**
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
*/
class ZFDebug_Controller_Plugin_Debug_Plugin_Variables extends ZFDebug_Controller_Plugin_Debug_Plugin implements ZFDebug_Controller_Plugin_Debug_Plugin_Interface
{
/**
* Contains plugin identifier name
*
* @var string
*/
protected $_identifier = 'variables';
/**
* @var Zend_Controller_Request_Abstract
*/
protected $_request;
/**
* Create ZFDebug_Controller_Plugin_Debug_Plugin_Variables
*
* @return void
*/
public function __construct()
{
}
/**
* Gets identifier for this plugin
*
* @return string
*/
public function getIdentifier()
{
return $this->_identifier;
}
/**
* Returns the base64 encoded icon
*
* @return string
**/
public function getIconData()
{
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAFWSURBVBgZBcE/SFQBAAfg792dppJeEhjZn80MChpqdQ2iscmlscGi1nBPaGkviKKhONSpvSGHcCrBiDDjEhOC0I68sjvf+/V9RQCsLHRu7k0yvtN8MTMPICJieaLVS5IkafVeTkZEFLGy0JndO6vWNGVafPJVh2p8q/lqZl60DpIkaWcpa1nLYtpJkqR1EPVLz+pX4rj47FDbD2NKJ1U+6jTeTRdL/YuNrkLdhhuAZVP6ukqbh7V0TzmtadSEDZXKhhMG7ekZl24jGDLgtwEd6+jbdWAAEY0gKsPO+KPy01+jGgqlUjTK4ZroK/UVKoeOgJ5CpRyq5e2qjhF1laAS8c+Ymk1ZrVXXt2+9+fJBYUwDpZ4RR7Wtf9u9m2tF8Hwi9zJ3/tg5pW2FHVv7eZJHd75TBPD0QuYze7n4Zdv+ch7cfg8UAcDjq7mfwTycew1AEQAAAMB/0x+5JQ3zQMYAAAAASUVORK5CYII=';
}
/**
* Gets menu tab for the Debugbar
*
* @return string
*/
public function getTab()
{
return ' Variables';
}
/**
* Gets content panel for the Debugbar
*
* @return string
*/
public function getPanel()
{
$this->_request = Zend_Controller_Front::getInstance()->getRequest();
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
if ($viewRenderer->view && method_exists($viewRenderer->view, 'getVars')) {
$viewVars = $this->_cleanData($viewRenderer->view->getVars());
} else {
$viewVars = "No 'getVars()' method in view class";
}
$vars = '';
if ($this->_request->isPost())
{
$vars .= '<h4>$_POST</h4>'
. '<div id="ZFDebug_post">' . $this->_cleanData($this->_request->getPost()) . '</div>';
}
$vars .= '<h4>$_COOKIE</h4>'
. '<div id="ZFDebug_cookie">' . $this->_cleanData($this->_request->getCookie()) . '</div>'
. '<h4>Request</h4>'
. '<div id="ZFDebug_requests">' . $this->_cleanData($this->_request->getParams()) . '</div>'
. '<h4>View vars</h4>'
. '<div id="ZFDebug_vars">' . $viewVars . '</div>';
return $vars;
}
}

View File

@ -1,198 +0,0 @@
<?php
/*
* $Id: BuildEvent.php 905 2010-10-05 16:28:03Z mrook $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
require_once 'phing/system/lang/EventObject.php';
/**
* Encapsulates a build specific event.
*
* <p>We have three sources of events all handled by this class:
*
* <ul>
* <li>Project level events</li>
* <li>Target level events</li>
* <li>Task level events</li>
* </ul>
*
* <p> Events are all fired from the project class by creating an event object
* using this class and passing it to the listeners.
*
* @author Andreas Aderhold <andi@binarycloud.com>
* @author Hans Lellelid <hans@xmpl.org>
* @version $Revision: 905 $
* @package phing
*/
class BuildEvent extends EventObject {
/**
* A reference to the project
* @var Project
*/
protected $project;
/**
* A reference to the target
* @var Target
*/
protected $target;
/**
* A reference to the task
*
* @var Task
*/
protected $task;
/**
* The message of this event, if the event is a message
* @var string
*/
protected $message = null;
/**
* The priority of the message
*
* @var string
* @see $message
*/
protected $priority = Project::MSG_VERBOSE;
/**
* The execption that caused the event, if any
*
* @var object
*/
protected $exception = null;
/**
* Construct a BuildEvent for a project, task or target source event
*
* @param object project the project that emitted the event.
*/
public function __construct($source) {
parent::__construct($source);
if ($source instanceof Project) {
$this->project = $source;
$this->target = null;
$this->task = null;
} elseif ($source instanceof Target) {
$this->project = $source->getProject();
$this->target = $source;
$this->task = null;
} elseif ($source instanceof Task) {
$this->project = $source->getProject();
$this->target = $source->getOwningTarget();
$this->task = $source;
} else {
throw new Exception("Can not construct BuildEvent, unknown source given.");
}
}
/**
* Sets the message with details and the message priority for this event.
*
* @param string The string message of the event
* @param integer The priority this message should have
*/
public function setMessage($message, $priority) {
$this->message = (string) $message;
$this->priority = (int) $priority;
}
/**
* Set the exception that was the cause of this event.
*
* @param Exception The exception that caused the event
*/
public function setException($exception) {
$this->exception = $exception;
}
/**
* Returns the project instance that fired this event.
*
* The reference to the project instance is set by the constructor if this
* event was fired from the project class.
*
* @return Project The project instance that fired this event
*/
public function getProject() {
return $this->project;
}
/**
* Returns the target instance that fired this event.
*
* The reference to the target instance is set by the constructor if this
* event was fired from the target class.
*
* @return Target The target that fired this event
*/
public function getTarget() {
return $this->target;
}
/**
* Returns the target instance that fired this event.
*
* The reference to the task instance is set by the constructor if this
* event was fired within a task.
*
* @return Task The task that fired this event
*/
public function getTask() {
return $this->task;
}
/**
* Returns the logging message. This field will only be set for
* "messageLogged" events.
*
* @return string The log message
*/
function getMessage() {
return $this->message;
}
/**
* Returns the priority of the logging message. This field will only
* be set for "messageLogged" events.
*
* @return integer The message priority
*/
function getPriority() {
return $this->priority;
}
/**
* Returns the exception that was thrown, if any.
* This field will only be set for "taskFinished", "targetFinished", and
* "buildFinished" events.
*
* @see BuildListener::taskFinished()
* @see BuildListener::targetFinished()
* @see BuildListener::buildFinished()
* @return Exception
*/
public function getException() {
return $this->exception;
}
}

View File

@ -1,121 +0,0 @@
<?php
/*
* $Id: BuildException.php 905 2010-10-05 16:28:03Z mrook $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
/**
* BuildException is for when things go wrong in a build execution.
*
* @author Andreas Aderhold <andi@binarycloud.com>
* @version $Revision: 905 $
* @package phing
*/
class BuildException extends Exception {
/**
* Location in the xml file.
* @var Location
*/
protected $location;
/**
* The nested "cause" exception.
* @var Exception
*/
protected $cause;
/**
* Construct a BuildException.
* Supported signatures:
* throw new BuildException($causeExc);
* throw new BuildException($msg);
* throw new Buildexception($causeExc, $loc);
* throw new BuildException($msg, $causeExc);
* throw new BuildException($msg, $loc);
* throw new BuildException($msg, $causeExc, $loc);
*/
function __construct($p1, $p2 = null, $p3 = null) {
$cause = null;
$loc = null;
$msg = "";
if ($p3 !== null) {
$cause = $p2;
$loc = $p3;
$msg = $p1;
} elseif ($p2 !== null) {
if ($p2 instanceof Exception) {
$cause = $p2;
$msg = $p1;
} elseif ($p2 instanceof Location) {
$loc = $p2;
if ($p1 instanceof Exception) {
$cause = $p1;
} else {
$msg = $p1;
}
}
} elseif ($p1 instanceof Exception) {
$cause = $p1;
} else {
$msg = $p1;
}
parent::__construct($msg);
if ($cause !== null) {
$this->cause = $cause;
$this->message .= " [wrapped: " . $cause->getMessage() ."]";
}
if ($loc !== null) {
$this->setLocation($loc);
}
}
/**
* Gets the cause exception.
*
* @return Exception
*/
public function getCause() {
return $this->cause;
}
/**
* Gets the location of error in XML file.
*
* @return Location
*/
public function getLocation() {
return $this->location;
}
/**
* Sets the location of error in XML file.
*
* @param Locaiton $loc
*/
public function setLocation(Location $loc) {
$this->location = $loc;
$this->message = $loc->toString() . ': ' . $this->message;
}
}

View File

@ -1,91 +0,0 @@
<?php
/*
* $Id: BuildListener.php 905 2010-10-05 16:28:03Z mrook $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
/**
* Interface for build listeners.
*
* Classes that implement a listener must extend this class and (faux)implement
* all methods that are decleard as dummies below.
*
* @author Andreas Aderhold <andi@binarycloud.com>
* @author Hans Lellelid <hans@xmpl.org>
* @version $Revision: 905 $
* @see BuildEvent
* @see Project::addBuildListener()
* @package phing
*/
interface BuildListener {
/**
* Fired before any targets are started.
*
* @param BuildEvent The BuildEvent
*/
function buildStarted(BuildEvent $event);
/**
* Fired after the last target has finished.
*
* @param BuildEvent The BuildEvent
* @see BuildEvent::getException()
*/
function buildFinished(BuildEvent $event);
/**
* Fired when a target is started.
*
* @param BuildEvent The BuildEvent
* @see BuildEvent::getTarget()
*/
function targetStarted(BuildEvent $event);
/**
* Fired when a target has finished.
*
* @param BuildEvent The BuildEvent
* @see BuildEvent#getException()
*/
function targetFinished(BuildEvent $event);
/**
* Fired when a task is started.
*
* @param BuildEvent The BuildEvent
* @see BuildEvent::getTask()
*/
function taskStarted(BuildEvent $event);
/**
* Fired when a task has finished.
*
* @param BuildEvent The BuildEvent
* @see BuildEvent::getException()
*/
function taskFinished(BuildEvent $event);
/**
* Fired whenever a message is logged.
*
* @param BuildEvent The BuildEvent
* @see BuildEvent::getMessage()
*/
function messageLogged(BuildEvent $event);
}

View File

@ -1,70 +0,0 @@
<?php
/*
* $Id: BuildLogger.php 905 2010-10-05 16:28:03Z mrook $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
require_once 'phing/BuildListener.php';
/**
* Interface for build loggers.
*
* Build loggers are build listeners but with some additional functionality:
* - They can be configured with a log level (below which they will ignore messages)
* - They have error and output streams
*
* Classes that implement a listener must implement this interface.
*
* @author Hans Lellelid <hans@xmpl.org>
* @version $Revision: 905 $
* @see BuildEvent
* @see Project::addBuildListener()
* @package phing
*/
interface BuildLogger extends BuildListener {
/**
* Sets the min log level that this logger should respect.
*
* Messages below this level are ignored.
*
* Constants for the message levels are in Project.php. The order of
* the levels, from least to most verbose, is:
* - Project::MSG_ERR
* - Project::MSG_WARN
* - Project::MSG_INFO
* - Project::MSG_VERBOSE
* - Project::MSG_DEBUG
*
* @param int $level The log level integer (e.g. Project::MSG_VERBOSE, etc.).
*/
public function setMessageOutputLevel($level);
/**
* Sets the standard output stream to use.
* @param OutputStream $output Configured output stream (e.g. STDOUT) for standard output.
*/
public function setOutputStream(OutputStream $output);
/**
* Sets the output stream to use for errors.
* @param OutputStream $err Configured output stream (e.g. STDERR) for errors.
*/
public function setErrorStream(OutputStream $err);
}

View File

@ -1,83 +0,0 @@
<?php
/*
* $Id: ConfigurationException.php 905 2010-10-05 16:28:03Z mrook $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
/**
* ConfigurationException is thrown by Phing during the configuration and setup phase of the project.
*
* @author Hans Lellelid <hans@xmpl.org>
* @version $Revision: 905 $
* @package phing
*/
class ConfigurationException extends Exception {
/**
* Location in the xml file.
* @var Location
*/
protected $location;
/**
* The nested "cause" exception.
* @var Exception
*/
protected $cause;
/**
* Construct a BuildException.
* Supported signatures:
* throw new BuildException($causeExc);
* throw new BuildException($msg);
* throw new BuildException($msg, $causeExc);
*/
function __construct($p1, $p2 = null, $p3 = null) {
$cause = null;
$msg = "";
if ($p2 !== null) {
if ($p2 instanceof Exception) {
$cause = $p2;
$msg = $p1;
}
} elseif ($p1 instanceof Exception) {
$cause = $p1;
} else {
$msg = $p1;
}
parent::__construct($msg);
if ($cause !== null) {
$this->cause = $cause;
$this->message .= " [wrapped: " . $cause->getMessage() ."]";
}
}
/**
* Gets the cause exception.
*
* @return Exception
*/
public function getCause() {
return $this->cause;
}
}

View File

@ -1,538 +0,0 @@
<?php
/*
* $Id: IntrospectionHelper.php 905 2010-10-05 16:28:03Z mrook $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
include_once 'phing/types/Reference.php';
include_once 'phing/types/Path.php';
include_once 'phing/util/StringHelper.php';
/**
* Helper class that collects the methods that a task or nested element
* holds to set attributes, create nested elements or hold PCDATA
* elements.
*
*<ul>
* <li><strong>SMART-UP INLINE DOCS</strong></li>
* <li><strong>POLISH-UP THIS CLASS</strong></li>
*</ul>
*
* @author Andreas Aderhold <andi@binarycloud.com>
* @author Hans Lellelid <hans@xmpl.org>
* @copyright © 2001,2002 THYRELL. All rights reserved
* @version $Revision: 905 $
* @package phing
*/
class IntrospectionHelper {
/**
* Holds the attribute setter methods.
*
* @var array string[]
*/
private $attributeSetters = array();
/**
* Holds methods to create nested elements.
*
* @var array string[]
*/
private $nestedCreators = array();
/**
* Holds methods to store configured nested elements.
*
* @var array string[]
*/
private $nestedStorers = array();
/**
* Map from attribute names to nested types.
*/
private $nestedTypes = array();
/**
* New idea in phing: any class can register certain
* keys -- e.g. "task.current_file" -- which can be used in
* task attributes, if supported. In the build XML these
* are referred to like this:
* <regexp pattern="\n" replace="%{task.current_file}"/>
* In the type/task a listener method must be defined:
* function setListeningReplace($slot) {}
* @var array string[]
*/
private $slotListeners = array();
/**
* The method to add PCDATA stuff.
*
* @var string Method name of the addText (redundant?) method, if class supports it :)
*/
private $methodAddText = null;
/**
* The Class that's been introspected.
*
* @var object
* @access private
*/
private $bean;
/**
* The cache of IntrospectionHelper classes instantiated by getHelper().
* @var array IntrospectionHelpers[]
*/
private static $helpers = array();
/**
* Factory method for helper objects.
*
* @param string $class The class to create a Helper for
*/
public static function getHelper($class) {
if (!isset(self::$helpers[$class])) {
self::$helpers[$class] = new IntrospectionHelper($class);
}
return self::$helpers[$class];
}
/**
* This function constructs a new introspection helper for a specific class.
*
* This method loads all methods for the specified class and categorizes them
* as setters, creators, slot listeners, etc. This way, the setAttribue() doesn't
* need to perform any introspection -- either the requested attribute setter/creator
* exists or it does not & a BuildException is thrown.
*
* @param string $bean The classname for this IH.
*/
function __construct($class) {
$this->bean = new ReflectionClass($class);
//$methods = get_class_methods($bean);
foreach($this->bean->getMethods() as $method) {
if ($method->isPublic()) {
// We're going to keep case-insensitive method names
// for as long as we're allowed :) It makes it much
// easier to map XML attributes to PHP class method names.
$name = strtolower($method->getName());
// There are a few "reserved" names that might look like attribute setters
// but should actually just be skipped. (Note: this means you can't ever
// have an attribute named "location" or "tasktype" or a nested element named "task".)
if ($name === "setlocation" || $name === "settasktype" || $name === "addtask") {
continue;
}
if ($name === "addtext") {
$this->methodAddText = $method;
} elseif (strpos($name, "setlistening") === 0) {
// Phing supports something unique called "RegisterSlots"
// These are dynamic values that use a basic slot system so that
// classes can register to listen to specific slots, and the value
// will always be grabbed from the slot (and never set in the project
// component). This is useful for things like tracking the current
// file being processed by a filter (e.g. AppendTask sets an append.current_file
// slot, which can be ready by the XSLTParam type.)
if (count($method->getParameters()) !== 1) {
throw new BuildException($method->getDeclaringClass()->getName()."::".$method->getName()."() must take exactly one parameter.");
}
$this->slotListeners[$name] = $method;
} elseif (strpos($name, "set") === 0) {
// A standard attribute setter.
if (count($method->getParameters()) !== 1) {
throw new BuildException($method->getDeclaringClass()->getName()."::".$method->getName()."() must take exactly one parameter.");
}
$this->attributeSetters[$name] = $method;
} elseif (strpos($name, "create") === 0) {
if (count($method->getParameters()) > 0) {
throw new BuildException($method->getDeclaringClass()->getName()."::".$method->getName()."() may not take any parameters.");
}
// Because PHP doesn't support return types, we are going to do
// two things here to guess return type:
// 1) parse comments for an explicit value
// 2) if that fails, assume that the part of the method after "create"
// is the name of the return type (in many cases it is not)
// This isn't super important -- i.e. we're not instantaiting classes
// based on this information. It's more just so that IntrospectionHelper
// can keep track of all the nested types -- and provide more helpful
// exception messages, etc.
preg_match('/@return[\s]+([\w]+)/', $method->getDocComment(), $matches);
if (!empty($matches[1]) && class_exists($matches[1], false)) {
$this->nestedTypes[$name] = $matches[1];
} else {
// assume that method createEquals() creates object of type "Equals"
// (that example would be false, of course)
$this->nestedTypes[$name] = $this->getPropertyName($name, "create");
}
$this->nestedCreators[$name] = $method;
} elseif (strpos($name, "addconfigured") === 0) {
// *must* use class hints if using addConfigured ...
// 1 param only
$params = $method->getParameters();
if (count($params) < 1) {
throw new BuildException($method->getDeclaringClass()->getName()."::".$method->getName()."() must take at least one parameter.");
}
if (count($params) > 1) {
$this->warn($method->getDeclaringClass()->getName()."::".$method->getName()."() takes more than one parameter. (IH only uses the first)");
}
$classname = null;
if (($hint = $params[0]->getClass()) !== null) {
$classname = $hint->getName();
}
if ($classname === null) {
throw new BuildException($method->getDeclaringClass()->getName()."::".$method->getName()."() method MUST use a class hint to indicate the class type of parameter.");
}
$this->nestedTypes[$name] = $classname;
$this->nestedStorers[$name] = $method;
} elseif (strpos($name, "add") === 0) {
// *must* use class hints if using add ...
// 1 param only
$params = $method->getParameters();
if (count($params) < 1) {
throw new BuildException($method->getDeclaringClass()->getName()."::".$method->getName()."() must take at least one parameter.");
}
if (count($params) > 1) {
$this->warn($method->getDeclaringClass()->getName()."::".$method->getName()."() takes more than one parameter. (IH only uses the first)");
}
$classname = null;
if (($hint = $params[0]->getClass()) !== null) {
$classname = $hint->getName();
}
// we don't use the classname here, but we need to make sure it exists before
// we later try to instantiate a non-existant class
if ($classname === null) {
throw new BuildException($method->getDeclaringClass()->getName()."::".$method->getName()."() method MUST use a class hint to indicate the class type of parameter.");
}
$this->nestedCreators[$name] = $method;
}
} // if $method->isPublic()
} // foreach
}
/** Sets the named attribute. */
function setAttribute(Project $project, $element, $attributeName, &$value) {
// we want to check whether the value we are setting looks like
// a slot-listener variable: %{task.current_file}
//
// slot-listener variables are not like properties, in that they cannot be mixed with
// other text values. The reason for this disparity is that properties are only
// set when first constructing objects from XML, whereas slot-listeners are always dynamic.
//
// This is made possible by PHP5 (objects automatically passed by reference) and PHP's loose
// typing.
if (StringHelper::isSlotVar($value)) {
$as = "setlistening" . strtolower($attributeName);
if (!isset($this->slotListeners[$as])) {
$msg = $this->getElementName($project, $element) . " doesn't support a slot-listening '$attributeName' attribute.";
throw new BuildException($msg);
}
$method = $this->slotListeners[$as];
$key = StringHelper::slotVar($value);
$value = Register::getSlot($key); // returns a RegisterSlot object which will hold current value of that register (accessible using getValue())
} else {
// Traditional value options
$as = "set".strtolower($attributeName);
if (!isset($this->attributeSetters[$as])) {
$msg = $this->getElementName($project, $element) . " doesn't support the '$attributeName' attribute.";
throw new BuildException($msg);
}
$method = $this->attributeSetters[$as];
if ($as == "setrefid") {
$value = new Reference($value);
} else {
// value is a string representation of a boolean type,
// convert it to primitive
if (StringHelper::isBoolean($value)) {
$value = StringHelper::booleanValue($value);
}
// does method expect a PhingFile object? if so, then
// pass a project-relative file.
$params = $method->getParameters();
$classname = null;
if (($hint = $params[0]->getClass()) !== null) {
$classname = $hint->getName();
}
// there should only be one param; we'll just assume ....
if ($classname !== null) {
switch(strtolower($classname)) {
case "phingfile":
$value = $project->resolveFile($value);
break;
case "path":
$value = new Path($project, $value);
break;
case "reference":
$value = new Reference($value);
break;
// any other object params we want to support should go here ...
}
} // if hint !== null
} // if not setrefid
} // if is slot-listener
try {
$project->log(" -calling setter ".$method->getDeclaringClass()->getName()."::".$method->getName()."()", Project::MSG_DEBUG);
$method->invoke($element, $value);
} catch(Exception $exc) {
throw new BuildException($exc);
}
}
/** Adds PCDATA areas.*/
function addText(Project $project, $element, $text) {
if ($this->methodAddText === null) {
$msg = $this->getElementName($project, $element)." doesn't support nested text data.";
throw new BuildException($msg);
}
try {
$method = $this->methodAddText;
$method->invoke($element, $text);
} catch (Exception $exc) {
throw new BuildException($exc);
}
}
/**
* Creates a named nested element.
*
* Valid creators can be in the form createFoo() or addFoo(Bar).
* @return object Returns the nested element.
* @throws BuildException
*/
function createElement(Project $project, $element, $elementName) {
$addMethod = "add".strtolower($elementName);
$createMethod = "create".strtolower($elementName);
$nestedElement = null;
if (isset($this->nestedCreators[$createMethod])) {
$method = $this->nestedCreators[$createMethod];
try { // try to invoke the creator method on object
$project->log(" -calling creator ".$method->getDeclaringClass()->getName()."::".$method->getName()."()", Project::MSG_DEBUG);
$nestedElement = $method->invoke($element);
} catch (Exception $exc) {
throw new BuildException($exc);
}
} elseif (isset($this->nestedCreators[$addMethod])) {
$method = $this->nestedCreators[$addMethod];
// project components must use class hints to support the add methods
try { // try to invoke the adder method on object
$project->log(" -calling adder ".$method->getDeclaringClass()->getName()."::".$method->getName()."()", Project::MSG_DEBUG);
// we've already assured that correct num of params
// exist and that method is using class hints
$params = $method->getParameters();
$classname = null;
if (($hint = $params[0]->getClass()) !== null) {
$classname = $hint->getName();
}
// create a new instance of the object and add it via $addMethod
$nestedElement = new $classname();
$method->invoke($element, $nestedElement);
} catch (Exception $exc) {
throw new BuildException($exc);
}
} else {
$msg = $this->getElementName($project, $element) . " doesn't support the '$elementName' creator/adder.";
throw new BuildException($msg);
}
if ($nestedElement instanceof ProjectComponent) {
$nestedElement->setProject($project);
}
return $nestedElement;
}
/**
* Creates a named nested element.
* @return void
* @throws BuildException
*/
function storeElement($project, $element, $child, $elementName = null) {
if ($elementName === null) {
return;
}
$storer = "addconfigured".strtolower($elementName);
if (isset($this->nestedStorers[$storer])) {
$method = $this->nestedStorers[$storer];
try {
$project->log(" -calling storer ".$method->getDeclaringClass()->getName()."::".$method->getName()."()", Project::MSG_DEBUG);
$method->invoke($element, $child);
} catch (Exception $exc) {
throw new BuildException($exc);
}
}
}
/** Does the introspected class support PCDATA? */
function supportsCharacters() {
return ($this->methodAddText !== null);
}
/** Return all attribues supported by the introspected class. */
function getAttributes() {
$attribs = array();
foreach (array_keys($this->attributeSetters) as $setter) {
$attribs[] =$this->getPropertyName($setter, "set");
}
return $attribs;
}
/** Return all nested elements supported by the introspected class. */
function getNestedElements() {
return $this->nestedTypes;
}
/**
* Get the the name for an element.
* When possible the full classnam (phing.tasks.system.PropertyTask) will
* be returned. If not available (loaded in taskdefs or typedefs) then the
* XML element name will be returned.
*
* @param Project $project
* @param object $element The Task or type element.
* @return string Fully qualified class name of element when possible.
*/
function getElementName(Project $project, $element) {
$taskdefs = $project->getTaskDefinitions();
$typedefs = $project->getDataTypeDefinitions();
// check if class of element is registered with project (tasks & types)
// most element types don't have a getTag() method
$elClass = get_class($element);
if (!in_array('getTag', get_class_methods($elClass))) {
// loop through taskdefs and typesdefs and see if the class name
// matches (case-insensitive) any of the classes in there
foreach(array_merge($taskdefs, $typedefs) as $elName => $class) {
if (0 === strcasecmp($elClass, StringHelper::unqualify($class))) {
return $class;
}
}
return "$elClass (unknown)";
} else {
// ->getTag() method does exist, so use it
$elName = $element->getTag();
if (isset($taskdefs[$elName])) {
return $taskdefs[$elName];
} elseif (isset($typedefs[$elName])) {
return $typedefs[$elName];
} else {
return "$elName (unknown)";
}
}
}
/** extract the name of a property from a method name - subtracting a given prefix. */
function getPropertyName($methodName, $prefix) {
$start = strlen($prefix);
return strtolower(substr($methodName, $start));
}
/**
* Prints warning message to screen if -debug was used.
*/
function warn($msg) {
if (Phing::getMsgOutputLevel() === Project::MSG_DEBUG) {
print("[IntrospectionHelper] " . $msg . "\n");
}
}
}

View File

@ -1,165 +0,0 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.

File diff suppressed because it is too large Load Diff

View File

@ -1,999 +0,0 @@
<?php
/*
* $Id: Project.php 905 2010-10-05 16:28:03Z mrook $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
include_once 'phing/system/io/PhingFile.php';
include_once 'phing/util/FileUtils.php';
include_once 'phing/TaskAdapter.php';
include_once 'phing/util/StringHelper.php';
include_once 'phing/BuildEvent.php';
include_once 'phing/input/DefaultInputHandler.php';
/**
* The Phing project class. Represents a completely configured Phing project.
* The class defines the project and all tasks/targets. It also contains
* methods to start a build as well as some properties and FileSystem
* abstraction.
*
* @author Andreas Aderhold <andi@binarycloud.com>
* @author Hans Lellelid <hans@xmpl.org>
* @version $Revision: 905 $
* @package phing
*/
class Project {
// Logging level constants.
const MSG_DEBUG = 4;
const MSG_VERBOSE = 3;
const MSG_INFO = 2;
const MSG_WARN = 1;
const MSG_ERR = 0;
/** contains the targets */
private $targets = array();
/** global filterset (future use) */
private $globalFilterSet = array();
/** all globals filters (future use) */
private $globalFilters = array();
/** Project properties map (usually String to String). */
private $properties = array();
/**
* Map of "user" properties (as created in the Ant task, for example).
* Note that these key/value pairs are also always put into the
* project properties, so only the project properties need to be queried.
* Mapping is String to String.
*/
private $userProperties = array();
/**
* Map of inherited "user" properties - that are those "user"
* properties that have been created by tasks and not been set
* from the command line or a GUI tool.
* Mapping is String to String.
*/
private $inheritedProperties = array();
/** task definitions for this project*/
private $taskdefs = array();
/** type definitions for this project */
private $typedefs = array();
/** holds ref names and a reference to the referred object*/
private $references = array();
/** The InputHandler being used by this project. */
private $inputHandler;
/* -- properties that come in via xml attributes -- */
/** basedir (PhingFile object) */
private $basedir;
/** the default target name */
private $defaultTarget = 'all';
/** project name (required) */
private $name;
/** project description */
private $description;
/** require phing version */
private $phingVersion;
/** a FileUtils object */
private $fileUtils;
/** Build listeneers */
private $listeners = array();
/**
* Constructor, sets any default vars.
*/
function __construct() {
$this->fileUtils = new FileUtils();
$this->inputHandler = new DefaultInputHandler();
}
/**
* Sets the input handler
*/
public function setInputHandler(InputHandler $handler) {
$this->inputHandler = $handler;
}
/**
* Retrieves the current input handler.
*/
public function getInputHandler() {
return $this->inputHandler;
}
/** inits the project, called from main app */
function init() {
// set builtin properties
$this->setSystemProperties();
// load default tasks
$taskdefs = Phing::getResourcePath("phing/tasks/defaults.properties");
try { // try to load taskdefs
$props = new Properties();
$in = new PhingFile((string)$taskdefs);
if ($in === null) {
throw new BuildException("Can't load default task list");
}
$props->load($in);
$enum = $props->propertyNames();
foreach($enum as $key) {
$value = $props->getProperty($key);
$this->addTaskDefinition($key, $value);
}
} catch (IOException $ioe) {
throw new BuildException("Can't load default task list");
}
// load default tasks
$typedefs = Phing::getResourcePath("phing/types/defaults.properties");
try { // try to load typedefs
$props = new Properties();
$in = new PhingFile((string)$typedefs);
if ($in === null) {
throw new BuildException("Can't load default datatype list");
}
$props->load($in);
$enum = $props->propertyNames();
foreach($enum as $key) {
$value = $props->getProperty($key);
$this->addDataTypeDefinition($key, $value);
}
} catch(IOException $ioe) {
throw new BuildException("Can't load default datatype list");
}
}
/** returns the global filterset (future use) */
function getGlobalFilterSet() {
return $this->globalFilterSet;
}
// ---------------------------------------------------------
// Property methods
// ---------------------------------------------------------
/**
* Sets a property. Any existing property of the same name
* is overwritten, unless it is a user property.
* @param string $name The name of property to set.
* Must not be <code>null</code>.
* @param string $value The new value of the property.
* Must not be <code>null</code>.
* @return void
*/
public function setProperty($name, $value) {
// command line properties take precedence
if (isset($this->userProperties[$name])) {
$this->log("Override ignored for user property " . $name, Project::MSG_VERBOSE);
return;
}
if (isset($this->properties[$name])) {
$this->log("Overriding previous definition of property " . $name, Project::MSG_VERBOSE);
}
$this->log("Setting project property: " . $name . " -> " . $value, Project::MSG_DEBUG);
$this->properties[$name] = $value;
}
/**
* Sets a property if no value currently exists. If the property
* exists already, a message is logged and the method returns with
* no other effect.
*
* @param string $name The name of property to set.
* Must not be <code>null</code>.
* @param string $value The new value of the property.
* Must not be <code>null</code>.
* @since 2.0
*/
public function setNewProperty($name, $value) {
if (isset($this->properties[$name])) {
$this->log("Override ignored for property " . $name, Project::MSG_DEBUG);
return;
}
$this->log("Setting project property: " . $name . " -> " . $value, Project::MSG_DEBUG);
$this->properties[$name] = $value;
}
/**
* Sets a user property, which cannot be overwritten by
* set/unset property calls. Any previous value is overwritten.
* @param string $name The name of property to set.
* Must not be <code>null</code>.
* @param string $value The new value of the property.
* Must not be <code>null</code>.
* @see #setProperty()
*/
public function setUserProperty($name, $value) {
$this->log("Setting ro project property: " . $name . " -> " . $value, Project::MSG_DEBUG);
$this->userProperties[$name] = $value;
$this->properties[$name] = $value;
}
/**
* Sets a user property, which cannot be overwritten by set/unset
* property calls. Any previous value is overwritten. Also marks
* these properties as properties that have not come from the
* command line.
*
* @param string $name The name of property to set.
* Must not be <code>null</code>.
* @param string $value The new value of the property.
* Must not be <code>null</code>.
* @see #setProperty()
*/
public function setInheritedProperty($name, $value) {
$this->inheritedProperties[$name] = $value;
$this->setUserProperty($name, $value);
}
/**
* Sets a property unless it is already defined as a user property
* (in which case the method returns silently).
*
* @param name The name of the property.
* Must not be <code>null</code>.
* @param value The property value. Must not be <code>null</code>.
*/
private function setPropertyInternal($name, $value) {
if (isset($this->userProperties[$name])) {
$this->log("Override ignored for user property " . $name, Project::MSG_VERBOSE);
return;
}
$this->properties[$name] = $value;
}
/**
* Returns the value of a property, if it is set.
*
* @param string $name The name of the property.
* May be <code>null</code>, in which case
* the return value is also <code>null</code>.
* @return string The property value, or <code>null</code> for no match
* or if a <code>null</code> name is provided.
*/
public function getProperty($name) {
if (!isset($this->properties[$name])) {
return null;
}
$found = $this->properties[$name];
// check to see if there are unresolved property references
if (false !== strpos($found, '${')) {
// attempt to resolve properties
$found = $this->replaceProperties($found);
// save resolved value
$this->properties[$name] = $found;
}
return $found;
}
/**
* Replaces ${} style constructions in the given value with the
* string value of the corresponding data types.
*
* @param value The string to be scanned for property references.
* May be <code>null</code>.
*
* @return the given string with embedded property names replaced
* by values, or <code>null</code> if the given string is
* <code>null</code>.
*
* @exception BuildException if the given value has an unclosed
* property name, e.g. <code>${xxx</code>
*/
public function replaceProperties($value) {
return ProjectConfigurator::replaceProperties($this, $value, $this->properties);
}
/**
* Returns the value of a user property, if it is set.
*
* @param string $name The name of the property.
* May be <code>null</code>, in which case
* the return value is also <code>null</code>.
* @return string The property value, or <code>null</code> for no match
* or if a <code>null</code> name is provided.
*/
public function getUserProperty($name) {
if (!isset($this->userProperties[$name])) {
return null;
}
return $this->userProperties[$name];
}
/**
* Returns a copy of the properties table.
* @return array A hashtable containing all properties
* (including user properties).
*/
public function getProperties() {
return $this->properties;
}
/**
* Returns a copy of the user property hashtable
* @return a hashtable containing just the user properties
*/
public function getUserProperties() {
return $this->userProperties;
}
/**
* Copies all user properties that have been set on the command
* line or a GUI tool from this instance to the Project instance
* given as the argument.
*
* <p>To copy all "user" properties, you will also have to call
* {@link #copyInheritedProperties copyInheritedProperties}.</p>
*
* @param Project $other the project to copy the properties to. Must not be null.
* @return void
* @since phing 2.0
*/
public function copyUserProperties(Project $other) {
foreach($this->userProperties as $arg => $value) {
if (isset($this->inheritedProperties[$arg])) {
continue;
}
$other->setUserProperty($arg, $value);
}
}
/**
* Copies all user properties that have not been set on the
* command line or a GUI tool from this instance to the Project
* instance given as the argument.
*
* <p>To copy all "user" properties, you will also have to call
* {@link #copyUserProperties copyUserProperties}.</p>
*
* @param other the project to copy the properties to. Must not be null.
*
* @since phing 2.0
*/
public function copyInheritedProperties(Project $other) {
foreach($this->userProperties as $arg => $value) {
if ($other->getUserProperty($arg) !== null) {
continue;
}
$other->setInheritedProperty($arg, $value);
}
}
// ---------------------------------------------------------
// END Properties methods
// ---------------------------------------------------------
function setDefaultTarget($targetName) {
$this->defaultTarget = (string) trim($targetName);
}
function getDefaultTarget() {
return (string) $this->defaultTarget;
}
/**
* Sets the name of the current project
*
* @param string name of project
* @return void
* @access public
* @author Andreas Aderhold, andi@binarycloud.com
*/
function setName($name) {
$this->name = (string) trim($name);
$this->setProperty("phing.project.name", $this->name);
}
/**
* Returns the name of this project
*
* @returns string projectname
* @access public
* @author Andreas Aderhold, andi@binarycloud.com
*/
function getName() {
return (string) $this->name;
}
/** Set the projects description */
function setDescription($description) {
$this->description = (string) trim($description);
}
/** return the description, null otherwise */
function getDescription() {
return $this->description;
}
/** Set the minimum required phing version **/
function setPhingVersion($version) {
$version = str_replace('phing', '', strtolower($version));
$this->phingVersion = (string)trim($version);
}
/** Get the minimum required phing version **/
function getPhingVersion() {
if($this->phingVersion === null) {
$this->setPhingVersion(Phing::getPhingVersion());
}
return $this->phingVersion;
}
/** Set basedir object from xml*/
function setBasedir($dir) {
if ($dir instanceof PhingFile) {
$dir = $dir->getAbsolutePath();
}
$dir = $this->fileUtils->normalize($dir);
$dir = new PhingFile((string) $dir);
if (!$dir->exists()) {
throw new BuildException("Basedir ".$dir->getAbsolutePath()." does not exist");
}
if (!$dir->isDirectory()) {
throw new BuildException("Basedir ".$dir->getAbsolutePath()." is not a directory");
}
$this->basedir = $dir;
$this->setPropertyInternal("project.basedir", $this->basedir->getAbsolutePath());
$this->log("Project base dir set to: " . $this->basedir->getPath(), Project::MSG_VERBOSE);
// [HL] added this so that ./ files resolve correctly. This may be a mistake ... or may be in wrong place.
chdir($dir->getAbsolutePath());
}
/**
* Returns the basedir of this project
*
* @returns PhingFile Basedir PhingFile object
* @access public
* @throws BuildException
* @author Andreas Aderhold, andi@binarycloud.com
*/
function getBasedir() {
if ($this->basedir === null) {
try { // try to set it
$this->setBasedir(".");
} catch (BuildException $exc) {
throw new BuildException("Can not set default basedir. ".$exc->getMessage());
}
}
return $this->basedir;
}
/**
* Sets system properties and the environment variables for this project.
*
* @return void
*/
function setSystemProperties() {
// first get system properties
$systemP = array_merge( self::getProperties(), Phing::getProperties() );
foreach($systemP as $name => $value) {
$this->setPropertyInternal($name, $value);
}
// and now the env vars
foreach($_SERVER as $name => $value) {
// skip arrays
if (is_array($value)) {
continue;
}
$this->setPropertyInternal('env.' . $name, $value);
}
return true;
}
/**
* Adds a task definition.
* @param string $name Name of tag.
* @param string $class The class path to use.
* @param string $classpath The classpat to use.
*/
function addTaskDefinition($name, $class, $classpath = null) {
$name = $name;
$class = $class;
if ($class === "") {
$this->log("Task $name has no class defined.", Project::MSG_ERR);
} elseif (!isset($this->taskdefs[$name])) {
Phing::import($class, $classpath);
$this->taskdefs[$name] = $class;
$this->log(" +Task definiton: $name ($class)", Project::MSG_DEBUG);
} else {
$this->log("Task $name ($class) already registerd, skipping", Project::MSG_VERBOSE);
}
}
function &getTaskDefinitions() {
return $this->taskdefs;
}
/**
* Adds a data type definition.
* @param string $name Name of tag.
* @param string $class The class path to use.
* @param string $classpath The classpat to use.
*/
function addDataTypeDefinition($typeName, $typeClass, $classpath = null) {
if (!isset($this->typedefs[$typeName])) {
Phing::import($typeClass, $classpath);
$this->typedefs[$typeName] = $typeClass;
$this->log(" +User datatype: $typeName ($typeClass)", Project::MSG_DEBUG);
} else {
$this->log("Type $typeName ($typeClass) already registerd, skipping", Project::MSG_VERBOSE);
}
}
function getDataTypeDefinitions() {
return $this->typedefs;
}
/** add a new target to the project */
function addTarget($targetName, &$target) {
if (isset($this->targets[$targetName])) {
throw new BuildException("Duplicate target: $targetName");
}
$this->addOrReplaceTarget($targetName, $target);
}
function addOrReplaceTarget($targetName, &$target) {
$this->log(" +Target: $targetName", Project::MSG_DEBUG);
$target->setProject($this);
$this->targets[$targetName] = $target;
$ctx = $this->getReference("phing.parsing.context");
$current = $ctx->getConfigurator()->getCurrentTargets();
$current[$targetName] = $target;
}
function getTargets() {
return $this->targets;
}
/**
* Create a new task instance and return reference to it. This method is
* sorta factory like. A _local_ instance is created and a reference returned to
* that instance. Usually PHP destroys local variables when the function call
* ends. But not if you return a reference to that variable.
* This is kinda error prone, because if no reference exists to the variable
* it is destroyed just like leaving the local scope with primitive vars. There's no
* central place where the instance is stored as in other OOP like languages.
*
* [HL] Well, ZE2 is here now, and this is still working. We'll leave this alone
* unless there's any good reason not to.
*
* @param string $taskType Task name
* @returns Task A task object
* @throws BuildException
* Exception
*/
function createTask($taskType) {
try {
$classname = "";
$tasklwr = strtolower($taskType);
foreach ($this->taskdefs as $name => $class) {
if (strtolower($name) === $tasklwr) {
$classname = $class;
break;
}
}
if ($classname === "") {
return null;
}
$cls = Phing::import($classname);
if (!class_exists($cls)) {
throw new BuildException("Could not instantiate class $cls, even though a class was specified. (Make sure that the specified class file contains a class with the correct name.)");
}
$o = new $cls();
if ($o instanceof Task) {
$task = $o;
} else {
$this->log (" (Using TaskAdapter for: $taskType)", Project::MSG_DEBUG);
// not a real task, try adapter
$taskA = new TaskAdapter();
$taskA->setProxy($o);
$task = $taskA;
}
$task->setProject($this);
$task->setTaskType($taskType);
// set default value, can be changed by the user
$task->setTaskName($taskType);
$this->log (" +Task: " . $taskType, Project::MSG_DEBUG);
} catch (Exception $t) {
throw new BuildException("Could not create task of type: " . $taskType, $t);
}
// everything fine return reference
return $task;
}
/**
* Create a datatype instance and return reference to it
* See createTask() for explanation how this works
*
* @param string Type name
* @returns object A datatype object
* @throws BuildException
* Exception
*/
function createDataType($typeName) {
try {
$cls = "";
$typelwr = strtolower($typeName);
foreach ($this->typedefs as $name => $class) {
if (strtolower($name) === $typelwr) {
$cls = StringHelper::unqualify($class);
break;
}
}
if ($cls === "") {
return null;
}
if (!class_exists($cls)) {
throw new BuildException("Could not instantiate class $cls, even though a class was specified. (Make sure that the specified class file contains a class with the correct name.)");
}
$type = new $cls();
$this->log(" +Type: $typeName", Project::MSG_DEBUG);
if (!($type instanceof DataType)) {
throw new Exception("$class is not an instance of phing.types.DataType");
}
if ($type instanceof ProjectComponent) {
$type->setProject($this);
}
} catch (Exception $t) {
throw new BuildException("Could not create type: $typeName", $t);
}
// everything fine return reference
return $type;
}
/**
* Executes a list of targets
*
* @param array List of target names to execute
* @returns void
* @throws BuildException
*/
function executeTargets($targetNames) {
foreach($targetNames as $tname) {
$this->executeTarget($tname);
}
}
/**
* Executes a target
*
* @param string Name of Target to execute
* @returns void
* @throws BuildException
*/
function executeTarget($targetName) {
// complain about executing void
if ($targetName === null) {
throw new BuildException("No target specified");
}
// invoke topological sort of the target tree and run all targets
// until targetName occurs.
$sortedTargets = $this->_topoSort($targetName, $this->targets);
$curIndex = (int) 0;
$curTarget = null;
do {
try {
$curTarget = $sortedTargets[$curIndex++];
$curTarget->performTasks();
} catch (BuildException $exc) {
$this->log("Execution of target \"".$curTarget->getName()."\" failed for the following reason: ".$exc->getMessage(), Project::MSG_ERR);
throw $exc;
}
} while ($curTarget->getName() !== $targetName);
}
function resolveFile($fileName, $rootDir = null) {
if ($rootDir === null) {
return $this->fileUtils->resolveFile($this->basedir, $fileName);
} else {
return $this->fileUtils->resolveFile($rootDir, $fileName);
}
}
/**
* Topologically sort a set of Targets.
* @param $root is the (String) name of the root Target. The sort is
* created in such a way that the sequence of Targets until the root
* target is the minimum possible such sequence.
* @param $targets is a array representing a "name to Target" mapping
* @return An array of Strings with the names of the targets in
* sorted order.
*/
function _topoSort($root, &$targets) {
$root = (string) $root;
$ret = array();
$state = array();
$visiting = array();
// We first run a DFS based sort using the root as the starting node.
// This creates the minimum sequence of Targets to the root node.
// We then do a sort on any remaining unVISITED targets.
// This is unnecessary for doing our build, but it catches
// circular dependencies or missing Targets on the entire
// dependency tree, not just on the Targets that depend on the
// build Target.
$this->_tsort($root, $targets, $state, $visiting, $ret);
$retHuman = "";
for ($i=0, $_i=count($ret); $i < $_i; $i++) {
$retHuman .= $ret[$i]->toString()." ";
}
$this->log("Build sequence for target '$root' is: $retHuman", Project::MSG_VERBOSE);
$keys = array_keys($targets);
while($keys) {
$curTargetName = (string) array_shift($keys);
if (!isset($state[$curTargetName])) {
$st = null;
} else {
$st = (string) $state[$curTargetName];
}
if ($st === null) {
$this->_tsort($curTargetName, $targets, $state, $visiting, $ret);
} elseif ($st === "VISITING") {
throw new Exception("Unexpected node in visiting state: $curTargetName");
}
}
$retHuman = "";
for ($i=0,$_i=count($ret); $i < $_i; $i++) {
$retHuman .= $ret[$i]->toString()." ";
}
$this->log("Complete build sequence is: $retHuman", Project::MSG_VERBOSE);
return $ret;
}
// one step in a recursive DFS traversal of the target dependency tree.
// - The array "state" contains the state (VISITED or VISITING or null)
// of all the target names.
// - The stack "visiting" contains a stack of target names that are
// currently on the DFS stack. (NB: the target names in "visiting" are
// exactly the target names in "state" that are in the VISITING state.)
// 1. Set the current target to the VISITING state, and push it onto
// the "visiting" stack.
// 2. Throw a BuildException if any child of the current node is
// in the VISITING state (implies there is a cycle.) It uses the
// "visiting" Stack to construct the cycle.
// 3. If any children have not been VISITED, tsort() the child.
// 4. Add the current target to the Vector "ret" after the children
// have been visited. Move the current target to the VISITED state.
// "ret" now contains the sorted sequence of Targets upto the current
// Target.
function _tsort($root, &$targets, &$state, &$visiting, &$ret) {
$state[$root] = "VISITING";
$visiting[] = $root;
if (!isset($targets[$root]) || !($targets[$root] instanceof Target)) {
$target = null;
} else {
$target = $targets[$root];
}
// make sure we exist
if ($target === null) {
$sb = "Target '$root' does not exist in this project.";
array_pop($visiting);
if (!empty($visiting)) {
$parent = (string) $visiting[count($visiting)-1];
$sb .= "It is used from target '$parent'.";
}
throw new BuildException($sb);
}
$deps = $target->getDependencies();
while($deps) {
$cur = (string) array_shift($deps);
if (!isset($state[$cur])) {
$m = null;
} else {
$m = (string) $state[$cur];
}
if ($m === null) {
// not been visited
$this->_tsort($cur, $targets, $state, $visiting, $ret);
} elseif ($m == "VISITING") {
// currently visiting this node, so have a cycle
throw $this->_makeCircularException($cur, $visiting);
}
}
$p = (string) array_pop($visiting);
if ($root !== $p) {
throw new Exception("Unexpected internal error: expected to pop $root but got $p");
}
$state[$root] = "VISITED";
$ret[] = $target;
}
function _makeCircularException($end, $stk) {
$sb = "Circular dependency: $end";
do {
$c = (string) array_pop($stk);
$sb .= " <- ".$c;
} while($c != $end);
return new BuildException($sb);
}
/**
* Adds a reference to an object. This method is called when the parser
* detects a id="foo" attribute. It passes the id as $name and a reference
* to the object assigned to this id as $value
*/
function addReference($name, $object) {
if (isset($this->references[$name])) {
$this->log("Overriding previous definition of reference to $name", Project::MSG_WARN);
}
$this->log("Adding reference: $name -> ".get_class($object), Project::MSG_DEBUG);
$this->references[$name] = $object;
}
/**
* Returns the references array.
* @return array
*/
function getReferences() {
return $this->references;
}
/**
* Returns a specific reference.
* @param string $key The reference id/key.
* @return Reference or null if not defined
*/
function getReference($key)
{
if (isset($this->references[$key])) {
return $this->references[$key];
}
return null; // just to be explicit
}
/**
* Abstracting and simplifyling Logger calls for project messages
*/
function log($msg, $level = Project::MSG_INFO) {
$this->logObject($this, $msg, $level);
}
function logObject($obj, $msg, $level) {
$this->fireMessageLogged($obj, $msg, $level);
}
function addBuildListener(BuildListener $listener) {
$this->listeners[] = $listener;
}
function removeBuildListener(BuildListener $listener) {
$newarray = array();
for ($i=0, $size=count($this->listeners); $i < $size; $i++) {
if ($this->listeners[$i] !== $listener) {
$newarray[] = $this->listeners[$i];
}
}
$this->listeners = $newarray;
}
function getBuildListeners() {
return $this->listeners;
}
function fireBuildStarted() {
$event = new BuildEvent($this);
foreach($this->listeners as $listener) {
$listener->buildStarted($event);
}
}
function fireBuildFinished($exception) {
$event = new BuildEvent($this);
$event->setException($exception);
foreach($this->listeners as $listener) {
$listener->buildFinished($event);
}
}
function fireTargetStarted($target) {
$event = new BuildEvent($target);
foreach($this->listeners as $listener) {
$listener->targetStarted($event);
}
}
function fireTargetFinished($target, $exception) {
$event = new BuildEvent($target);
$event->setException($exception);
foreach($this->listeners as $listener) {
$listener->targetFinished($event);
}
}
function fireTaskStarted($task) {
$event = new BuildEvent($task);
foreach($this->listeners as $listener) {
$listener->taskStarted($event);
}
}
function fireTaskFinished($task, $exception) {
$event = new BuildEvent($task);
$event->setException($exception);
foreach($this->listeners as $listener) {
$listener->taskFinished($event);
}
}
function fireMessageLoggedEvent($event, $message, $priority) {
$event->setMessage($message, $priority);
foreach($this->listeners as $listener) {
$listener->messageLogged($event);
}
}
function fireMessageLogged($object, $message, $priority) {
$this->fireMessageLoggedEvent(new BuildEvent($object), $message, $priority);
}
}

View File

@ -1,70 +0,0 @@
<?php
/*
* $Id: ProjectComponent.php 905 2010-10-05 16:28:03Z mrook $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
/**
* Abstract class providing properties and methods common to all
* the project components
*
* @author Andreas Aderhold <andi@binarycloud.com>
* @author Hans Lellelid <hans@xmpl.org>
* @version $Revision: 905 $
* @package phing
*/
abstract class ProjectComponent {
/**
* Holds a reference to the project that a project component
* (a task, a target, etc.) belongs to
*
* @var Project A reference to the current project instance
*/
protected $project = null;
/**
* References the project to the current component.
*
* @param Project $project The reference to the current project
*/
public function setProject($project) {
$this->project = $project;
}
/**
* Returns a reference to current project
*
* @return Project Reference to current porject object
*/
public function getProject() {
return $this->project;
}
/**
* Logs a message with the given priority.
*
* @param string $msg The message to be logged.
* @param integer $level The message's priority at this message should have
*/
public function log($msg, $level = Project::MSG_INFO) {
if ($this->project !== null) {
$this->project->log($msg, $level);
}
}
}

View File

@ -1,118 +0,0 @@
<?php
/*
* $Id: RuntimeConfigurable.php 905 2010-10-05 16:28:03Z mrook $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
/**
* Wrapper class that holds the attributes of a Task (or elements
* nested below that level) and takes care of configuring that element
* at runtime.
*
* <strong>SMART-UP INLINE DOCS</strong>
*
* @author Andreas Aderhold <andi@binarycloud.com>
* @author Hans Lellelid <hans@xmpl.org>
* @version $Revision: 905 $
* @package phing
*/
class RuntimeConfigurable {
private $elementTag = null;
private $children = array();
private $wrappedObject = null;
private $attributes = array();
private $characters = "";
/** @param proxy The element to wrap. */
function __construct($proxy, $elementTag) {
$this->wrappedObject = $proxy;
$this->elementTag = $elementTag;
}
function setProxy($proxy) {
$this->wrappedObject = $proxy;
}
/** Set's the attributes for the wrapped element. */
function setAttributes($attributes) {
$this->attributes = $attributes;
}
/** Returns the AttributeList of the wrapped element. */
function getAttributes() {
return $this->attributes;
}
/** Adds child elements to the wrapped element. */
function addChild(RuntimeConfigurable $child) {
$this->children[] = $child;
}
/** Returns the child with index */
function getChild($index) {
return $this->children[(int)$index];
}
/** Add characters from #PCDATA areas to the wrapped element. */
function addText($data) {
$this->characters .= (string) $data;
}
function getElementTag() {
return $this->elementTag;
}
/** Configure the wrapped element and all children. */
function maybeConfigure(Project $project) {
$id = null;
// DataType configured in ProjectConfigurator
// if ( is_a($this->wrappedObject, "DataType") )
// return;
if ($this->attributes || $this->characters) {
ProjectConfigurator::configure($this->wrappedObject, $this->attributes, $project);
if (isset($this->attributes["id"])) {
$id = $this->attributes["id"];
}
$this->attributes = null;
if ($this->characters) {
ProjectConfigurator::addText($project, $this->wrappedObject, (string) $this->characters);
$this->characters="";
}
if ($id !== null) {
$project->addReference($id, $this->wrappedObject);
}
}
if ( is_array($this->children) && !empty($this->children) ) {
// Configure all child of this object ...
foreach($this->children as $child) {
$child->maybeConfigure($project);
ProjectConfigurator::storeChild($project, $this->wrappedObject, $child->wrappedObject, strtolower($child->getElementTag()));
}
}
}
}

View File

@ -1,317 +0,0 @@
<?php
/*
* $Id: Target.php 905 2010-10-05 16:28:03Z mrook $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
include_once 'phing/TaskContainer.php';
/**
* The Target component. Carries all required target data. Implements the
* abstract class {@link TaskContainer}
*
* @author Andreas Aderhold <andi@binarycloud.com>
* @copyright <EFBFBD> 2001,2002 THYRELL. All rights reserved
* @version $Revision: 905 $ $Date: 2010-10-05 18:28:03 +0200 (Tue, 05 Oct 2010) $
* @access public
* @see TaskContainer
* @package phing
*/
class Target implements TaskContainer {
/** name of target */
private $name;
/** dependencies */
private $dependencies = array();
/** holds objects of children of this target */
private $children = array();
/** the if cond. from xml */
private $ifCondition = "";
/** the unless cond. from xml */
private $unlessCondition = "";
/** description of this target */
private $description;
/** reference to project */
private $project;
/**
* References the project to the current component.
*
* @param Project The reference to the current project
*/
public function setProject(Project $project) {
$this->project = $project;
}
/**
* Returns reference to current project
*
* @return Project Reference to current porject object
*/
public function getProject() {
return $this->project;
}
/**
* Sets the target dependencies from xml
*
* @param string $depends Comma separated list of targetnames that depend on
* this target
* @throws BuildException
*/
public function setDepends($depends) {
// explode should be faster than strtok
$deps = explode(',', $depends);
for ($i=0, $size=count($deps); $i < $size; $i++) {
$trimmed = trim($deps[$i]);
if ($trimmed === "") {
throw new BuildException("Syntax Error: Depend attribute for target ".$this->getName()." is malformed.");
}
$this->addDependency($trimmed);
}
}
/**
* Adds a singular dependent target name to the list
*
* @param string The dependency target to add
* @access public
*/
public function addDependency($dependency) {
$this->dependencies[] = (string) $dependency;
}
/**
* Returns reference to indexed array of the dependencies this target has.
*
* @return array Referece to target dependencoes
*/
public function getDependencies() {
return $this->dependencies;
}
/**
* Sets the name of the target
*
* @param string Name of this target
*/
public function setName($name) {
$this->name = (string) $name;
}
/**
* Returns name of this target.
*
* @return string The name of the target
* @access public
*/
function getName() {
return (string) $this->name;
}
/**
* Adds a task element to the list of this targets child elements
*
* @param object The task object to add
* @access public
*/
function addTask(Task $task) {
$this->children[] = $task;
}
/**
* Adds a runtime configurable element to the list of this targets child
* elements.
*
* @param object The RuntimeConfigurabel object
* @access public
*/
function addDataType($rtc) {
$this->children[] = $rtc;
}
/**
* Returns an array of all tasks this target has as childrens.
*
* The task objects are copied here. Don't use this method to modify
* task objects.
*
* @return array Task[]
*/
public function getTasks() {
$tasks = array();
for ($i=0,$size=count($this->children); $i < $size; $i++) {
$tsk = $this->children[$i];
if ($tsk instanceof Task) {
// note: we're copying objects here!
$tasks[] = clone $tsk;
}
}
return $tasks;
}
/**
* Set the if-condition from the XML tag, if any. The property name given
* as parameter must be present so the if condition evaluates to true
*
* @param string The property name that has to be present
* @access public
*/
public function setIf($property) {
$this->ifCondition = ($property === null) ? "" : $property;
}
/**
* Set the unless-condition from the XML tag, if any. The property name
* given as parameter must be present so the unless condition evaluates
* to true
*
* @param string The property name that has to be present
* @access public
*/
public function setUnless($property) {
$this->unlessCondition = ($property === null) ? "" : $property;
}
/**
* Sets a textual description of this target.
*
* @param string The description text
*/
public function setDescription($description) {
if ($description !== null && strcmp($description, "") !== 0) {
$this->description = (string) $description;
} else {
$this->description = null;
}
}
/**
* Returns the description of this target.
*
* @return string The description text of this target
*/
public function getDescription() {
return $this->description;
}
/**
* Returns a string representation of this target. In our case it
* simply returns the target name field
*
* @return string The string representation of this target
*/
function toString() {
return (string) $this->name;
}
/**
* The entry point for this class. Does some checking, then processes and
* performs the tasks for this target.
*
*/
public function main() {
if ($this->testIfCondition() && $this->testUnlessCondition()) {
foreach($this->children as $o) {
if ($o instanceof Task) {
// child is a task
$o->perform();
} else {
// child is a RuntimeConfigurable
$o->maybeConfigure($this->project);
}
}
} elseif (!$this->testIfCondition()) {
$this->project->log("Skipped target '".$this->name."' because property '".$this->ifCondition."' not set.", Project::MSG_VERBOSE);
} else {
$this->project->log("Skipped target '".$this->name."' because property '".$this->unlessCondition."' set.", Project::MSG_VERBOSE);
}
}
/**
* Performs the tasks by calling the main method of this target that
* actually executes the tasks.
*
* This method is for ZE2 and used for proper exception handling of
* task exceptions.
*/
public function performTasks() {
try {// try to execute this target
$this->project->fireTargetStarted($this);
$this->main();
$this->project->fireTargetFinished($this, $null=null);
} catch (BuildException $exc) {
// log here and rethrow
$this->project->fireTargetFinished($this, $exc);
throw $exc;
}
}
/**
* Tests if the property set in ifConfiditon exists.
*
* @return boolean <code>true</code> if the property specified
* in <code>$this->ifCondition</code> exists;
* <code>false</code> otherwise
*/
private function testIfCondition() {
if ($this->ifCondition === "") {
return true;
}
$properties = explode(",", $this->ifCondition);
$result = true;
foreach ($properties as $property) {
$test = ProjectConfigurator::replaceProperties($this->getProject(), $property, $this->project->getProperties());
$result = $result && ($this->project->getProperty($test) !== null);
}
return $result;
}
/**
* Tests if the property set in unlessCondition exists.
*
* @return boolean <code>true</code> if the property specified
* in <code>$this->unlessCondition</code> exists;
* <code>false</code> otherwise
*/
private function testUnlessCondition() {
if ($this->unlessCondition === "") {
return true;
}
$properties = explode(",", $this->unlessCondition);
$result = true;
foreach ($properties as $property) {
$test = ProjectConfigurator::replaceProperties($this->getProject(), $property, $this->project->getProperties());
$result = $result && ($this->project->getProperty($test) === null);
}
return $result;
}
}

View File

@ -1,265 +0,0 @@
<?php
/*
* $Id: Task.php 905 2010-10-05 16:28:03Z mrook $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
require_once 'phing/ProjectComponent.php';
include_once 'phing/RuntimeConfigurable.php';
/**
* The base class for all Tasks.
*
* Use {@link Project#createTask} to register a new Task.
*
* @author Andreas Aderhold <andi@binarycloud.com>
* @copyright <EFBFBD> 2001,2002 THYRELL. All rights reserved
* @version $Revision: 905 $
* @see Project#createTask()
* @package phing
*/
abstract class Task extends ProjectComponent {
/**
* @var Target owning Target object
*/
protected $target;
/**
* @var string description of the task
*/
protected $description;
/**
* @var string internal taskname (req)
*/
protected $taskType;
/**
* @var string Taskname for logger
*/
protected $taskName;
/**
* @var Location stored buildfile location
*/
protected $location;
/**
* @var RuntimeConfigurable wrapper of the task
*/
protected $wrapper;
/**
* Sets the owning target this task belongs to.
*
* @param Target Reference to owning target
*/
public function setOwningTarget(Target $target) {
$this->target = $target;
}
/**
* Returns the owning target of this task.
*
* @return Target The target object that owns this task
*/
public function getOwningTarget() {
return $this->target;
}
/**
* Returns the name of task, used only for log messages
*
* @return string Name of this task
*/
public function getTaskName() {
if ($this->taskName === null) {
// if no task name is set, then it's possible
// this task was created from within another task. We don't
// therefore know the XML tag name for this task, so we'll just
// use the class name stripped of "task" suffix. This is only
// for log messages, so we don't have to worry much about accuracy.
return preg_replace('/task$/i', '', get_class($this));
}
return $this->taskName;
}
/**
* Sets the name of this task for log messages
*
* @return string A string representing the name of this task for log
*/
public function setTaskName($name) {
$this->taskName = (string) $name;
}
/**
* Returns the name of the task under which it was invoked,
* usually the XML tagname
*
* @return string The type of this task (XML Tag)
*/
public function getTaskType() {
return $this->taskType;
}
/**
* Sets the type of the task. Usually this is the name of the XML tag
*
* @param string The type of this task (XML Tag)
*/
public function setTaskType($name) {
$this->taskType = (string) $name;
}
/**
* Returns a name
*
*/
protected function getRegisterSlot($slotName) {
return Register::getSlot('task.' . $this->getTaskName() . '.' . $slotName);
}
/**
* Provides a project level log event to the task.
*
* @param string The message to log
* @param integer The priority of the message
* @see BuildEvent
* @see BuildListener
*/
function log($msg, $level = Project::MSG_INFO) {
$this->project->logObject($this, $msg, $level);
}
/**
* Sets a textual description of the task
*
* @param string $desc The text describing the task
*/
public function setDescription($desc) {
$this->description = $desc;
}
/**
* Returns the textual description of the task
*
* @return string The text description of the task
*/
public function getDescription() {
return $this->description;
}
/**
* Called by the parser to let the task initialize properly.
* Should throw a BuildException if something goes wrong with the build
*
* This is abstract here, but may not be overloaded by subclasses.
*
* @throws BuildException
*/
public function init() {
}
/**
* Called by the project to let the task do it's work. This method may be
* called more than once, if the task is invoked more than once. For
* example, if target1 and target2 both depend on target3, then running
* <em>phing target1 target2</em> will run all tasks in target3 twice.
*
* Should throw a BuildException if someting goes wrong with the build
*
* This is abstract here. Must be overloaded by real tasks.
*/
abstract public function main();
/**
* Returns the location within the buildfile this task occurs. Used
* by {@link BuildException} to give detailed error messages.
*
* @return Location The location object describing the position of this
* task within the buildfile.
*/
function getLocation() {
return $this->location;
}
/**
* Sets the location within the buildfile this task occurs. Called by
* the parser to set location information.
*
* @param Location $location The location object describing the position of this
* task within the buildfile.
*/
function setLocation(Location $location) {
$this->location = $location;
}
/**
* Returns the wrapper object for runtime configuration
*
* @return RuntimeConfigurable The wrapper object used by this task
*/
function getRuntimeConfigurableWrapper() {
if ($this->wrapper === null) {
$this->wrapper = new RuntimeConfigurable($this, $this->getTaskName());
}
return $this->wrapper;
}
/**
* Sets the wrapper object this task should use for runtime
* configurable elements.
*
* @param RuntimeConfigurable $wrapper The wrapper object this task should use
*/
function setRuntimeConfigurableWrapper(RuntimeConfigurable $wrapper) {
$this->wrapper = $wrapper;
}
/**
* Configure this task if it hasn't been done already.
*/
public function maybeConfigure() {
if ($this->wrapper !== null) {
$this->wrapper->maybeConfigure($this->project);
}
}
/**
* Perfrom this task
*/
public function perform() {
try { // try executing task
$this->project->fireTaskStarted($this);
$this->maybeConfigure();
$this->main();
$this->project->fireTaskFinished($this, $null=null);
} catch (Exception $exc) {
if ($exc instanceof BuildException) {
if ($exc->getLocation() === null) {
$exc->setLocation($this->getLocation());
}
}
$this->project->fireTaskFinished($this, $exc);
throw $exc;
}
}
}

View File

@ -1,84 +0,0 @@
<?php
/*
* $Id: TaskAdapter.php 905 2010-10-05 16:28:03Z mrook $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
require_once 'phing/Task.php';
/**
* Use introspection to "adapt" an arbitrary ( not extending Task, but with
* similar patterns).
*
* @author Andreas Aderhold <andi@binarycloud.com>
* @copyright © 2001,2002 THYRELL. All rights reserved
* @version $Revision: 905 $
* @package phing
*/
class TaskAdapter extends Task {
/** target object */
private $proxy;
/**
* Main entry point.
* @return void
*/
function main() {
if (method_exists($this->proxy, "setProject")) {
try { // try to set project
$this->proxy->setProject($this->project);
} catch (Exception $ex) {
$this->log("Error setting project in " . get_class($this->proxy) . Project::MSG_ERR);
throw new BuildException($ex);
}
} else {
throw new Exception("Error setting project in class " . get_class($this->proxy));
}
if (method_exists($this->proxy, "main")) {
try { //try to call main
$this->proxy->main($this->project);
} catch (Exception $ex) {
$this->log("Error in " . get_class($this->proxy), Project::MSG_ERR);
throw new BuildException($ex->getMessage());
}
} else {
throw new BuildException("Your task-like class '" . get_class($this->proxy) ."' does not have a main() method");
}
}
/**
* Set the target object.
* @param object $o
* @return void
*/
function setProxy($o) {
$this->proxy = $o;
}
/**
* Gets the target object.
* @return object
*/
function getProxy() {
return $this->proxy;
}
}

View File

@ -1,42 +0,0 @@
<?php
/*
* $Id: TaskContainer.php 905 2010-10-05 16:28:03Z mrook $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
/**
* Abstract interface for objects which can contain tasks (targets)
* Used to check if a class can contain tasks (via instanceof)
*
* @author Andreas Aderhold <andi@binarycloud.com>
* @copyright © 2001,2002 THYRELL. All rights reserved
* @version $Revision: 905 $ $Date: 2010-10-05 18:28:03 +0200 (Tue, 05 Oct 2010) $
* @access public
* @package phing
*/
interface TaskContainer {
/**
* Adds a task to this task container. Must be implemented
* by derived class
*
* @param object The task to be added to the container
* @access public
*/
function addTask(Task $task);
}

View File

@ -1,215 +0,0 @@
<?php
/*
* $Id: UnknownElement.php 905 2010-10-05 16:28:03Z mrook $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
require_once 'phing/Task.php';
/**
* Wrapper class that holds all information necessary to create a task
* that did not exist when Phing started.
*
* <em> This has something to do with phing encountering an task XML element
* it is not aware of at start time. This is a situation where special steps
* need to be taken so that the element is then known.</em>
*
* @author Andreas Aderhold <andi@binarycloud.com>
* @author Hans Lellelid <hans@xmpl.org>
* @version $Revision: 905 $
* @package phing
*/
class UnknownElement extends Task {
private $elementName;
private $realThing;
private $children = array();
/**
* Constructs a UnknownElement object
*
* @param string The XML element name that is unknown
* @access public
*/
function __construct($elementName) {
$this->elementName = (string) $elementName;
}
/**
* Return the XML element name that this <code>UnnownElement</code>
* handles.
*
* @return string The XML element name that is unknown
*/
public function getTag() {
return (string) $this->elementName;
}
/**
* Tries to configure the unknown element
*
* @throws BuildException if the element can not be configured
*/
public function maybeConfigure() {
$this->realThing = $this->makeObject($this, $this->wrapper);
$this->wrapper->setProxy($this->realThing);
if ($this->realThing instanceof Task) {
$this->realThing->setRuntimeConfigurableWrapper($this->wrapper);
}
$this->handleChildren($this->realThing, $this->wrapper);
$this->wrapper->maybeConfigure($this->getProject());
}
/**
* Called when the real task has been configured for the first time.
*
* @throws BuildException if the task can not be created
*/
public function main() {
if ($this->realThing === null) {
// plain impossible to get here, maybeConfigure should
// have thrown an exception.
throw new BuildException("Should not be executing UnknownElement::main() -- task/type: {$this->elementName}");
}
if ($this->realThing instanceof Task) {
$this->realThing->main();
}
}
/**
* Add a child element to the unknown element
*
* @param object The object representing the child element
*/
public function addChild(UnknownElement $child) {
$this->children[] = $child;
}
/**
* Handle child elemets of the unknown element, if any.
*
* @param ProjectComponent The parent object the unkown element belongs to
* @param object The parent wrapper object
*/
function handleChildren(ProjectComponent $parent, $parentWrapper) {
if ($parent instanceof TaskAdapter) {
$parent = $parent->getProxy();
}
$parentClass = get_class($parent);
$ih = IntrospectionHelper::getHelper($parentClass);
for ($i=0, $childrenCount=count($this->children); $i < $childrenCount; $i++) {
$childWrapper = $parentWrapper->getChild($i);
$child = $this->children[$i];
$realChild = null;
if ($parent instanceof TaskContainer) {
$realChild = $this->makeTask($child, $childWrapper, false);
$parent->addTask($realChild);
} else {
$project = $this->project === null ? $parent->project : $this->project;
$realChild = $ih->createElement($project, $parent, $child->getTag());
}
$childWrapper->setProxy($realChild);
if ($realChild instanceof Task) {
$realChild->setRuntimeConfigurableWrapper($childWrapper);
}
if ($realChild instanceof ProjectComponent) {
$child->handleChildren($realChild, $childWrapper);
}
if ($realChild instanceof Task) {
$realChild->maybeConfigure();
}
}
}
/**
* Creates a named task or data type. If the real object is a task,
* it is configured up to the init() stage.
*
* @param UnknownElement $ue The unknown element to create the real object for.
* Must not be <code>null</code>.
* @param RuntimeConfigurable $w Ignored in this implementation.
* @return object The Task or DataType represented by the given unknown element.
*/
protected function makeObject(UnknownElement $ue, RuntimeConfigurable $w) {
$o = $this->makeTask($ue, $w, true);
if ($o === null) {
$o = $this->project->createDataType($ue->getTag());
}
if ($o === null) {
throw new BuildException("Could not create task/type: '".$ue->getTag()."'. Make sure that this class has been declared using taskdef / typedef.");
}
return $o;
}
/**
* Create a named task and configure it up to the init() stage.
*
* @param UnknownElement $ue The unknwon element to create a task from
* @param RuntimeConfigurable $w The wrapper object
* @param boolean $onTopLevel Whether to treat this task as if it is top-level.
* @return Task The freshly created task
*/
protected function makeTask(UnknownElement $ue, RuntimeConfigurable $w, $onTopLevel = false) {
$task = $this->project->createTask($ue->getTag());
if ($task === null) {
if (!$onTopLevel) {
throw new BuildException("Could not create task of type: '".$this->elementName."'. Make sure that this class has been declared using taskdef.");
}
return null;
}
// used to set the location within the xmlfile so that exceptions can
// give detailed messages
$task->setLocation($this->getLocation());
$attrs = $w->getAttributes();
if (isset($attrs['id'])) {
$this->project->addReference($attrs['id'], $task);
}
// UnknownElement always has an associated target
$task->setOwningTarget($this->target);
$task->init();
return $task;
}
/**
* Get the name of the task to use in logging messages.
*
* @return string The task's name
*/
function getTaskName() {
return $this->realThing === null ? parent::getTaskName() : $this->realThing->getTaskName();
}
}

View File

@ -1,157 +0,0 @@
<?php
/*
* $Id: BaseFilterReader.php 905 2010-10-05 16:28:03Z mrook $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
include_once 'phing/system/io/FilterReader.php';
include_once 'phing/system/io/StringReader.php';
/**
* Base class for core filter readers.
*
* @author <a href="mailto:yl@seasonfive.com">Yannick Lecaillez</a>
* @version $Revision: 905 $ $Date: 2010-10-05 18:28:03 +0200 (Tue, 05 Oct 2010) $
* @access public
* @see FilterReader
* @package phing.filters
*/
class BaseFilterReader extends FilterReader {
/** Have the parameters passed been interpreted? */
protected $initialized = false;
/** The Phing project this filter is part of. */
protected $project = null;
/**
* Constructor used by Phing's introspection mechanism.
* The original filter reader is only used for chaining
* purposes, never for filtering purposes (and indeed
* it would be useless for filtering purposes, as it has
* no real data to filter). ChainedReaderHelper uses
* this placeholder instance to create a chain of real filters.
*
* @param Reader $in
*/
function __construct($in = null) {
if ($in === null) {
$dummy = "";
$in = new StringReader($dummy);
}
parent::__construct($in);
}
/**
* Returns the initialized status.
*
* @return boolean whether or not the filter is initialized
*/
function getInitialized() {
return $this->initialized;
}
/**
* Sets the initialized status.
*
* @param boolean $initialized Whether or not the filter is initialized.
*/
function setInitialized($initialized) {
$this->initialized = (boolean) $initialized;
}
/**
* Sets the project to work with.
*
* @param object $project The project this filter is part of.
* Should not be <code>null</code>.
*/
function setProject(Project $project) {
// type check, error must never occur, bad code of it does
$this->project = $project;
}
/**
* Returns the project this filter is part of.
*
* @return object The project this filter is part of
*/
function getProject() {
return $this->project;
}
/**
* Reads characters.
*
* @param off Offset at which to start storing characters.
* @param len Maximum number of characters to read.
*
* @return Characters read, or -1 if the end of the stream
* has been reached
*
* @throws IOException If an I/O error occurs
*/
function read($len = null) {
return $this->in->read($len);
}
/**
* Reads a line of text ending with '\n' (or until the end of the stream).
* The returned String retains the '\n'.
*
* @return the line read, or <code>null</code> if the end of the
stream has already been reached
*
* @throws IOException if the underlying reader throws one during
* reading
*/
function readLine() {
$line = null;
while ( ($ch = $this->in->read(1)) !== -1 ) {
$line .= $ch;
if ( $ch === "\n" )
break;
}
return $line;
}
/**
* Returns whether the end of file has been reached with input stream.
* @return boolean
*/
function eof() {
return $this->in->eof();
}
/**
* Convenience method to support logging in filters.
* @param string $msg Message to log.
* @param int $level Priority level.
*/
function log($msg, $level = Project::MSG_INFO) {
if ($this->project !== null) {
$this->project->log("[filter:".get_class($this)."] ".$msg, $level);
}
}
}

View File

@ -1,69 +0,0 @@
<?php
/*
* $Id: BaseParamFilterReader.php 905 2010-10-05 16:28:03Z mrook $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
include_once 'phing/filters/BaseFilterReader.php';
include_once 'phing/types/Parameterizable.php';
include_once 'phing/types/Parameter.php';
/**
* Base class for core filter readers.
*
* @author <a href="mailto:yl@seasonfive.com">Yannick Lecaillez</a>
* @copyright © 2003 seasonfive. All rights reserved
* @version $Revision: 905 $ $Date: 2010-10-05 18:28:03 +0200 (Tue, 05 Oct 2010) $
* @access public
* @see FilterReader
* @package phing.filters
*/
class BaseParamFilterReader extends BaseFilterReader implements Parameterizable {
/** The passed in parameter array. */
protected $_parameters = array();
/*
* Sets the parameters used by this filter, and sets
* the filter to an uninitialized status.
*
* @param array Array of parameters to be used by this filter.
* Should not be <code>null</code>.
*/
function setParameters($parameters) {
// type check, error must never occur, bad code of it does
if ( !is_array($parameters) ) {
throw new Exception("Expected parameters array got something else");
}
$this->_parameters = $parameters;
$this->setInitialized(false);
}
/*
* Returns the parameters to be used by this filter.
*
* @return the parameters to be used by this filter
*/
function &getParameters() {
return $this->_parameters;
}
}

View File

@ -1,43 +0,0 @@
<?php
/*
* $Id: ChainableReader.php 905 2010-10-05 16:28:03Z mrook $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
/**
* Interface indicating that a reader may be chained to another one.
*
* @author Magesh Umasankar
* @package phing.filters
*/
interface ChainableReader {
/**
* Returns a reader with the same configuration as this one,
* but filtering input from the specified reader.
*
* @param Reader $rdr the reader which the returned reader should be filtering
*
* @return Reader A reader with the same configuration as this one, but
* filtering input from the specified reader
*/
public function chain(Reader $rdr);
}

View File

@ -1,82 +0,0 @@
<?php
/*
* $Id: ExpandProperties.php 905 2010-10-05 16:28:03Z mrook $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
require_once 'phing/filters/BaseFilterReader.php';
include_once 'phing/filters/ChainableReader.php';
/**
* Expands Phing Properties, if any, in the data.
* <p>
* Example:<br>
* <pre><expandproperties/></pre>
* Or:
* <pre><filterreader classname="phing.filters.ExpandProperties'/></pre>
*
* @author Yannick Lecaillez <yl@seasonfive.com>
* @author Hans Lellelid <hans@xmpl.org>
* @version $Revision: 905 $
* @see BaseFilterReader
* @package phing.filters
*/
class ExpandProperties extends BaseFilterReader implements ChainableReader {
/**
* Returns the filtered stream.
* The original stream is first read in fully, and the Phing properties are expanded.
*
* @return mixed the filtered stream, or -1 if the end of the resulting stream has been reached.
*
* @exception IOException if the underlying stream throws an IOException
* during reading
*/
function read($len = null) {
$buffer = $this->in->read($len);
if($buffer === -1) {
return -1;
}
$project = $this->getProject();
$buffer = ProjectConfigurator::replaceProperties($project, $buffer, $project->getProperties());
return $buffer;
}
/**
* Creates a new ExpandProperties filter using the passed in
* Reader for instantiation.
*
* @param object A Reader object providing the underlying stream.
* Must not be <code>null</code>.
*
* @return object A new filter based on this configuration, but filtering
* the specified reader
*/
function chain(Reader $reader) {
$newFilter = new ExpandProperties($reader);
$newFilter->setProject($this->getProject());
return $newFilter;
}
}

View File

@ -1,161 +0,0 @@
<?php
/*
* $Id: HeadFilter.php 905 2010-10-05 16:28:03Z mrook $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
include_once 'phing/filters/BaseParamFilterReader.php';
include_once 'phing/filters/ChainableReader.php';
/**
* Reads the first <code>n</code> lines of a stream.
* (Default is first 10 lines.)
* <p>
* Example:
* <pre><headfilter lines="3"/></pre>
* Or:
* <pre><filterreader classname="phing.filters.HeadFilter">
* <param name="lines" value="3"/>
* </filterreader></pre>
*
* @author <a href="mailto:yl@seasonfive.com">Yannick Lecaillez</a>
* @author hans lellelid, hans@velum.net
* @version $Revision: 905 $ $Date: 2010-10-05 18:28:03 +0200 (Tue, 05 Oct 2010) $
* @access public
* @see FilterReader
* @package phing.filters
*/
class HeadFilter extends BaseParamFilterReader implements ChainableReader {
/**
* Parameter name for the number of lines to be returned.
*/
const LINES_KEY = "lines";
/**
* Number of lines currently read in.
* @var integer
*/
private $_linesRead = 0;
/**
* Number of lines to be returned in the filtered stream.
* @var integer
*/
private $_lines = 10;
/**
* Returns first n lines of stream.
* @return the resulting stream, or -1
* if the end of the resulting stream has been reached
*
* @exception IOException if the underlying stream throws an IOException
* during reading
*/
function read($len = null) {
if ( !$this->getInitialized() ) {
$this->_initialize();
$this->setInitialized(true);
}
// note, if buffer contains fewer lines than
// $this->_lines this code will not work.
if($this->_linesRead < $this->_lines) {
$buffer = $this->in->read($len);
if($buffer === -1) {
return -1;
}
// now grab first X lines from buffer
$lines = explode("\n", $buffer);
$linesCount = count($lines);
// must account for possibility that the num lines requested could
// involve more than one buffer read.
$len = ($linesCount > $this->_lines ? $this->_lines - $this->_linesRead : $linesCount);
$filtered_buffer = implode("\n", array_slice($lines, 0, $len) );
$this->_linesRead += $len;
return $filtered_buffer;
}
return -1; // EOF, since the file is "finished" as far as subsequent filters are concerned.
}
/**
* Sets the number of lines to be returned in the filtered stream.
*
* @param integer $lines the number of lines to be returned in the filtered stream.
*/
function setLines($lines) {
$this->_lines = (int) $lines;
}
/**
* Returns the number of lines to be returned in the filtered stream.
*
* @return integer The number of lines to be returned in the filtered stream.
*/
function getLines() {
return $this->_lines;
}
/**
* Creates a new HeadFilter using the passed in
* Reader for instantiation.
*
* @param object A Reader object providing the underlying stream.
* Must not be <code>null</code>.
*
* @return object A new filter based on this configuration, but filtering
* the specified reader.
*/
function chain(Reader $reader) {
$newFilter = new HeadFilter($reader);
$newFilter->setLines($this->getLines());
$newFilter->setInitialized(true);
$newFilter->setProject($this->getProject());
return $newFilter;
}
/**
* Scans the parameters list for the "lines" parameter and uses
* it to set the number of lines to be returned in the filtered stream.
*/
private function _initialize() {
$params = $this->getParameters();
if ( $params !== null ) {
for($i = 0, $_i=count($params) ; $i < $_i; $i++) {
if ( self::LINES_KEY == $params[$i]->getName() ) {
$this->_lines = (int) $params[$i]->getValue();
break;
}
}
}
}
}

View File

@ -1,260 +0,0 @@
<?php
/*
* $Id: LineContains.php 905 2010-10-05 16:28:03Z mrook $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
include_once 'phing/filters/BaseParamFilterReader.php';
include_once 'phing/filters/BaseFilterReader.php';
include_once 'phing/filters/ChainableReader.php';
/**
* Filter which includes only those lines that contain all the user-specified
* strings.
*
* Example:
*
* <pre><linecontains>
* <contains value="foo">
* <contains value="bar">
* </linecontains></pre>
*
* Or:
*
* <pre><filterreader classname="phing.filters.LineContains">
* <param type="contains" value="foo"/>
* <param type="contains" value="bar"/>
* </filterreader></pre>
*
* This will include only those lines that contain <code>foo</code> and
* <code>bar</code>.
*
* @author Yannick Lecaillez <yl@seasonfive.com>
* @author Hans Lellelid <hans@velum.net>
* @version $Revision: 905 $
* @see PhingFilterReader
* @package phing.filters
*/
class LineContains extends BaseParamFilterReader implements ChainableReader {
/**
* The parameter name for the string to match on.
* @var string
*/
const CONTAINS_KEY = "contains";
/**
* Array of Contains objects.
* @var array
*/
private $_contains = array();
/**
* [Deprecated]
* @var string
*/
private $_line = null;
/**
* Returns all lines in a buffer that contain specified strings.
* @return mixed buffer, -1 on EOF
*/
function read($len = null) {
if ( !$this->getInitialized() ) {
$this->_initialize();
$this->setInitialized(true);
}
$buffer = $this->in->read($len);
if ($buffer === -1) {
return -1;
}
$lines = explode("\n", $buffer);
$matched = array();
$containsSize = count($this->_contains);
foreach($lines as $line) {
for($i = 0 ; $i < $containsSize ; $i++) {
$containsStr = $this->_contains[$i]->getValue();
if ( strstr($line, $containsStr) === false ) {
$line = null;
break;
}
}
if($line !== null) {
$matched[] = $line;
}
}
$filtered_buffer = implode("\n", $matched);
return $filtered_buffer;
}
/**
* [Deprecated. For reference only, used to be read() method.]
* Returns the next character in the filtered stream, only including
* lines from the original stream which contain all of the specified words.
*
* @return the next character in the resulting stream, or -1
* if the end of the resulting stream has been reached
*
* @exception IOException if the underlying stream throws an IOException
* during reading
*/
function readChar() {
if ( !$this->getInitialized() ) {
$this->_initialize();
$this->setInitialized(true);
}
$ch = -1;
if ( $this->_line !== null ) {
$ch = substr($this->_line, 0, 1);
if ( strlen($this->_line) === 1 )
$this->_line = null;
else
$this->_line = substr($this->_line, 1);
} else {
$this->_line = $this->readLine();
if ( $this->_line === null ) {
$ch = -1;
} else {
$containsSize = count($this->_contains);
for($i = 0 ; $i < $containsSize ; $i++) {
$containsStr = $this->_contains[$i]->getValue();
if ( strstr($this->_line, $containsStr) === false ) {
$this->_line = null;
break;
}
}
return $this->readChar();
}
}
return $ch;
}
/**
* Adds a <code><contains></code> nested element.
*
* @return Contains The <code>contains</code> element added.
* Must not be <code>null</code>.
*/
function createContains() {
$num = array_push($this->_contains, new Contains());
return $this->_contains[$num-1];
}
/**
* Sets the array of words which must be contained within a line read
* from the original stream in order for it to match this filter.
*
* @param array $contains An array of words which must be contained
* within a line in order for it to match in this filter.
* Must not be <code>null<code>.
*/
function setContains($contains) {
// type check, error must never occur, bad code of it does
if ( !is_array($contains) ) {
throw new Exception("Excpected array got something else");
}
$this->_contains = $contains;
}
/**
* Returns the vector of words which must be contained within a line read
* from the original stream in order for it to match this filter.
*
* @return array The array of words which must be contained within a line read
* from the original stream in order for it to match this filter. The
* returned object is "live" - in other words, changes made to the
* returned object are mirrored in the filter.
*/
function getContains() {
return $this->_contains;
}
/**
* Creates a new LineContains using the passed in
* Reader for instantiation.
*
* @param object A Reader object providing the underlying stream.
* Must not be <code>null</code>.
*
* @return object A new filter based on this configuration, but filtering
* the specified reader
*/
function chain(Reader $reader) {
$newFilter = new LineContains($reader);
$newFilter->setContains($this->getContains());
$newFilter->setInitialized(true);
$newFilter->setProject($this->getProject());
return $newFilter;
}
/**
* Parses the parameters to add user-defined contains strings.
*/
private function _initialize() {
$params = $this->getParameters();
if ( $params !== null ) {
foreach($params as $param) {
if ( self::CONTAINS_KEY == $param->getType() ) {
$cont = new Contains();
$cont->setValue($param->getValue());
array_push($this->_contains, $cont);
break; // because we only support a single contains
}
}
}
}
}
/**
* Holds a contains element.
*
* @package phing.filters
*/
class Contains {
/**
* @var string
*/
private $_value;
/**
* Set 'contains' value.
* @param string $contains
*/
function setValue($contains) {
$this->_value = (string) $contains;
}
/**
* Returns 'contains' value.
* @return string
*/
function getValue() {
return $this->_value;
}
}

View File

@ -1,179 +0,0 @@
<?php
/*
* $Id: LineContainsRegexp.php 905 2010-10-05 16:28:03Z mrook $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
include_once 'phing/filters/BaseParamFilterReader.php';
include_once 'phing/types/RegularExpression.php';
include_once 'phing/filters/ChainableReader.php';
/**
* Filter which includes only those lines that contain the user-specified
* regular expression matching strings.
*
* Example:
* <pre><linecontainsregexp>
* <regexp pattern="foo*">
* </linecontainsregexp></pre>
*
* Or:
*
* <pre><filterreader classname="phing.filters.LineContainsRegExp">
* <param type="regexp" value="foo*"/>
* </filterreader></pre>
*
* This will fetch all those lines that contain the pattern <code>foo</code>
*
* @author Yannick Lecaillez <yl@seasonfive.com>
* @author Hans Lellelid <hans@xmpl.org>
* @version $Revision: 905 $
* @see FilterReader
* @package phing.filters
*/
class LineContainsRegexp extends BaseParamFilterReader implements ChainableReader {
/**
* Parameter name for regular expression.
* @var string
*/
const REGEXP_KEY = "regexp";
/**
* Regular expressions that are applied against lines.
* @var array
*/
private $_regexps = array();
/**
* Returns all lines in a buffer that contain specified strings.
* @return mixed buffer, -1 on EOF
*/
function read($len = null) {
if ( !$this->getInitialized() ) {
$this->_initialize();
$this->setInitialized(true);
}
$buffer = $this->in->read($len);
if ($buffer === -1) {
return -1;
}
$lines = explode("\n", $buffer);
$matched = array();
$regexpsSize = count($this->_regexps);
foreach($lines as $line) {
for($i = 0 ; $i<$regexpsSize ; $i++) {
$regexp = $this->_regexps[$i];
$re = $regexp->getRegexp($this->getProject());
$matches = $re->matches($line);
if ( !$matches ) {
$line = null;
break;
}
}
if($line !== null) {
$matched[] = $line;
}
}
$filtered_buffer = implode("\n", $matched);
return $filtered_buffer;
}
/**
* Adds a <code>regexp</code> element.
*
* @return object regExp The <code>regexp</code> element added.
*/
function createRegexp() {
$num = array_push($this->_regexps, new RegularExpression());
return $this->_regexps[$num-1];
}
/**
* Sets the vector of regular expressions which must be contained within
* a line read from the original stream in order for it to match this
* filter.
*
* @param regexps An array of regular expressions which must be contained
* within a line in order for it to match in this filter. Must not be
* <code>null</code>.
*/
function setRegexps($regexps) {
// type check, error must never occur, bad code of it does
if ( !is_array($regexps) ) {
throw new Exception("Excpected an 'array', got something else");
}
$this->_regexps = $regexps;
}
/**
* Returns the array of regular expressions which must be contained within
* a line read from the original stream in order for it to match this
* filter.
*
* @return array The array of regular expressions which must be contained within
* a line read from the original stream in order for it to match this
* filter. The returned object is "live" - in other words, changes made to
* the returned object are mirrored in the filter.
*/
function getRegexps() {
return $this->_regexps;
}
/**
* Creates a new LineContainsRegExp using the passed in
* Reader for instantiation.
*
* @param object A Reader object providing the underlying stream.
* Must not be <code>null</code>.
*
* @return object A new filter based on this configuration, but filtering
* the specified reader
*/
function chain(Reader $reader) {
$newFilter = new LineContainsRegExp($reader);
$newFilter->setRegexps($this->getRegexps());
$newFilter->setInitialized(true);
$newFilter->setProject($this->getProject());
return $newFilter;
}
/**
* Parses parameters to add user defined regular expressions.
*/
private function _initialize() {
$params = $this->getParameters();
if ( $params !== null ) {
for($i = 0 ; $i<count($params) ; $i++) {
if ( self::REGEXP_KEY === $params[$i]->getType() ) {
$pattern = $params[$i]->getValue();
$regexp = new RegularExpression();
$regexp->setPattern($pattern);
array_push($this->_regexps, $regexp);
}
}
}
}
}

View File

@ -1,142 +0,0 @@
<?php
/*
* $Id: PrefixLines.php 905 2010-10-05 16:28:03Z mrook $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
include_once 'phing/filters/BaseParamFilterReader.php';
include_once 'phing/filters/ChainableReader.php';
/**
* Attaches a prefix to every line.
*
* Example:
* <pre><prefixlines prefix="Foo"/></pre>
*
* Or:
*
* <pre><filterreader classname="phing.filters.PrefixLines">
* <param name="prefix" value="Foo"/>
* </filterreader></pre>
*
* @author <a href="mailto:yl@seasonfive.com">Yannick Lecaillez</a>
* @author hans lellelid, hans@velum.net
* @version $Revision: 905 $ $Date: 2010-10-05 18:28:03 +0200 (Tue, 05 Oct 2010) $
* @access public
* @see FilterReader
* @package phing.filters
*/
class PrefixLines extends BaseParamFilterReader implements ChainableReader {
/**
* Parameter name for the prefix.
* @var string
*/
const PREFIX_KEY = "lines";
/**
* The prefix to be used.
* @var string
*/
private $_prefix = null;
/**
* Adds a prefix to each line of input stream and returns resulting stream.
*
* @return mixed buffer, -1 on EOF
*/
function read($len = null) {
if ( !$this->getInitialized() ) {
$this->_initialize();
$this->setInitialized(true);
}
$buffer = $this->in->read($len);
if ($buffer === -1) {
return -1;
}
$lines = explode("\n", $buffer);
$filtered = array();
foreach($lines as $line) {
$line = $this->_prefix . $line;
$filtered[] = $line;
}
$filtered_buffer = implode("\n", $filtered);
return $filtered_buffer;
}
/**
* Sets the prefix to add at the start of each input line.
*
* @param string $prefix The prefix to add at the start of each input line.
* May be <code>null</code>, in which case no prefix
* is added.
*/
function setPrefix($prefix) {
$this->_prefix = (string) $prefix;
}
/**
* Returns the prefix which will be added at the start of each input line.
*
* @return string The prefix which will be added at the start of each input line
*/
function getPrefix() {
return $this->_prefix;
}
/**
* Creates a new PrefixLines filter using the passed in
* Reader for instantiation.
*
* @param object A Reader object providing the underlying stream.
* Must not be <code>null</code>.
*
* @return object A new filter based on this configuration, but filtering
* the specified reader
*/
function chain(Reader $reader) {
$newFilter = new PrefixLines($reader);
$newFilter->setPrefix($this->getPrefix());
$newFilter->setInitialized(true);
$newFilter->setProject($this->getProject());
return $newFilter;
}
/**
* Initializes the prefix if it is available from the parameters.
*/
private function _initialize() {
$params = $this->getParameters();
if ( $params !== null ) {
for($i = 0, $_i=count($params) ; $i < $_i ; $i++) {
if ( self::PREFIX_KEY == $params[$i]->getName() ) {
$this->_prefix = (string) $params[$i]->getValue();
break;
}
}
}
}
}

Some files were not shown because too many files have changed in this diff Show More