PHP: Class not detected? - php

For some reason, when I try running my php script,
Fatal error: Class 'GeoTools\LatLngCollection' not found in ...
However, I have the classes in the same directory. Namely, I am using https://github.com/jkoreska/RouteboxerPHP
and I have all the scripts in the same directory.
Can someone tell me what I'm doing wrong?
Current script:
$points = [
[48.167, 17.104],
[48.399, 17.586],
[48.908, 18.049],
[49.22253, 18.734436],
[48.728115, 21.255798],
];
$collection = new GeoTools\LatLngCollection($points);
$boxer = new GeoTools\RouteBoxer();
//calculate boxes with 10km distance from the line between points
$boxes = $boxer->box(points, $distance = 10);
//boxes now contain an array of LatLngBounds
//literally have to return string that is printed to STDOUT
print $boxes
?>

When you write GeoTools\LatLngCollection then GeoTools is not the directory, but the namespace of the class LatLngCollection. However, the linked sourcecode defines no namespace at all, and by the way, no class named LatLngCollection. So what you most likely need to do is
require_once(__DIR__ . '/RouteBoxer.class.php');
$points = ...;
$collection = array();
array_push($collection, new LatLng(48.167, 17.104);
array_push($collection, new LatLng(48.399, 17.586);
/...
$boxer = new RouteBoxer();
//...
require includes a file. So I assume that you saved the classes in file "RouteBoxer.class.php" like it is in GitHub.

Related

Using Dynamic Variable Names to Call Static Variable in PHP

I am trying to implement a logging library which would fetch the current debug level from the environment the application runs in:
23 $level = $_SERVER['DEBUG_LEVEL'];
24 $handler = new StreamHandler('/var/log/php/php.log', Logger::${$level});
When I do this, the code fails with the error:
A valid variable name starts with a letter or underscore,followed by any number of letters, numbers, or underscores at line 24.
How would I use a specific Logger:: level in this way?
UPDATE:
I have tried having $level = "INFO" and changing ${$level} to $$level. None of these changes helped.
However, replacing the line 24 with $handler = new StreamHandler('/var/log/php/php.log', Logger::INFO); and the code compiles and runs as expected.
The variable itself is declared here
PHP Version => 5.6.99-hhvm
So the answer was to use a function for a constant lookup:
$handler = new StreamHandler('/var/log/php/php.log', constant("Monolog\Logger::" . $level));
<?php
class Logger {
const MY = 1;
}
$lookingfor = 'MY';
// approach 1
$value1 = (new ReflectionClass('Logger'))->getConstants()[$lookingfor];
// approach 2
$value2 = constant("Logger::" . $lookingfor);
echo "$value1|$value2";
?>
Result: "1|1"

How do I use the output from a php file in a TemplaVoila FCE?

I am trying to use the output from a php file in a TemplaVoila FCE.
According to the articles, etc, I have found on the subject, I seem to be doing it right. But it does not work.
I have reduced my implementation to a very simple test, and I hope that someone here can tell me what I am doing wrong.
The php code is in fileadmin/php/test.php
The file contains this code:
<?php
function getBeechgroveTest($content, $conf)
{
return 'B';
}
//echo getBeechgroveTest(0,0);
?>
In the main template (template module - not TemplaVoila) I have added this line:
includeLibs.beechgroveTest = fileadmin/php/test.php
I have tried to put it at the root level and inside a PAGE object. Both gave the same result.
If I uncomment the 'echo' line I get a 'B' at the top of my HTML page, so the php must be read at some point.
My FCE has one field of type 'None (TypoScript only)' and contains this code:
10 = TEXT
10 {
value = A
}
20 = USER
20 {
userFunc = getBeechgroveTest
}
30 = TEXT
30 {
value = C
}
I was expecting the FCE to output 'ABC', but I only get 'AC'.
What am I doing wrong?
I use TYPO3 version 4.5.30 and TemplVoila 1.8.0
It must by problem in cache, try use USER_INT instead USER. If you create this object as USER_INT, it will be rendered non-cached, outside the main page-rendering.
20 = USER_INT
20 {
userFunc = getBeechgroveTest
}

Ebay Trading API ReturnPolicyType

I'm trying to create a script to add items to my test ebay account. But I've hit a problem I'm not sure if I have the wrong file set? but it doesn't seem to match up to the documentation (or I'm reading it wrong).
The file set I have is PHP Toolkit with 527 Support. There is also PHP Toolkit with 515 Support. Both from https://www.x.com/developers/ebay/php-accelerator-toolkit-ebay-trading-api-edition
I've found this great script through another question on stack overflow
https://github.com/iloveitaly/ebay-php/blob/master/eBayCommon.php
And I've been looking at the online help files here: http://developer.ebay.com/devzone/xml/docs/WebHelp/wwhelp/wwhimpl/js/html/wwhelp.htm
Here is the error I'm getting: PHP Fatal error: Class 'ReturnPolicyType' not found
The way I understand it is that there should be a file for each "Type" there is one for CategoryType and AmountType but no file for ReturnPolicyType. And no reference to it any any of the files I have.. am I looking at this totally wrongly?
require_once '../EbatNs/EbatNs_ServiceProxy.php';
require_once '../EbatNs/EbatNs_Logger.php';
require_once '../EbatNs/VerifyAddItemRequestType.php';
require_once '../EbatNs/AddItemRequestType.php';
require_once '../EbatNs/ItemType.php';
require_once '../EbatNs/ItemConditionCodeType.php';
require_once '../EbatNs/GetMyeBaySellingRequestType.php';
require_once '../EbatNs/GetMyeBaySellingResponseType.php';
require_once '../EbatNs/GetItemRequestType.php';
$session = new EbatNs_Session('config/ebay.config.php');
$cs = new EbatNs_ServiceProxy($session);
$cs->_logger = new EbatNs_Logger();
$req = new VerifyAddItemRequestType();
$item = new ItemType();
$item->BuyItNowPrice;
$item->Description = 'test ��� � <b>Some bold text</b>';
$item->ListingDuration = 'Days_7';
$item->Title = '��� test-titel';
$item->Currency = 'EUR';
$item->ListingType = 'Chinese';
$item->Quantity = 1;
$item->StartPrice = new AmountType();
$item->StartPrice->setTypeValue('1.0');
$item->StartPrice->setTypeAttribute('currencyID', 'EUR');
$item->Country = 'GB';
$item->Location = '-- not given --';
$item->ConditionID = '1';
$item->PrimaryCategory = new CategoryType();
$item->PrimaryCategory->CategoryID = 11450;
$returnPolicy = new ReturnPolicyType();
$returnPolicy->setRefundOption($sellerConfig['refund']['option']);
$returnPolicy->setRefund($sellerConfig['refund']['option']);
$returnPolicy->setReturnsWithinOption($sellerConfig['refund']['within']);
$returnPolicy->setReturnsWithin($sellerConfig['refund']['within']);
$returnPolicy->setReturnsAcceptedOption($sellerConfig['refund']['returns']);
$returnPolicy->setReturnsAccepted($sellerConfig['refund']['returns']);
$returnPolicy->setDescription($sellerConfig['refund']['description']);
$returnPolicy->setShippingCostPaidByOption($sellerConfig['refund']['paidby']);
$returnPolicy->setShippingCostPaidBy($sellerConfig['refund']['paidby']);
$item->ReturnPolicy = $returnPolicy;
$item->Site = 'UK';
$item->ShipToLocations[]="Europe";
$item->PaymentMethods[] = 'PayPal';
$item->PayPalEmailAddress = 'paypal#intradesys.com';
$req->Item = $item;
$res = $cs->VerifyAddItem($req);
?>
You're going to have to get a newer toolkit. ReturnPolicy was added 3 1/2 years ago in 581.
Also, the lowest supported schema is now 629. I would recommend using as new of a toolkit as you can find. It looks like eBay hasn't updated their PHP page in a while, so you should go directly to the toolkit developer website to see what they have there.
Hope this helps!

How to properly load DoctrineExtensions in Bisna?

I am trying to load some doctrine extensions but I get all sort of errors. So far this is what I have
In my ini:
autoloaderNamespaces[] = "DoctrineExtensions"
resources.doctrine.classLoader.loaderClass = "Doctrine\Common\ClassLoader"
resources.doctrine.classLoader.loaderFile = "Doctrine/Common/ClassLoader.php"
resources.doctrine.classLoader.loaders.DoctrineExtensions_Paginate.namespace = "DoctrineExtensions\Paginate"
resources.doctrine.classLoader.loaders.DoctrineExtensions_Paginate.includePath = APPLICATION_PATH '/../library/Doctrine/DoctrineExtensions/Paginate/'
And in one of my controllers:
$count = Paginate::getTotalQueryResults($query); // Step 1
$paginateQuery = Paginate::getPaginateQuery($query, $offset, $limitPerPage); // Step 2 and 3
$result = $paginateQuery->getResult();
And this is the error:
Warning: include_once(DoctrineExtensions/Paginate.php): failed to open stream: No such file or directory
Try something simple
//include class loader first
//make sure this is correct
$doctrine_root=APPLICATION_PATH. '/../library/Doctrine';
require_once $doctrine_root.'/Common/ClassLoader.php';
$classLoader = new \Doctrine\Common\ClassLoader('Doctrine',$doctrine_root);
$classLoader->register();
user Doctrine\DoctrineExtensions\Paginate;
Then try reset of the code
$count = Paginate::getTotalQueryResults($query); // Step 1
// Step 2 and 3
$paginateQuery = Paginate::getPaginateQuery($query, $offset, $limitPerPage);
$result = $paginateQuery->getResult();
let me know how this works
cheers :)
Note : I haven't tested this code at my end
I suggest you try this plugin: beberlei / DoctrineExtensions
And here are the details on how to integrate it into your project: README
I do not think you can do so for as the developer has built the extensions! :S
In order to use the autoload for the class Paginate, the class should have been called DoctrineExtensions_Paginate_Paginate.
Good Luck!

PHP Error on Code it should not be running

First let me say sorry for the amount of code I'm posting below I'm going to try and keep it as short as possible but this is built on top of my MVC (lightweight-mvc)
Ok So my Problem is that for some reason php is throwing a fatal error on code that should not be being used in my current code,
So how this works I have my MVC witch used the first 2 parts of the url to know what its loading, the problem is I'm building a Moulder CMS into my MVC so it's boot strapping twice,
So here is my Problem,
http://{domain}/admin/control/addon/uploader/method/uploadCheck/
I'm using the above now let me explain a little into that the /admin/control are for the main MVC System it auto-loads the Admin controller then fires the controlAction method from the controller much the same as most MVC's,
The next part are URL paramters that build an array the same as GET or POST would
array('addon'=>'uploader', 'method'=>'uploadCheck')
So from that my control action will auto load as is the code below
public function controlAction(){
global $_URL;
if(cleanData::URL("addon")){
$addonName = "addon_".cleanData::URL("addon");
$methodName = (cleanData::URL("method"))? cleanData::URL("method")."Action" : "indexAction";
echo $methodName;
$addon = new $addonName();
$addon->$methodName();
return;
}else{
$this->loadView("CMS/controll");
}
}
cleanData::URL is an abstract method that just returns the value of the key provided though addSlashes()
So as you can see from the code below it will then use the autoloader to load the module(AKA addon)
Just so you can follow the auto loader works in a simpler version of the Zend Frame work autoloader _ so you have class name addon_admin that would be inside file admin.php that is in the folder addon so the autoloader will load addon/admin.php
So As above with my URL and controlAction it's loading addon/uploader.php and as such this is the contents
<?php
class addon_uploader extends Addons{
public function uploadCheckAction(){
echo 0;
}
public function uploaderAction(){
if (!empty($_FILES)) {
$tmpFile = $_FILES['Filedata']["tmp_name"];
$newLock = "../uploads/".end(explode('/', $tmpFile).$_FILES['Filedata']['name']);
move_uploaded_file($tmpFileName, $newLock);
$POSTback = array(
'name' => $_FILES['Filedata']['name'],
'type' => $_FILES['Filedata']['type'],
'tmp_name' => $newLock,
'error' => $_FILES['Filedata']['error'],
'size' => $_FILES['Filedata']['size']
);
echo json_enocde($POSTback);
}
}
}
?>
But as you can see from my URL its using the uploadCheckAction method witch for debugging i have set so it always says false (AKA 0),
But i seem to get this error:
Fatal error: Only variables can be passed by reference in C:\xampp\htdocs\FallenFate\addon\uploader.php on line 11
But line 11 is $newLock = "../uploads/".end(explode('/', $tmpFile).$_FILES['Filedata']['name']); witch should not be being used could any one provide any help into why this would occur and how i could fix it
end() PHP Manual needs an expression of a single variable (more precisely an array), but not a function return value or any other type of expression.
I think that's basically the cause of your error, more specifically with your code:
$newLock = "../uploads/".end(explode('/', $tmpFile).$_FILES['Filedata']['name']);
you're even driving this far beyond any level of treatment PHP can cope with:
you concatenate an array with a string (which results in a string).
you run end() on that string - not on a variable, not even an array.
I have no clue what you try to do with the code, but I can try:
$filename = $_FILES['Filedata']['name'];
$parts = explode('/', $tmpFile);
$last = end($parts);
$newLock = "../uploads/". $last . $filename;
Or probably even only this:
$filename = $_FILES['Filedata']['name'];
$newLock = "../uploads/". $filename;

Categories