I want to integrate phpspec2 with CodeIgniter 2. I've succesfully installed phpspec using composer as described on phpspec website. Now I'd like to integrate it into my CodeIgniter 2 installation. I've found an article by AniDear on this subject and did everything as described. However when I run bin/phpspec I get an error:
PHP Warning: require(core/Common.php): failed to open stream: No such file or directory
in C:\xampp\htdocs\eljotengine\spec\ci_bootstrap.php on line 37
Warning: require(core/Common.php): failed to open stream: No such file or directory in C:\xampp\htdocs\eljotengine\spec\ci_bootstrap.php on line 37
and so on. My file structure looks like this:
eljotengine
|-application
|-sytem
|- ... other CI
|-spec
| |- ci_bootstrap.php
I am using xampp on Windows 7. My ci_bootstrap.php file looks like the one in the above mentioned article by AniDear.
I've tried to change the paths in the ci_bootstrap.php file (it seems to be the problem) however it did not change much.
Any ideas how to make this work?
Greets :)
I am having problem with PHPSpec2 too.
Since I have only tried it with PHPSpec (not PHPSpec2), I would suggest you to install PHPSpec instead. Just change the file composer.json, on the line "phpspec/phpspec2": "*" to "phpspec/phpspec": "*" , then runs composer update again.
Run this phpspec, by using command vendor\bin\phpspec.php.bat spec on your project path, whereas "spec" is the folder containing spec files.
And since you're running phpspec from your project directory, I suggest changing content inside ci_bootstrap.php as follow
define('BASEPATH',realpath('system/').'/'); //set absolute path to CI system/
define('APPPATH', 'application/'); //set relative path to CI application
set_include_path(
get_include_path().PATH_SEPARATOR.
realpath(APPPATH).PATH_SEPARATOR.
realpath(BASEPATH).PATH_SEPARATOR.
'spec'); //adding 'spec' in path, for easily do require 'ci_bootstrap.php' from inside spec files
require BASEPATH.'core/Common.php';
require APPPATH.'config/constants.php';
require BASEPATH.'core/Controller.php';
Related
PHP doesn't seem to find a class defined in a library which I'm trying to auto-load from Composer.
I'm messing around with PHP served by Apache 2.4, which I've had success with in the past, but introducing Composer into the mix has proven troublesome for me. I'm attempting to use an OAuth2 library for Slack, installed successfully using composer require bramdevries/oauth2-slack in the virtualhost's document root, such that the file structure looks like:
+-- composer.json
+-- composer.lock
+-- index.php
+-- vendor/
| +-- autoload.php
| +-- composer/
| +-- bramdevries/
| | +-- <library files>
| ... dependencies
This one library is the only one that I'm using thus far, and my index.php is the only source file in the entire document root that isn't a library inside composer/. This project is, for all intents and purposes, about 3 lines of PHP code, shown below.
From my understanding of the Composer documentation: since I'm using a library that provides its own composer.json, Composer should take care of generating all of the auto-loading stuff if I do composer dump-autoload (which, I gather, is unnecessary since Composer generates that stuff on update, install, etc).
However, whenever I go to load my index.php in a browser, Apache2 responds with HTTP 500.
Given the file structure above, here is the entirety of my index.php:
<?php
require "vendor/autoload.php";
$slack = new League\OAuth2\Client\Provider\Slack([ /* stuff */ ]);
?>
And here is the error found in /var/log/apache2/error.log:
PHP Fatal error: Uncaught Error: Class 'League\\OAuth2\\Client\\Provider\\Slack' not found in <document_root>/index.php:3
Stack trace:
#0 {main}
thrown in <document_root>/index.php on line 3
So, I'm clearly doing something wrong, but what?
I've used Apache2 and PHP for a little while now (including a project for a pre-capstone CS project class this semester), but my working knowledge of PHP is limited to the functional aspects; I haven't messed much with its OOP aspects. Also, I'm familiar with dependency/package managers similar to Composer (specifically, NPM for Node.js), but not with Composer itself. TIA!
Edit: forgot to add – I've searched around enough that every link on the first couple pages of any given Google search with related terms shows up purple, and nothing I've tried thus far has worked for me, so I'm sure I'm just missing a step or something.
Their example appears to be incorrect, or maybe changed and they forgot to update the README.
If you look at their source for the Slack provider, it is in the namespace Bramdevries\Oauth\Client\Provider.
You just need to change the constructor to:
$slack = new Bramdevries\Oauth\Client\Provider\Slack([ /* stuff */ ]);
Hopefully after that you don't run into anything else!
It makes use of the League code which their composer.json does bring in, but to use this particular provider you have to reference their code in the proper namespace.
The other hint at this is looking at their autoload definition in composer.json:
"autoload": {
"psr-4": {
"Bramdevries\\Oauth\\Client\\": "src"
}
},
I've been trying to install a web application which is built using the Laravel framework. The application is hosted as a GIT repository.
Here is a detailed description of my problem to clarify how I'm facing it.
For the first time I cloned the repository in the following path:
/var/www/app.example.com/script/
Then created a symbolic link to it's public directory like this to follow my server's nginx routing convention:
ln -s /var/www/app.example.com/script/public /var/www/app.example.com/public_html
But I decided to move everything out of the script directory to one upper level and this is where my problem started.
I moved the Laravel installation to /var/www/app.example.com/ and made nginx to directly load its public directory as the root path.
Now the problem is every time I try to load the application it's trying to read the files from their previous location:
Warning:
require(/var/www/app.example.com/script/public/../bootstrap/autoload.php):
failed to open stream: No such file or directory in
/var/www/app.example.com/public/index.php on line 21
Fatal error: require(): Failed opening required
'/var/www/app.example.com/script/public/../bootstrap/autoload.php'
(include_path='.:/usr/share/php:/usr/share/pear') in
/var/www/app.example.com/public/index.php on line 21
Notes to keep in mind:
I've used composer to install all the dependencies
curl -sS https://getcomposer.org/installer | php
php composer.phar install
I'm using nginx as my web server
I've tried removing everything (including ~/.composer) and start all over again to no avail.
I have even tried to move the whole project into a new root directory
It seems the problem is with __DIR__ magic constant since it contains the wrong path
Weirdly enough if I echo __DIR__ it prints the correct path but in the next line in which it's used it has the incorrect old path
I hope I have been clear enough in my description to avoid any confusion and possible down-votes.
So i could be completly wrong here, but is there a configuration file where it might have saved it? Or is there still something left in the script directory that can mabey cause this? As when the __DIR__ outputs the right value, then it should in the other code too.
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.
The Yii2 preview was recently released and is available on github. I want to take it for a test drive, but the "documentation" so far gets outdated almost instantly since it is still under heavy development. I have tried to follow this guide on creating a simple CRUD app with Yii2, but it fails at the step:
php yiic.php app/create /var/www/yii2
With the error:
Could not open input file: yiic.php
Indicating that there is no file called yiic.php. The only folder within the framework folder is yii (framework/yii), and within that folder there is no file yiic.php, only Yii.php which when called in the command line gives the command list:
The following commands are available:
- asset
- cache
- help
- message
- migrate
Anyone managed to successfully setup a Yii2 app? Care to share how you got it done?
Seems like yiic has been removed for now, there are alternatives though, so read on.
It's all in the early stages, so the following method could break in the coming days/weeks/months. Therefore use with caution.
There are 2 ways to do this now:
Use composer. (I recommend this option.)
Directly copy the contents of yii2/apps/ directory to your apps directory, depending on the type of app you want to try.
There are currently 2 options for type of app - advanced, and basic. Both are in their respective directories within the yii2/apps/ directory, i.e yii2/apps/advanced and yii2/apps/basic.
For basic go through the basic readme.md, and for advanced go through the advanced readme.md.
The directions for using composer are given in the respective readme.md files. Including them here for completeness:
Basic app:
Install composer, if you don't have it.
Use composer to install the app alongwith dependencies(Yii):
php path/to/composer.phar create-project --stability=dev yiisoft/yii2-app-basic my_yii2_trial
Access app from http://localhost/my_yii2_trial/www
Advanced app:
Install composer, if you don't have it.
Use composer to install the app alongwith dependencies(Yii):
php path/to/composer.phar create-project --stability=dev yiisoft/yii2-app-advanced my_yii2_trial
According to readme, after step 2 app should be accessible, but composer was failing(see issue 439). With schmunk's tip, ran the install or install.bat command that gets copied by composer: ./install . Selected development environment (by entering choice 0 in the instructions that show up when running install command). Update: The command has been renamed to init, composer doesn't fail anymore, with fix from Qiang (check the issue 439 for more details).
Access app at: http://localhost/my_yii2_trial/frontend/www or http://localhost/my_yii2_trial/backstage/www
Here's how to copy the directory and get it working:
Basic app:
create your web-accessible directory for the app : my_yii2_trial
copy all files and folders from yii2/apps/basic/ directory to my_yii2_trial/ directory.
modify the my_yii2_trial/www/index.php file to point to the correct path for Yii.php.
For me it was within yii2/framework/yii/
comment the line that tries to include ../vendor/autoload.php file, I couldn't find that file anywhere, so its probably for some future use. it is the autoloader provided by composer.
Access from browser : http://localhost/my_yii2_trial/www
Advanced app:
create your web-accessible directory for the app : my_yii2_trial
copy all files and folders from yii2/apps/advanced/ directory to my_yii2_trial/ directory.
modify the my_yii2_trial/frontend/www/index.php file to point to the correct path for Yii.php. Similarly modify backstage/www/index.php.
comment the line that tries to include ../vendor/autoload.php file in both the index.php of backstage and frontend.
Access app at: http://localhost/my_yii2_trial/frontend/www or http://localhost/my_yii2_trial/backstage/www
Some important links to read more about this: issue 77, issue 108, issue 131, and wiki comment.
I am not sure how composer's autoloader is being used, so can't comment on that. Also in future versions, backstage might be renamed to backend.
I have installed a new zf project, and get the next error:
Warning: require_once(Zend/Application.php) [function.require-once]: failed to open stream: No such file or directory in C:\wamp\www\zend\public\index.php on line 18
I have set the include path and in addition i have uploaded zf to the library folder.
But, I can't find any trace to a file named Application.php ...
Somewhere along the line you have mixed ZF1 and ZF2 instructions or code. There is no Zend/Application.php in ZF2 (this is a ZF1 thing), and ZF2 apps do not generally have a 'library' folder. So either you are using ZF2 but have followed some app setup instructions for ZF1, or you've used the ZF1 command line tool to create a ZF1 project and have then put ZF2 into the library folder.
Here is the ZF2 skeleton app: https://github.com/zendframework/ZendSkeletonApplication - this should give you an idea what your app should look like.
As the error obviously says Zend/Application.php is not there. Check you include path and your folder.