Unknown parser class "PropelArrayParser" - php

I'm new to Propel and I need to work with a website that was already setup with Propel (1.6.9).
I got this working on my laptop and generated without any errors. (Yay!)
After generating classes (on the same schema.xml and other related files as earlier on) there seem to be some differences. (spotted in file sizes) When I uploaded these files to the web hosting where the old files were doing a fine job, I ran into an error:
Fatal error: Uncaught exception 'PropelException' with message 'Unknown parser class "PropelArrayParser"' in /var/www/vhosts/10/154462/webspace/httpdocs/DOMAIN/vendor/propel/propel1/runtime/lib/parser/PropelParser.php:101
Stack trace:
#0 /var/www/vhosts/10/154462/webspace/httpdocs/DOMAIN/vendor/propel/propel1/runtime/lib/om/BaseObject.php(375): PropelParser::getParser('Array')
#1 /var/www/vhosts/10/154462/webspace/httpdocs/DOMAIN/vendor/propel/propel1/runtime/lib/om/BaseObject.php(424): BaseObject->exportTo('Array', 'fieldName')
#2 /var/www/vhosts/10/154462/webspace/httpdocs/DOMAIN/src/controllers/UsersController.php(26): BaseObject->__call('toArray', Array)
#3 /var/www/vhosts/10/154462/webspace/httpdocs/DOMAIN/src/controllers/UsersController.php(26): User->toArray('fieldName')
#4 /var/www/vhosts/10/154462/webspace/httpdocs/DOMAIN/framework/framework.php(196): require('/var/www/vhosts...')
#5 /var/www/vhosts/10/154462/web in /var/www/vhosts/10/154462/webspace/httpdocs/DOMAIN/vendor/propel/propel1/runtime/lib/parser/PropelParser.php on line 101
The error is referring to:
$case = new AgencyCosts();
$case->fromArray($_POST, BasePeer::TYPE_FIELDNAME);
$case->save();
So I figured something was wrong with includes. That's why I added the following to my init.php:
set_include_path(dirname(DIR) . '/vendor/propel/propel1/runtime/lib/parser' . PATH_SEPARATOR . get_include_path());
require dirname(DIR) . '/vendor/propel/propel1/runtime/lib/parser/PropelJSONParser.php';
Without any success.
The init.php (where the including is done) is available here.
Any help would be appreciated.

You're getting this exception when Propel cannot find the class definition. From Propel's code:
// PropelParse::getParser
if (!class_exists($class)) {
throw new PropelException(sprintf('Unknown parser class "%s"', $class));
}
Propel generates a classmap file, where the paths of all Propel's classes are written. It seems like you just get the wrong file included or wrong paths in it. Take a look at your configuration file for the classmap key:
$conf['classmap'] = include(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'classmap-<you-project-name>-conf.php');
And then examine the contents of that file. It might happen because you blindly moved the files from your computer to the server.

Related

use of class with namespace error

in api.php i use severall classes, with autoloaders. in include them like this
use \protoware\cms\Account as Account;
use \protoware\cms\Content as Content;
use protoware\cms\Count as Count;
include __DIR__ . '/vendor/autoload.php';
Local this works fine, when i upload it on a server i get this
Europe/Brussels] PHP Fatal error: Uncaught Error: Class 'protoware\cms\Content' not found in /data/vhosts/achielvolckaert.be/wwwroot/api.php:97
Stack trace:
#0 {main}
thrown in /data/vhosts/achielvolckaert.be/wwwroot/api.php on line 97
line 97 is the first line where i open a connection:
$content = new protoware\cms\Content();
$data = $content->get_content('medisch');
I have 0 clue how to fix this, i updated autloader, checked if all files were uploaded...
Try add a \ before class name, like $content = new \protoware\cms\Content(); or just $content = new Content() since you have a use statement.
If this class is a dependency, check if its correctly installed (inside your vendor folder, i.e.). Maybe run composer install?

php - Class not found (composer.json)

