I'm using Math_Finance pear package locally. I made a modification to some file included in the package, this made my calculations work. Now I migrate my project to a web shared hosting and asked to install the same pear package. However I'm unable to perform the same modification I did locally because is a shared hosting.
My question is: is there a way to override or just include the file that was modified? I don't want to copy all files in the package to my public_html directory but I'm afraid that this is the only solution.
Thanks
You could send in a patch if it's a bug fix. If it's just added functionality. You could simply overwrite some functionality of the Math_Finance class by extending it. (thanks for the tip #hek2mgl ;)
Class Math_Finance {
public function someMethod() {
// original logic
}
}
Class My_Math_Finance extends Math_Finance {
public function someMethod() {
// change some of the needed logic
}
}
Depending on the method they used for representing the path to the included files this may work.
Assuming the original file is in
/usr/local/share/php/PEAR/Statistics/Cool.php
In your site mirror the PEAR and save your version as
/mywebroot/library/PEAR/Statistics/Cool.php
Then prepend the path to your library directory into the include paths
ini_set("include_path", "/mywebroot/library".PATH_SEPARATOR.ini_get("include_path"));
Now when including your version will be found prior to PEAR's.
I don't want to copy all files in the package to my public_html directory but I'm afraid that this is the only solution.
Yep! that's the solution. But what is so bad with that? We are talking about 2 additional php files ;) :
Math/Finance.php
Math/Finance_FunctionParameters.php
Place them in a folder inside your application, let's say lib. Then make sure, that you import both files from this location:
require_once 'lib/Math/Finance.php';
require_once 'lib/Math/Finance_FunctionParameters.php';
I had issues with pear as well and had to change to remove the pear requirement - here is the fork from original repo without pear
https://github.com/hashmode/Math_Finance
Related
I created some resources with php artisan, located in Http/Resources/Api/V1
Then I moved all at the root folder : Http/Resources, and deleted the Api/V1 folders
But now, my application uses an old version of my resources, I dont know why.
For example, in my controller I have :
public function show($id)
{
return new UserResource(User::findOrFail($id));
}
But the resource used is an old one, it doesn't even exists anymore
When you moved your resources from Http/Resources/Api/V1 to Http/Resources make sure you change the namespace in the resource files to reflect those changes.
After changing the namespaces make sure you use the correct includes at the top of your controllers because they will be different after you changed your namespaces.
If you did all the above steps make sure to run:
composer dump-autoload
This will fix any autoloading issues after you changed namespaces.
Here's the code, https://github.com/google/google-api-php-client/
Here's the file that's missing, https://github.com/google/google-api-php-client/blob/master/src/Google/autoload.php
I know it's possible to create this file with composer, but was just wondering if anyone has it available.
I'm also concerned that this alone might not make the software work, as I've tried to do it the manual way and the Class it can't reference is "GuzzleHttp\Collection" which is accessed in PHP with "use GuzzleHttp\Collection". I don't know how adding "autoload.php" will help referencing a file that's not part of the "google-api-php-client".
Does anyone actually have this software working in PHP, it says Beta?
I found it using Google Cache,
http://webcache.googleusercontent.com/search?q=cache:992oyuQ76a0J:https://github.com/google/google-api-php-client/blob/master/src/Google/autoload.php+&cd=1&hl=en&ct=clnk&gl=us
This file should be load from vendor directory
// include your composer dependencies
require_once 'vendor/autoload.php';
I'm trying to get some code set up to use an particular company's API.
I have experience with Perl and if I need a module installed, I type cpan ModuleName and most of the time it Just Works. How does that work with PHP code of similar complexity?
The company in question have a github repository with PHP Client system to access their API, which looks much the same as a perl Module.
I can git clone it, I can download it, but then what? Do I have to install it? There are no installation instructions. Or do I just start using it? There's a composer.json file in there. Do I need to run a composer command so it can figure out and install its dependencies like a CPAN module would? Will it install into system folders or just right there in whatever directory it happens to be in? I feel like there ought be some kind of official installation process because there's a /tests/ folder in the files I downloaded.
Their example code literally starts like this:
<?php
/* #var $CompanyName \CompanyName_Api */
$CompanyName = new \CompanyName_Api();
/* do interesting stuff */
and that's it. Of course nothing works if I just do that because it doesn't know where the CompanyName_Api files are. It works if I add this:
<?php
include('/full/path/to/downloaded/files/CompanyName/src/Api.php');
is that all I need to do?
In order to install all dependencies defined in composer.json you would run the following command inside the project directory:
composer install
This will find and download the dependencies into the vendor directory and it will also generate an optimized autoloader.
To autoload your own source files you'll need to add it to the autoload section in the composer.json file:
First your need to install an PHP environment like PHP, Apache and all stuff, then you need to clone that file from the git repository or just download it, then navigate to the dir and fire the command composer install. It will install all of the dependencies required for that package. After that, run the code from the browser -- the package api code may have the auto loader file which you need to include in your current package and autoloader will do all the stuff for you. Add your folder structure and file structure so that you get a better answer on this.
I am trying to include the YouTube Analytics Service of Google but I can not access it through the Vendor folder.
include(app_path.'path/to/analytics/Google_YoutubeAnalyticsService.php')
It is not working, because it defaults to the App folder.
How can I get out of the App folder and into the Vendor folder (where the YouTube Analytics file is at)?
The error is {
include(C:\xampp\htdocs\mysite\app/path/to/analytics/Google_YoutubeAnalyticsService.php):
failed to open stream: No such file or directory
From where do you want to include that file ?
Place a reference to your file in composer.json autoload object:
"autoload": {
"files":["your_file_path"]
}
Run composer dumpautoload, and you'll have your file :)
Actually you have in the helpers function the path so basically the function base_path give the direction to the root of your project so
echo base_path() . '/vendor';
Should be the route to your vendor folder.
You can se all the documentation in
Helper Functions Laravel
Be sure that you are seeing the documentation of the laravel version that you are using (I put the link for the 4.2 version).
This question was asked a long time ago and the answers reflect that. Most the time now all you need to do is import it using the "use" statement if you installed it with composer. Composer will already reference all the important directories.
It should be something like this, but it will vary depending on the project.
use FolderNameUsuallyGitHubUserName\ClassNameorGitHubProjectName\Class;
That could include a base class as well as some exception classes.
use FolderNameUsuallyGitHubUserName\ClassNameorGitHubProjectName\ClassException;
Usually most packages if compliant with modern composer and php standards work in this fashion.
Now i'm stuck with file_exists() function. My project is built from repositories, one is symlinked as a DocRoot, others are available to php interpreter via include_path. But the default file_exists() cannot look at the files are placed somewhere under include_path, so i need or somehow redefine this func with a wrapper or to write my own, include it in other modules and replace all matches of this func in the directory tree. It's possible, but is not good and is not clear for developers.
I've already seen pecl-apd (2008) and pecl-runkit (2007), but there are no more such pecls among the others in my gentoo repository or the overlays. So, how to redefine a function in a modern way?
== upd ===
Ok. Let's go deeper.
Assume we have /home/me/repos/ directory, where our git modules are placed and a virtual host /var/srv/domain.com, where it all is assembled
repos_
\_site_root_
\_.git
\_file1
\_module1_
\_.git
\_we_need_this_file_too
\_module2_
\_.git
domain.com_
\_htdocs –> ~/repos/site_root
\_tmp
so we need to somehow include folders with modules 1 and 2 into the project. Then adding path to ~/repos to php include_path via vhost config
php_admin_value include_path ".:/home/me/repos"
Now php can
include ('module1/we_need_this_file_too');
from my repos directory. but when it tries to check the file before including with file_exists(), it fails, because those directories are still closed for file_exists(). This is the problem.
Now i've found a workaround with absolute paths, anyway i'd have to create a personal config in my project. I also though about to chdir() into /home/me/repos/ when it needs to (and describing <Directory> section in vhost), but it was bad idea.
From the PHP manual
PHP does not support function overloading, nor is it possible to undefine or redefine previously-declared functions.
Well, you may, as you already mentioned, if you install the runkit extension and use runkit_function_redefine or if you install APD and use override_function.
I working on library for function redefining in php5.3
Source: https://github.com/Bubujka/bu.defun
Exampls: http://defun.bubujka.org/doc.html
Simple redefining:
<?php
def('name', function(){
echo "Waserd";
});
name();
echo "\n";
def('name', function(){
echo "Bubujka";
});
name();
---
Waserd
Bubujka