Fatal error: Interface 'Zend\Config\Reader\ReaderInterface' - php

<?php
require_once BLOCKS_ROOT_ENGINE . "Zend/Loader/StandardAutoloader.php";
//require_once BLOCKS_ROOT_ENGINE."library/Zend/Config/Reader/Xml.php";
class Engine {
static public function start() {
$autoLoader = new Zend\Loader\StandardAutoloader(array(
'fallback_autoloader' => true,
));
// register our StandardAutoloader with the SPL autoloader
$autoLoader->register();
$config = new Engine_Zend_Config_Reader_Xml();
//echo $config->config->layout->default->head;
$root = new Core_Root_Blocks_Root();
}
}
The above is located in Engine/Engine.php
The Zend library is located in Engine/Zend/* The autoloader successfully finds the Xml class. But for some strange reason it can not find the interface it implements. what am i doing wrong.
Directory Structure
XML.php
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* #link http://github.com/zendframework/zf2 for the canonical source repository
* #copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* #license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Config\Reader;
use XMLReader;
use Zend\Config\Exception;
/**
* XML config reader.
*/
class Xml implements ReaderInterface
{
/**
* XML Reader instance.
*
* #var XMLReader
*/
protected $reader;
/**
* Directory of the file to process.
*
* #var string
*/
protected $directory;
/**
* Nodes to handle as plain text.
*
* #var array
*/
protected $textNodes = array(
XMLReader::TEXT,
XMLReader::CDATA,
XMLReader::WHITESPACE,
XMLReader::SIGNIFICANT_WHITESPACE
);
/**
* fromFile(): defined by Reader interface.
*
* #see ReaderInterface::fromFile()
* #param string $filename
* #return array
* #throws Exception\RuntimeException
*/
public function fromFile($filename)
{
if (!is_file($filename) || !is_readable($filename)) {
throw new Exception\RuntimeException(sprintf(
"File '%s' doesn't exist or not readable",
$filename
));
}
$this->reader = new XMLReader();
$this->reader->open($filename, null, LIBXML_XINCLUDE);
$this->directory = dirname($filename);
set_error_handler(
function ($error, $message = '', $file = '', $line = 0) use ($filename) {
throw new Exception\RuntimeException(sprintf(
'Error reading XML file "%s": %s',
$filename, $message
), $error);
}, E_WARNING
);
$return = $this->process();
restore_error_handler();
return $return;
}
/**
* fromString(): defined by Reader interface.
*
* #see ReaderInterface::fromString()
* #param string $string
* #return array|bool
* #throws Exception\RuntimeException
*/
public function fromString($string)
{
if (empty($string)) {
return array();
}
$this->reader = new XMLReader();
$this->reader->xml($string, null, LIBXML_XINCLUDE);
$this->directory = null;
set_error_handler(
function ($error, $message = '', $file = '', $line = 0) {
throw new Exception\RuntimeException(sprintf(
'Error reading XML string: %s',
$message
), $error);
}, E_WARNING
);
$return = $this->process();
restore_error_handler();
return $return;
}
/**
* Process data from the created XMLReader.
*
* #return array
*/
protected function process()
{
return $this->processNextElement();
}
/**
* Process the next inner element.
*
* #return mixed
*/
protected function processNextElement()
{
$children = array();
$text = '';
while ($this->reader->read()) {
if ($this->reader->nodeType === XMLReader::ELEMENT) {
if ($this->reader->depth === 0) {
return $this->processNextElement();
}
$attributes = $this->getAttributes();
$name = $this->reader->name;
if ($this->reader->isEmptyElement) {
$child = array();
} else {
$child = $this->processNextElement();
}
if ($attributes) {
if (!is_array($child)) {
$child = array();
}
$child = array_merge($child, $attributes);
}
if (isset($children[$name])) {
if (!is_array($children[$name]) || !array_key_exists(0, $children[$name])) {
$children[$name] = array($children[$name]);
}
$children[$name][] = $child;
} else {
$children[$name] = $child;
}
} elseif ($this->reader->nodeType === XMLReader::END_ELEMENT) {
break;
} elseif (in_array($this->reader->nodeType, $this->textNodes)) {
$text .= $this->reader->value;
}
}
return $children ?: $text;
}
/**
* Get all attributes on the current node.
*
* #return array
*/
protected function getAttributes()
{
$attributes = array();
if ($this->reader->hasAttributes) {
while ($this->reader->moveToNextAttribute()) {
$attributes[$this->reader->localName] = $this->reader->value;
}
$this->reader->moveToElement();
}
return $attributes;
}
}
ERROR

I think that you missed to set the include paths to Zend Framework library in your index.php file.
The autoloader class loads because you add require_once to the exact file with autoloader class definition. As I understand BLOCKS_ROOT_ENGINE constant is defined in your index.php.
Also I guess that you add somehow /opt/local/apache2/htdocs/blocks path to include paths in index.php - that is because autoloader is able to load Engine_Zend_Config_Reader_Xml class.
It is necessary to add BLOCKS_ROOT_ENGINE in your index.php to include paths list to allow autoloader find Zend\Config\Reader\ReaderInterface.

Not sure if this is your case, but once I ran into strange issues with my students with permission.
One student (with root permission) did something with folder permissions and we were not able to find out what - but files in that folder couldn't be accessible by php any more.
Even file_exists() returned false.
We finnaly resolve issue by copying whole folder, removing original one and renaming copied folder with original name.
Please check if your permissions are ok.