I'm trying to implement a PHP Library for detecting CMS I found on github, but I can't for the life of me figure it out.
I am new to php and composer, but I installed composer in my directory, then updated the json as instructed, but it cannot find the classes, despite them all being in the directory.
running this code
include(__DIR__ . "/vendor/autoload.php");
$domain = "http://google.com";
$cms = new DetectCMS($domain);
if($cms->getResult()) {
echo "Detected CMS: ".$cms->getResult();
} else {
echo "CMS couldn't be detected";
}
gives me this error
PHP Fatal error: Uncaught Error: Class 'DetectCMS' not found in D:\Projects\Scraper\ccc.php:12
Stack trace:
#0 {main}
thrown in D:\Projects\Scraper\ccc.php on line 12
here is my file structure:
would anyone have any idea what I'm doing wrong with this information?
Thanks in advance
I think to include a class using the autoloader,in your class, you must do something about it:
in your composer.json
"autoload": {
"psr-4" :{"DetectCMS": "DetectCMS"}
}
after in your class DetectCMS.php:
<?php
use DetectCMS\DetectCMS;
or
<?php
$loader = require 'vendor/autoload.php';
$loader->add('DetectCMS', __DIR__.'DetectCMS');

PHP tries to Autoload Random Class Name

A customer of mine is reporting an odd problem with some code in their Magento system (Magento is an ecommerce platform written in PHP). I don't have direct access to the system to poke around and debug, so I thought I'd ask Stack Overflow if you've ever seen anything like this.
The error they're occasionally seeing is
Warning: include(O1ucm02owqn3iwwcx5osz2m2.php): failed to open stream:
With a call stack that includes
#0 /Users/theirusername/Sites/project/lib/Varien/Autoload.php(93): mageCoreErrorHandler(2, 'include(O1ucm02...', '/Users/theiruse...', 93, Array)
#1 /Users/theirusername/Sites/project/lib/Varien/Autoload.php(93): Varien_Autoload::autoload()
#2 [internal function]: Varien_Autoload->autoload('o1ucm02owqn3iww...')
#3 [internal function]: spl_autoload_call('o1ucm02owqn3iww...')
#4 /Users/theirusername/Sites/project/app/code/local/Theirname/Commercebug/Model/Observer.php(191): defined('Mage_Core_Block...')
From this, I can deduce that PHP thinks it needs to instantiate a class named O1ucm02owqn3iwwcx5osz2m2. However, I can't figure out why PHP might be doing this. The lines that trigger the error (#4 in the callstack, around line 191 in Observer.php) should be
if(defined("Mage_Core_Block_Template::XML_PATH_DEBUG_TEMPLATE_HINTS"))
{
$path = Mage_Core_Block_Template::XML_PATH_DEBUG_TEMPLATE_HINTS;
}
These lines don't seem to mention any PHP class named O1ucm02owqn3iwwcx5osz2m2 (I say "should be" because the customer's deployed the code themselves, I'm working with them to get a copy to look for potential problems).
Does anyone have any idea what might be going on? Is this a a known PHP bug/issue with some version and/or has anyone seen an issues like this with PHP autoloaders/defined/class constants?
(I'm working with my customer to determine the version of PHP they're running, as well as getting a copy of the files they've deployed to ensure they match what I assume are there.)
The defined() function serves as a compliment to the define() function for named constants. That is to say, constants declared with define can be nicely checked with defined.
However, that code is checking a class constant, which while possible, is less typical. I suspect that the checking is triggering autoloading (just as the use of class_exists can trigger autoloading.) However, the value handed off to the autoloader through use of defined is mangled (perhaps handing off the hash of the z-val for the string.)
I'm wondering if the following change would get things working:
// force PHP to load the class first, then let defined() check for the constant
if(class_exists("Mage_Core_Block_Template") && defined("Mage_Core_Block_Template::XML_PATH_DEBUG_TEMPLATE_HINTS"))
{
$path = Mage_Core_Block_Template::XML_PATH_DEBUG_TEMPLATE_HINTS;
}
As Alan noted in his comment, Zend Guard could be causing an issue, too.

Is it possible to mimic PHPUnit's output-to-console results using a Listener?

Situation
I'm implementing a Listener for PHPUnit that will record test results to a DB for later review. I like the default information phpunit outputs to console when a failure, error, skipped, or incomplete test is encountered.
Example:
1) sandbox_ExtensionSampleTest::testError
printf(): Too few arguments
E:\ecom_testing\tests_v2\TestSuites\sandbox\Base.php:28
E:\ecom_testing\tests_v2\TestSuites\sandbox\ExtensionSampleTest.php:37
C:\Program Files (x86)\EasyPHP-5.3.8.1\php\pear\pear\PHPUnit\Framework\TestCase.php:939
C:\Program Files (x86)\EasyPHP-5.3.8.1\php\pear\pear\PHPUnit\Framework\TestCase.php:801
C:\Program Files (x86)\EasyPHP-5.3.8.1\php\pear\pear\PHPUnit\Framework\TestResult.php:649
C:\Program Files (x86)\EasyPHP-5.3.8.1\php\pear\pear\PHPUnit\Framework\TestCase.php:748
C:\Program Files (x86)\EasyPHP-5.3.8.1\php\pear\pear\PHPUnit\Framework\TestSuite.php:772
C:\Program Files (x86)\EasyPHP-5.3.8.1\php\pear\pear\PHPUnit\Framework\TestSuite.php:745
C:\Program Files (x86)\EasyPHP-5.3.8.1\php\pear\pear\PHPUnit\TextUI\TestRunner.php:325
C:\Program Files (x86)\EasyPHP-5.3.8.1\php\pear\pear\PHPUnit\TextUI\Command.php:187
C:\Program Files (x86)\EasyPHP-5.3.8.1\php\pear\pear\PHPUnit\TextUI\Command.php:125
C:\Program Files (x86)\EasyPHP-5.3.8.1\php\pear\phpunit:44
FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
Note: I did find listing all the PHPUnit dependencies in the output is a bug, but the example above still shows two related test files.
Question
One of the parameters for an implemented listener method is Exception $e. I can get the message as well as the first line using $e, but I can't seem to get the rest of the lines.
After reading Exceptions in the PHP manual, I thought using $e->getPrevious() would work... attempted to do the following:
// Storing in a array to put into a DB later
// First line with the message
$trace[] = sprintf(
"%s\n\n%s:%s\n",
$e->getMessage(),
$e->getFile(),
$e->getLine()
);
// Go through the rest of the exceptions of files and lines
while ($e = $e->getPrevious()){
$trace[] = sprintf(
"%s:%s\n",
$e->getFile(),
$e->getLine()
);
}
That didn't work. It seems like $e->getPrevious() is empty and I did confirmed it when I dumped the object. I thought something like $e->getTraceAsString() would yield the same results, but it's not what I expected (I haven't used exceptions much)
The list of file and line number combinations is called the stack trace. You can grab it as an array using Exception::getTrace() and walk it yourself, or you can let PHPUnit filter out its classes for you by calling PHPUnit_Util_Filter::getFilteredStacktrace(). Pass the exception $e and true to receive a formatted string, or pass false to get the filtered array back instead.

Zend Framework - ErrorHandler does not seem to be working as expected

This is my first experience using the Zend Framework. I am attempting to follow the Quick Start tutorial. Everything was working as expected until I reached the section on the Error Controller and View. When I navigate to a page that does not exist, instead of receiving the error page I get the Fatal Error screen dump (in all it's glory):
Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception'
with message 'Invalid controller specified (error)' in
/home/.fantasia/bcnewman/foo.com/library/Zend/Controller/Dispatcher/Standard.php:249
Stack trace: #0
/home/.fantasia/bcnewman/foo.com/library/Zend/Controller/Front.php(946):
Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http),
Object(Zend_Controller_Response_Http)) #1
/home/.fantasia/bcnewman/foo.com/public/index.php(42):
Zend_Controller_Front->dispatch() #2 {main} thrown in
/home/.fantasia/bcnewman/foo.com/library/Zend/Controller/Dispatcher/Standard.php
on line 249
I do not believe this is caused by a syntax error on my part (a copied and pasted the example file's content from the tutorial) and I believe I have the application directory structure correct:
./application
./application/controllers
./application/controllers/IndexController.php
./application/controllers/ErrorHandler.php
./application/views
./application/views/scripts
./application/views/scripts/index
./application/views/scripts/index/index.phtml
./application/views/scripts/error
./application/views/scripts/error/error.phtml
./application/bootstrap.php
./public
./public/index.php
And finally, the IndexController and index.phtml view does work.
You have ErrorHandler.php. It should be ErrorController.php. Controllers all need to be named following the format of NameController.php. Since you don't have it named properly the dispatcher cannot find it.
Assuming that you have the ErrorController plugin loaded into your front controller, make sure that in your bootstrap that you do not have the following set:
$frontController->throwExceptions(true);
If this is set then Exceptions will always be thrown, regardless of whether or not you have an error controller set.

Categories