Well the issue had to do with out I set up my autoloader. I downloaded the skeleton ZF2 and found this file that was quite helpful for setting up
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* #link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* #copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* #license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* This autoloading setup is really more complicated than it needs to be for most
* applications. The added complexity is simply to reduce the time it takes for
* new developers to be productive with a fresh skeleton. It allows autoloading
* to be correctly configured, regardless of the installation method and keeps
* the use of composer completely optional. This setup should work fine for
* most users, however, feel free to configure autoloading however you'd like.
*/
// Composer autoloading
if (file_exists('vendor/autoload.php')) {
$loader = include 'vendor/autoload.php';
}
$zf2Path = false;
if (is_dir('vendor/ZF2/library')) {
$zf2Path = 'vendor/ZF2/library';
} elseif (getenv('ZF2_PATH')) { // Support for ZF2_PATH environment variable or git submodule
$zf2Path = getenv('ZF2_PATH');
} elseif (get_cfg_var('zf2_path')) { // Support for zf2_path directive value
$zf2Path = get_cfg_var('zf2_path');
}
if ($zf2Path) {
if (isset($loader)) {
$loader->add('Zend', $zf2Path);
} else {
include $zf2Path . '/Zend/Loader/AutoloaderFactory.php';
Zend\Loader\AutoloaderFactory::factory(array(
'Zend\Loader\StandardAutoloader' => array(
'autoregister_zf' => true
)
));
}
}
if (!class_exists('Zend\Loader\AutoloaderFactory')) {
throw new RuntimeException('Unable to load ZF2. Run `php composer.phar install` or define a ZF2_PATH environment variable.');
}

Related

How do I resolve Cannot use 'Object' as class name as it is reserved in C:\projectfolder\ckphp-demo\cake\libs\object.php on line 33

In working on a new cakephp application I get the error message Cannot use 'Object' as class name as it is reserved in C:\projectfolder\ckphp-demo\cake\libs\object.php on line 33.
The project is a legacy web application using cakePHP 1.3.17 with php version PHP 7.4.28 on developement server. see below code for object.php
line 33 is where class Object { starts
<?php
/**
* Object class, allowing __construct and __destruct in PHP4.
*
* Also includes methods for logging and the special method RequestAction,
* to call other Controllers' Actions from anywhere.
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* #copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* #link http://cakephp.org CakePHP(tm) Project
* #package cake
* #subpackage cake.cake.libs
* #since CakePHP(tm) v 0.2.9
* #license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Object class, allowing __construct and __destruct in PHP4.
*
* Also includes methods for logging and the special method RequestAction,
* to call other Controllers' Actions from anywhere.
*
* #package cake
* #subpackage cake.cake.libs
*/
class Object {
/**
* A hack to support __construct() on PHP 4
* Hint: descendant classes have no PHP4 class_name() constructors,
* so this constructor gets called first and calls the top-layer __construct()
* which (if present) should call parent::__construct()
*
* #return Object
*/
function Object() {
$args = func_get_args();
if (method_exists($this, '__destruct')) {
register_shutdown_function (array(&$this, '__destruct'));
}
call_user_func_array(array(&$this, '__construct'), $args);
}
/**
* Class constructor, overridden in descendant classes.
*/
function __construct() {
}
/**
* Object-to-string conversion.
* Each class can override this method as necessary.
*
* #return string The name of this class
* #access public
*/
function toString() {
$class = get_class($this);
return $class;
}
/**
* Calls a controller's method from any location. Can be used to connect controllers together
* or tie plugins into a main application. requestAction can be used to return rendered views
* or fetch the return value from controller actions.
*
* #param mixed $url String or array-based url.
* #param array $extra if array includes the key "return" it sets the AutoRender to true.
* #return mixed Boolean true or false on success/failure, or contents
* of rendered action if 'return' is set in $extra.
* #access public
*/
function requestAction($url, $extra = array()) {
if (empty($url)) {
return false;
}
if (!class_exists('dispatcher')) {
require CAKE . 'dispatcher.php';
}
if (in_array('return', $extra, true)) {
$extra = array_merge($extra, array('return' => 0, 'autoRender' => 1));
}
if (is_array($url) && !isset($extra['url'])) {
$extra['url'] = array();
}
$params = array_merge(array('autoRender' => 0, 'return' => 1, 'bare' => 1, 'requested' => 1), $extra);
$dispatcher = new Dispatcher;
return $dispatcher->dispatch($url, $params);
}
/**
* Calls a method on this object with the given parameters. Provides an OO wrapper
* for `call_user_func_array`
*
* #param string $method Name of the method to call
* #param array $params Parameter list to use when calling $method
* #return mixed Returns the result of the method call
* #access public
*/
function dispatchMethod($method, $params = array()) {
switch (count($params)) {
case 0:
return $this->{$method}();
case 1:
return $this->{$method}($params[0]);
case 2:
return $this->{$method}($params[0], $params[1]);
case 3:
return $this->{$method}($params[0], $params[1], $params[2]);
case 4:
return $this->{$method}($params[0], $params[1], $params[2], $params[3]);
case 5:
return $this->{$method}($params[0], $params[1], $params[2], $params[3], $params[4]);
default:
return call_user_func_array(array(&$this, $method), $params);
break;
}
}
/**
* Stop execution of the current script. Wraps exit() making
* testing easier.
*
* #param $status see http://php.net/exit for values
* #return void
* #access public
*/
function _stop($status = 0) {
exit($status);
}
/**
* Convience method to write a message to CakeLog. See CakeLog::write()
* for more information on writing to logs.
*
* #param string $msg Log message
* #param integer $type Error type constant. Defined in app/config/core.php.
* #return boolean Success of log write
* #access public
*/
function log($msg, $type = LOG_ERROR) {
if (!class_exists('CakeLog')) {
require LIBS . 'cake_log.php';
}
if (!is_string($msg)) {
$msg = print_r($msg, true);
}
return CakeLog::write($type, $msg);
}
/**
* Allows setting of multiple properties of the object in a single line of code. Will only set
* properties that are part of a class declaration.
*
* #param array $properties An associative array containing properties and corresponding values.
* #return void
* #access protected
*/
function _set($properties = array()) {
if (is_array($properties) && !empty($properties)) {
$vars = get_object_vars($this);
foreach ($properties as $key => $val) {
if (array_key_exists($key, $vars)) {
$this->{$key} = $val;
}
}
}
}
/**
* Used to report user friendly errors.
* If there is a file app/error.php or app/app_error.php this file will be loaded
* error.php is the AppError class it should extend ErrorHandler class.
*
* #param string $method Method to be called in the error class (AppError or ErrorHandler classes)
* #param array $messages Message that is to be displayed by the error class
* #return error message
* #access public
*/
function cakeError($method, $messages = array()) {
if (!class_exists('ErrorHandler')) {
App::import('Core', 'Error');
if (file_exists(APP . 'error.php')) {
include_once (APP . 'error.php');
} elseif (file_exists(APP . 'app_error.php')) {
include_once (APP . 'app_error.php');
}
}
if (class_exists('AppError')) {
$error = new AppError($method, $messages);
} else {
$error = new ErrorHandler($method, $messages);
}
return $error;
}
/**
* Checks for a persistent class file, if found file is opened and true returned
* If file is not found a file is created and false returned
* If used in other locations of the model you should choose a unique name for the persistent file
* There are many uses for this method, see manual for examples
*
* #param string $name name of the class to persist
* #param string $object the object to persist
* #return boolean Success
* #access protected
* #todo add examples to manual
*/
function _persist($name, $return = null, &$object, $type = null) {
$file = CACHE . 'persistent' . DS . strtolower($name) . '.php';
if ($return === null) {
if (!file_exists($file)) {
return false;
} else {
return true;
}
}
if (!file_exists($file)) {
$this->_savePersistent($name, $object);
return false;
} else {
$this->__openPersistent($name, $type);
return true;
}
}
/**
* You should choose a unique name for the persistent file
*
* There are many uses for this method, see manual for examples
*
* #param string $name name used for object to cache
* #param object $object the object to persist
* #return boolean true on save, throws error if file can not be created
* #access protected
*/
function _savePersistent($name, &$object) {
$file = 'persistent' . DS . strtolower($name) . '.php';
$objectArray = array(&$object);
$data = str_replace('\\', '\\\\', serialize($objectArray));
$data = '<?php $' . $name . ' = \'' . str_replace('\'', '\\\'', $data) . '\' ?>';
$duration = '+999 days';
if (Configure::read() >= 1) {
$duration = '+10 seconds';
}
cache($file, $data, $duration);
}
/**
* Open the persistent class file for reading
* Used by Object::_persist()
*
* #param string $name Name of persisted class
* #param string $type Type of persistance (e.g: registry)
* #return void
* #access private
*/
function __openPersistent($name, $type = null) {
$file = CACHE . 'persistent' . DS . strtolower($name) . '.php';
include($file);
switch ($type) {
case 'registry':
$vars = unserialize(${$name});
foreach ($vars['0'] as $key => $value) {
if (strpos($key, '_behavior') !== false) {
App::import('Behavior', Inflector::classify(substr($key, 0, -9)));
} else {
App::import('Model', Inflector::camelize($key));
}
unset ($value);
}
unset($vars);
$vars = unserialize(${$name});
foreach ($vars['0'] as $key => $value) {
ClassRegistry::addObject($key, $value);
unset ($value);
}
unset($vars);
break;
default:
$vars = unserialize(${$name});
$this->{$name} = $vars['0'];
unset($vars);
break;
}
}
}

Fatal error: Uncaught Error: Class 'App\Database' not found

I try to learn oop but in my first class it gives me this error.
Database class
<?php
namespace App;
class Database
{
...
}
in my functions.php
<?php
require 'helpers.php';
require 'connection.php';
use App\Database;
...
Class under the "app" folder and it's namespace is "App". Why I'm getting this error ?
You either need to include the file, or use an AutoLoader. AutoLoaders tell PHP where a class can be found, as PHP needs to know the file.
Autoloaders are fully explained in the PHP documentation:
https://secure.php.net/manual/en/language.oop5.autoload.php
Example from the mentioned documentation:
<?php
spl_autoload_register(function ($class_name) {
include $class_name . '.php';
});
$obj = new MyClass1();
$obj2 = new MyClass2();
?>
In this case spl_autoload_register is used to register the autoloader. The autoloader is a function which takes the class name, and includes the necessary class. For example you can use the autoloader function as used above, in which case the class name needs to be identical to the filename.
This is a quite simple example, but a more advanced autoloader could check if files exist, check multiple locations, etc...
Examples are mentioned in the comments on your original question.
note: You will find other sources mentioning the __autoload($class) function. This function does exactly the same, but will be removed from PHP in future updates. Therefore, you are better off using spl_autoload_register
Because I posted my Autoloader in the comments.
https://github.com/ArtisticPhoenix/MISC/blob/master/Autoloader.php
You can find the code at the bottom of this post:
The basic usage is as follows:
require_once 'Autoloader.php';
AutoLoader::getInstance()->regesterPath('\\', __DIR__);
This assumes it's in the directory that is the root of you namespace. So if you have a class.
namespace App;
class Database{ ... }
And this class is in
www
|- Autoloader.php
|- App
| --Database.php
Then it will look for __DIR__ + Namespace or __DIR__/APP/. You can register paths because if you have this setup.
www
|- Autoloader.php
|- includes
|-- App
| ---Database.php
Where the class is located in includes/App and Autoloader is in / the root folder you can do it this way.
require_once 'Autoloader.php';
AutoLoader::getInstance()->regesterPath('\\', __DIR__.'/includes/');
Also if you have it setup like this.
www
|- Autoloader.php
|- includes
| --Database.php
Where there is no actual App folder then you can do it like this.
require_once 'Autoloader.php';
AutoLoader::getInstance()->regesterPath('\\App\\', __DIR__.'/includes/');
Or any combination of the above.
It will account for the differences between \\App. App and \\App\\ for the most part. But you can also turn on debugging with this.
require_once 'Autoloader.php';
$AutoLoader = AutoLoader::getInstance();
$AutoLoader->setDebug(true);
$AutoLoader>regesterPath('\\App\\', __DIR__.'/includes/');
And it will spit out a bunch of stuff telling you where it is looking. You may have to use <pre> to keep the whitespace format, if your working in HTML. Conveniently you can also turn off Debugging, because you may be autoloading a bunch of classes.
$AutoLoader->setDebug(false);
You can also assign multiple paths, and give them a priority and it will look in them in the order of the priority. But that is not really important in this case.
So for example:
I have a folder
www
|-MISC
|--index.php
|--Autoloader.php
|---IMAP
|----GmailClient.php
Which is also in the same Git Repo. It has the namespace of Lib\Email\IMAP of which only the IMAP exists.
And to load It if I do this in index.php, which is inside the MISC file and at the same level as the AutoLoader.php file:
//include the Autoloader
require_once __DIR__.'/Autoloader.php';
//get an instance of it (Singleton pattern)
$Autoloader = Autoloader::getInstance();
//regester a namespace, path pair
$Autoloader->regesterPath('Lib\Email', __DIR__.'/IMAP/');
//preserve whitespace
echo "<pre>";
//turn on debugging before a problem class
$Autoloader->setDebug(true);
//Attempt to load the class as normal
$G = new GmailClient($hostname, $username, $password);
//turn off debugging after trying to load a problem class.
$AutoLoader->setDebug(false);
This is what it Outputs for debugging
================================= Autoloader::debugMode ==================================
Autoloader::splAutoload Lib\Email\IMAP\GmailClient
Checking class: GmailClient
Checking namespace: Lib/Email/IMAP
checking pathname:C:/Server/www/MISC/IMAP/IMAP/GmailClient.php
==========================================================================================
Right away we can see C:/Server/www/MISC/IMAP/IMAP/GmailClient.php That IMAP is in there 2x. This is because I included that in the path, So it starts looking in C:/Server/www/MISC/IMAP/ and then adds the namespace that wasn't given in the namespace arg IMAP from Lib/Email/IMAP. We gave it Lib/Email as the first argument. So essentially, because this was part of the path it's already in that folder when it looks for that.
So If I just remove that IMAP from the path:
$Autoloader->regesterPath('Lib\Email', __DIR__);
It will output this:
================================= Autoloader::debugMode ==================================
Autoloader::splAutoload Lib\Email\IMAP\GmailClient
Checking class: GmailClient
Checking namespace: Lib/Email/IMAP
checking pathname:C:/Server/www/MISC/IMAP/GmailClient.php
Found: C:/Server/www/MISC/IMAP/GmailClient.php
==========================================================================================
With the most important line being this
Found: C:/Server/www/MISC/IMAP/GmailClient.php
Which obviously means that it found the class file and loaded it.
Hope that makes sense.
Following is the full code for the autoloader, that way the answer wont break if anything changes with the Repo I linked.
<?php
/**
*
* (c) 2016 ArtisticPhoenix
*
* For license information please view the LICENSE file included with this source code. GPL-3
*
* PSR4 compatible Autoloader
*
* #author ArtisticPhoenix
* #see http://www.php-fig.org/psr/psr-4/
*
* #example
* $Autoloader = Autoloader::getInstance();
* //looks in includes for folder named /includes/Lib/Auth/User/
* $Autoloader->regesterPath('Lib\\Auth\\User', __DIR__.'/includes/');
*
*/
final class Autoloader
{
/**
*
* #var int
*/
const DEFAULT_PRIORITY = 10;
/**
* namespace / class path storage
* #var array
*/
private $paths = array();
/**
* cashe the loaded files
* #var array
*/
private $files = array();
/**
* namespace / class path storage
* #var array
*/
private $debugMode = false;
/**
*
* #var Self
*/
private static $instance;
/**
* No public construction allowed - Singleton
*/
private function __construct($throw, $prepend)
{
spl_autoload_register(array( $this,'splAutoload'), $throw, $prepend);
}
/**
* No cloning of allowed
*/
private function __clone()
{
}
/**
*
* Get an instance of the Autoloader Singleton
* #param boolean $throw
* #param boolean $prepend
* #return self
*/
public static function getInstance($throw = false, $prepend = false)
{
if (!self::$instance) {
self::$instance = new self($throw, $prepend);
}
return self::$instance;
}
/**
* set debug output
* #param boolean $debug
* #return self
*/
public function setDebug($debug = false)
{
$this->debugMode = $debug;
return $this;
}
/**
* Autoload
* #param string $class
*/
public function splAutoload($class)
{
$this->debugMode('_START_');
$this->debugMode(__METHOD__.' '.$class);
//keep the orignal class name
$_class = str_replace('\\', '/', $class);
$namespace = '';
if (false !== ($pos = strrpos($_class, '/'))) {
$namespace = substr($_class, 0, ($pos));
$_class = substr($_class, ($pos + 1));
}
//replace _ in class name only
if (false !== ($pos = strrpos($_class, '/'))) {
if (strlen($namespace)) {
$namespace .= '/'.substr($_class, 0, ($pos));
} else {
$namespace = substr($_class, 0, ($pos));
}
$_class = substr($_class, ($pos + 1));
}
$this->debugMode("Checking class: $_class");
$this->debugMode("Checking namespace: $namespace");
do {
if (isset($this->paths[ $namespace ])) {
foreach ($this->paths[ $namespace ] as $registered) {
$filepath = $registered['path'] . $_class . '.php';
$this->debugMode("checking pathname:{$filepath}");
if (file_exists($filepath)) {
$this->debugMode("Found: $filepath");
$this->debugMode('_END_');
require_once $filepath;
$this->files[$class] = $filepath;
}
}
}
if (strlen($namespace) == 0) {
//if the namespace is empty and we couldn't find the class we are done.
break;
}
if (false !== ($pos = strrpos($namespace, '/'))) {
$_class = substr($namespace, ($pos + 1)) . '/' . $_class;
$namespace = substr($namespace, 0, ($pos));
} else {
$_class = (strlen($namespace) ? $namespace : '') . '/' . $_class;
$namespace = '';
}
} while (true);
$this->debugMode('_END_');
}
/**
* get the paths regestered for a namespace, leave null go get all paths
* #param string $namespace
* #return array or false on falure
*/
public function getRegisteredPaths($namespace = null)
{
if (is_null($namespace)) {
return $this->paths;
} else {
return (isset($this->paths[$namespace])) ? array($namespace => $this->paths[$namespace]) : false;
}
}
/**
*
* #param string $namespace
* #param string $path
* #param int $priority
* #return self
*/
public function regesterPath($namespace, $path, $priority = self::DEFAULT_PRIORITY)
{
$namespace = str_replace('\\', '/', $namespace); //convert to directory seperator
$path = ($this->normalizePath($path));
$this->paths[$namespace][sha1($path)] = array(
'path' => $path,
'priority' => $priority
);
$this->sortByPriority($namespace);
return $this;
}
/**
* un-regester a path
* #param string $namespace
* #param string $path
*/
public function unloadPath($namespace, $path = null)
{
if ($path) {
$path = $this->normalizePath($path);
unset($this->paths[$namespace][sha1($path)]);
} else {
unset($this->paths[$namespace]);
}
}
/**
* check if a namespace is regestered
* #param string $namespace
* #param string $path
* #return bool
*/
public function isRegistered($namespace, $path = null)
{
if ($path) {
$path = $this->normalizePath($path);
return isset($this->paths[$namespace][sha1($path)]) ? true : false;
} else {
return isset($this->paths[$namespace]) ? true : false;
}
}
/**
* get the file pathname of a loaded class
* #param string $class
* #return mixed
*/
public function getLoadedFile($class = null)
{
if (!$class) {
return $this->files;
}
if (isset($this->files[$class])) {
return $this->files[$class];
}
}
/**
* output debug message
* #param string $message
*/
protected function debugMode($message)
{
if (!$this->debugMode) {
return;
}
switch ($message) {
case '_START_':
echo str_pad("= ".__METHOD__." =", 90, "=", STR_PAD_BOTH) . PHP_EOL;
break;
case '_END_':
echo str_pad("", 90, "=", STR_PAD_BOTH) . PHP_EOL . PHP_EOL;
break;
default:
echo $message . PHP_EOL;
}
}
/**
* sort namespaces by priority
* #param string $namespace
*/
protected function sortByPriority($namespace)
{
uasort($this->paths[$namespace], function ($a, $b) {
return ($a['priority'] > $b['priority']) ? true : false;
});
}
/**
* convert a path to unix seperators and make sure it has a trailing slash
* #param string $path
* #return string
*/
protected function normalizePath($path)
{
if (false !== strpos($path, '\\')) {
$path = str_replace("\\", "/", $path);
}
return rtrim($path, '/') . '/';
}
}
P.S. the GmailClient class I used in this example, I wrote to parse incoming Emails in a Gmail account. It's not 100% fleshed out as we needed it for a specific purpose. But it is in the same GitHub repository.

Php class exception error message

I'm struggling with fixing this class exception error. If anyone could help it would be greatly appreciated, Thanks!
BACKGROUND INFO:
After installing a Dashnex plugin on my wordpress site & then uninstalling WP Quick cache I am getting this error message. Please note that quick cache is fully uninstalled & the wp-config.php file includes no quick cache instructions.
ERROR MESSAGE:
Fatal error: Uncaught exception 'ReflectionException' with message 'Class \quick_cache does not exist' in /home/cal108/public_html/wp-content/plugins/dashnex-plugin/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/AnnotationDriver.php:246 Stack trace: #0 /home/cal108/public_html/wp-content/plugins/dashnex-plugin/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/AnnotationDriver.php(246): ReflectionClass->__construct('\quick_cache') #1 /home/cal108/public_html/wp-content/plugins/dashnex-plugin/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php(113): Doctrine\Common\Persistence\Mapping\Driver\AnnotationDriver->getAllClassNames() #2 /home/cal108/public_html/wp-content/plugins/dashnex-plugin/DashNex/Doctrine/MagicSchema.php(18): Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getAllMetadata() #3 /home/cal108/public_html/wp-content/plugins/dashnex-plugin/DashNex/Doctrine/MagicSchema.php(37): DashNex\Doctrine\MagicSchema->Get in /home/cal108/public_html/wp-content/plugins/dashnex-plugin/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/AnnotationDriver.php on line 246
AnnotationDriver.php Line 246
$rc = new \ReflectionClass($className);
AnnotationDriver.php File
<?php
abstract class AnnotationDriver implements MappingDriver
{
/**
* The AnnotationReader.
*
* #var AnnotationReader
*/
protected $reader;
/**
* The paths where to look for mapping files.
*
* #var array
*/
protected $paths = array();
/**
* The paths excluded from path where to look for mapping files.
*
* #var array
*/
protected $excludePaths = array();
/**
* The file extension of mapping documents.
*
* #var string
*/
protected $fileExtension = '.php';
/**
* Cache for AnnotationDriver#getAllClassNames().
*
* #var array|null
*/
protected $classNames;
/**
* Name of the entity annotations as keys.
*
* #var array
*/
protected $entityAnnotationClasses = array();
/**
* Initializes a new AnnotationDriver that uses the given AnnotationReader for reading
* docblock annotations.
*
* #param AnnotationReader $reader The AnnotationReader to use, duck-typed.
* #param string|array|null $paths One or multiple paths where mapping classes can be found.
*/
public function __construct($reader, $paths = null)
{
$this->reader = $reader;
if ($paths) {
$this->addPaths((array) $paths);
}
}
/**
* Appends lookup paths to metadata driver.
*
* #param array $paths
*
* #return void
*/
public function addPaths(array $paths)
{
$this->paths = array_unique(array_merge($this->paths, $paths));
}
/**
* Retrieves the defined metadata lookup paths.
*
* #return array
*/
public function getPaths()
{
return $this->paths;
}
/**
* Append exclude lookup paths to metadata driver.
*
* #param array $paths
*/
public function addExcludePaths(array $paths)
{
$this->excludePaths = array_unique(array_merge($this->excludePaths, $paths));
}
/**
* Retrieve the defined metadata lookup exclude paths.
*
* #return array
*/
public function getExcludePaths()
{
return $this->excludePaths;
}
/**
* Retrieve the current annotation reader
*
* #return AnnotationReader
*/
public function getReader()
{
return $this->reader;
}
/**
* Gets the file extension used to look for mapping files under.
*
* #return string
*/
public function getFileExtension()
{
return $this->fileExtension;
}
/**
* Sets the file extension used to look for mapping files under.
*
* #param string $fileExtension The file extension to set.
*
* #return void
*/
public function setFileExtension($fileExtension)
{
$this->fileExtension = $fileExtension;
}
/**
* Returns whether the class with the specified name is transient. Only non-transient
* classes, that is entities and mapped superclasses, should have their metadata loaded.
*
* A class is non-transient if it is annotated with an annotation
* from the {#see AnnotationDriver::entityAnnotationClasses}.
*
* #param string $className
*
* #return boolean
*/
public function isTransient($className)
{
$classAnnotations = $this->reader->getClassAnnotations(new \ReflectionClass($className));
foreach ($classAnnotations as $annot) {
if (isset($this->entityAnnotationClasses[get_class($annot)])) {
return false;
}
}
return true;
}
/**
* {#inheritDoc}
*/
public function getAllClassNames()
{
if ($this->classNames !== null) {
return $this->classNames;
}
if (!$this->paths) {
throw MappingException::pathRequired();
}
$classes = array();
$includedFiles = array();
foreach ($this->paths as $path) {
if ( ! is_dir($path)) {
throw MappingException::fileMappingDriversRequireConfiguredDirectoryPath($path);
}
$iterator = new \RegexIterator(
new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS),
\RecursiveIteratorIterator::LEAVES_ONLY
),
'/^.+' . preg_quote($this->fileExtension) . '$/i',
\RecursiveRegexIterator::GET_MATCH
);
foreach ($iterator as $file) {
$sourceFile = $file[0];
if ( ! preg_match('(^phar:)i', $sourceFile)) {
$sourceFile = realpath($sourceFile);
}
foreach ($this->excludePaths as $excludePath) {
$exclude = str_replace('\\', '/', realpath($excludePath));
$current = str_replace('\\', '/', $sourceFile);
if (strpos($current, $exclude) !== false) {
continue 2;
}
}
require_once $sourceFile;
$includedFiles[] = $sourceFile;
}
}
$declared = get_declared_classes();
foreach ($declared as $className) {
$rc = new \ReflectionClass($className);
$sourceFile = $rc->getFileName();
if (in_array($sourceFile, $includedFiles) && ! $this->isTransient($className)) {
$classes[] = $className;
}
}
$this->classNames = $classes;
return $classes;
}
}
I WAS ABLE TO SOLVE MY PROBLEM. HELP NOT NEEDED ANYMORE :)
FOR ANYONE THIS MAY STILL HELP:
I DISABLED ALL OF MY PLUGINS BY RENAMING THEM IT IN CPANEL, THEN BROUGHT EACH ONE ONLINE AGAIN TO KNOW IF THE DASHNEX PLUGIN WAS THE CULPRIT. IT WAS. THEN RENAMED ALL PLUGINS AGAIN & ALL WORKING FINE.
I DON'T THINK THE DASHNEX PLUGIN LIKED MY UNINSTALLING WP QUICK CACHE. BUT REINSTALLING IT AFTER WP QUCIK CACHE HAD ALREADY BEEN UNINSTALLED WORKED FINE. THIS IS THE 2ND TIME I'VE HAD PROBLEMS WHEN QUICK CACHE HAS BEEN UNINSTALLED SO BE WARY OF IT. MAYBE BEST TO JUST DEACTIVATE IT & ONLY UNINSTALL IT ON A BRAND NEW SITE BEFORE INSTALLING ANY OTHER PLUGINS.
DIDN'T END UP NEEDING TO TWEAK THE PHP CODE.

Why show OWASP Mutillidae II php WARING in kali linux?

When i open https://127.0.0.1/mutillidae/ then my webpage show this error
I also change the permission of LoggerAppenderFile.php but it still error.
The php file code is
<?php
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
* #package log4php
* #subpackage appenders
*/
/**
* FileAppender appends log events to a file.
*
* Parameters are ({#link $fileName} but option name is <b>file</b>),
* {#link $append}.
*
* #version $Revision: 806678 $
* #package log4php
* #subpackage appenders
*/
class LoggerAppenderFile extends LoggerAppender {
/**
* #var boolean if {#link $file} exists, appends events.
*/
private $append = true;
/**
* #var string the file name used to append events
*/
protected $fileName;
/**
* #var mixed file resource
*/
protected $fp = false;
public function __construct($name = '') {
parent::__construct($name);
$this->requiresLayout = true;
}
public function __destruct() {
$this->close();
}
public function activateOptions() {
$fileName = $this->getFile();
if(!is_file($fileName)) {
$dir = dirname($fileName);
if(!is_dir($dir)) {
mkdir($dir, 0777, true);
}
}
$this->fp = fopen($fileName, ($this->getAppend()? 'a':'w'));
if($this->fp) {
if(flock($this->fp, LOCK_EX)) {
if($this->getAppend()) {
fseek($this->fp, 0, SEEK_END);
}
fwrite($this->fp, $this->layout->getHeader());
flock($this->fp, LOCK_UN);
$this->closed = false;
} else {
// TODO: should we take some action in this case?
$this->closed = true;
}
} else {
$this->closed = true;
}
}
public function close() {
if($this->closed != true) {
if($this->fp and $this->layout !== null) {
if(flock($this->fp, LOCK_EX)) {
fwrite($this->fp, $this->layout->getFooter());
flock($this->fp, LOCK_UN);
}
fclose($this->fp);
}
$this->closed = true;
}
}
public function append(LoggerLoggingEvent $event) {
if($this->fp and $this->layout !== null) {
if(flock($this->fp, LOCK_EX)) {
fwrite($this->fp, $this->layout->format($event));
flock($this->fp, LOCK_UN);
} else {
$this->closed = true;
}
}
}
/**
* Sets and opens the file where the log output will go.
*
* This is an overloaded method. It can be called with:
* - setFile(string $fileName) to set filename.
* - setFile(string $fileName, boolean $append) to set filename and append.
*/
public function setFile() {
$numargs = func_num_args();
$args = func_get_args();
if($numargs == 1 and is_string($args[0])) {
$this->setFileName($args[0]);
} else if ($numargs >=2 and is_string($args[0]) and is_bool($args[1])) {
$this->setFile($args[0]);
$this->setAppend($args[1]);
}
}
/**
* #return string
*/
public function getFile() {
return $this->getFileName();
}
/**
* #return boolean
*/
public function getAppend() {
return $this->append;
}
public function setAppend($flag) {
$this->append = LoggerOptionConverter::toBoolean($flag, true);
}
public function setFileName($fileName) {
$this->fileName = $fileName;
}
/**
* #return string
*/
public function getFileName() {
return $this->fileName;
}
}
How can i solve this problem ?
I found a solution in http://fanli7.net/a/bianchengyuyan/PHP/20130723/398120.html here but i failed. If this problem is unsolvable then it can occur a big problem for my lab testing ?
OK. I find the solution. Actually you setup a old version of mutillidae. So it was buggy program. Then i find a new version. Here is the download link enter link description here. After you setup it,it will be awesome.

How to use openinviter in zend framework

Hi
Can anyone tell me how to use openinviter script in zend framework
I have used Open Invitor in one of my projects by following a tutorials. Unfortunately, I couldn't find out the link. Here are the main steps:
(a) Create a custom library. To do this, create a folder inside library (library/openinvitor)
(b) Install the Open Invitor Package inside this library (ie library/openinvitor/install.php). I did this by commenting index & htaccess during the installation.
(c) Register new library in the Boot Strap. (Copy the line needed for the Open Invitor Loading)
protected function _initAutoload ()
{
// Add autoloader empty namespace
$autoLoader = Zend_Loader_Autoloader::getInstance();
$autoLoader->registerNamespace('openinviter_');
$resourceLoader = new Zend_Loader_Autoloader_Resource(array('basePath' => APPLICATION_PATH , 'namespace' => '' , 'resourceTypes' => array('form' => array('path' => 'forms/' , 'namespace' => 'Form_') , 'model' => array('path' => 'models/' , 'namespace' => 'Model_'))));
// Return it so that it can be stored by the bootstrap
return $autoLoader;
}
(d) The file name of the library file is: Service.php Also note the name of the class in the step (e)
(e) The content of the Service file is:
<?php
require_once 'openinviter.php';
/**
* This class is the connection between OpenInviter service and Zend Framework.
* The class is implemented only for extracting contacts.
*
* #tutorial
*
* $inviter = new OpenInviter_Service();
*
* p($inviter->getPlugins());// get all services
* p($inviter->getPlugins('email'));// get all services
* p($inviter->getPlugins('email', 'gmail'));// get gmail plugin properties
* p($inviter->getPlugins('email', 'gmail', 'version'));// get gmail plugin version
*
* // get contacts
* p($inviter->getContacts('me#example.com', 'mypass', 'example'));
*
*
* #author stoil
* #link http://openinviter.com/
* #uses OpenInviter 1.7.6
*
*/
class openinviter_Service
{
const PATH_PLUGINS = 'plugins/';
protected $_messages = array();
protected $_plugins;
protected $_openInviter;
/*~~~~~~~~~~ private methods ~~~~~~~~~~*/
private function _loadPlugins()
{
if($this->_plugins === null) {
$this->_plugins = $this->getOpenInviter()->getPlugins(false);
}
}
/*~~~~~~~~~~ protected methods ~~~~~~~~~~*/
protected function _addMessage($code, $message, $type = 'error')
{
$this->_messages[$type][$code] = $message;
}
protected function _initAutoload()
{
set_include_path(
dirname(realpath(__FILE__)) . DIRECTORY_SEPARATOR . self::PATH_PLUGINS.
PATH_SEPARATOR.
get_include_path()
);
}
/*~~~~~~~~~~ constructor ~~~~~~~~~~*/
public function __construct()
{
$this->_initAutoload();
$this->_openInviter = new openinviter();
$this->_loadPlugins();
}
/*~~~~~~~~~~ public methods ~~~~~~~~~~*/
/**
* Update plugins
*/
public function updatePlugins()
{
$this->_plugins = $this->getOpenInviter()->getPlugins(true);
}
/**
* Get plugin(s), provider(s) or provider details
* #param $type
* #param $provider
* #param $detail
* #return unknown_type
*/
public function getPlugins($type = null, $provider = null, $detail = null)
{
if ($type !== null) {
if ($provider !== null) {
if ($detail !== null) {
return $this->_plugins[$type][$provider][$detail];
} else {
return $this->_plugins[$type][$provider];
}
} else {
return $this->_plugins[$type];
}
} else {
return $this->_plugins;
}
}
/**
* #return openinviter
*/
protected function getOpenInviter()
{
return $this->_openInviter;
}
/**
* Get system messages
* #param string $type
* #return array
*/
public function getMessages($type = null)
{
if($type !== null) {
return $this->_messages[$type];
} else {
return $this->_messages;
}
}
/**
* Get email clients
* #param string $email
* #param string $password
* #param string $provider
* #return array
*/
public function getContacts($email, $password, $provider)
{
$contacts = array();
$this->getOpenInviter()->startPlugin($provider);
$internalError = $this->getOpenInviter()->getInternalError();
if ($internalError) {
$this->_addMessage('inviter', $internalError);
} elseif (! $this->getOpenInviter()->login($email, $password)) {
$internalError = $this->getOpenInviter()->getInternalError();
$this->_addMessage(
'login',
($internalError
? $internalError
: 'Login failed. Please check the email and password you have provided and try again later !'
)
);
} elseif (false === $contacts = $this->getOpenInviter()->getMyContacts()) {
$this->_addMessage('contacts', 'Unable to get contacts');
}
return $contacts;
}
}
(f) Then in the desired controller/function, create an object of the Open Invitor librray and access any functions.
$inviter = new openinviter_Service(); // Create the Object of Opne Invitor
$plugins = $inviter->getPlugins('email'); // Read all Available Plugins.

Categories