Installing PHP Github project on localhost using composer - php

I downloaded the Text-Statistics ZIP master from Github and extracted and renamed the folder to stats on /Library/WebServer/Documents/stats. Then I used cd /Library/WebServer/Documents/stats and composer update and all dependencies built on /Library/WebServer/Documents/stats as well. When I go to http://localhost/stats/ in my browser, it shows as follows:
This is my first time to install a project on my localhost directory which uses composer. Shall I create an index.php to see how the codes work? Below you can also see the composer.json file:
{
"name": "textstatistics",
"description": "PHP package to measure the readability of text according to various algorithms.",
"require": {
"php": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": "4.2.*"
},
"autoload": {
"psr-0" : {
"DaveChild\\TextStatistics" : "src"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"suggest": {
"ext-bcmath": "More accurate floating point calculations.",
"ext-mbstring": "Handle multi-byte text properly."
}
}

The package you 'installed' is a toolbox and meant to be used inside your project. It has no index.php since that would be useless, what would it have to show?
You should add it to an existing project by running composer require davechild/textstatistics from your project's root directory.
Composer exists so you do not have to download the package, and it's dependencies, yourself (like you did with the zip). It will also generate your autoload file so you do not have to bother about requiring or loading those classes. And it is especially useful when you want to update your dependencies (just run composer update)

This is completely unrelated to github or composer. It looks like this project is not a web application, because I don't see a bootstrap file (something like index.php). This means there is nothing which makes sense to call from a webserver context.
I took a short look at the projects github page. PHP Text Statistics is a library that will be used in other projects, but it's not a standalone tool, or application.

Related

Composer: How to override a requirement globally for composer.json?

TL;DR:
My Project requires library A, A requires B1.
B1 is broken but there is a fork B2.
I want to achieve that composer will install B2 instead of B1 even if A requires B1 and not B2.
How to do that?
More in detail:
In a symfony project we require the following library:
"require": {
"emanueleminotto/twig-cache-bundle": "1.0.2",
}
This library requires itself another library that is currently broken:
"require": {
"asm89/twig-cache-extension": "^1.3"
},
For the broken library exists already a pull request for over 4 month but the maintainer refuses to merge it.
My question is, if it would be possible to overwrite the dependencies also for sub-dependencies, that always the patched fork would be used instead of the original one?
For the asm89/twig-cache-extension exists the following fork with fixes: https://github.com/blackandred/twig-cache-extension
I tried to add this fork to my composer.json and registered the fork explicitly under "repositories":
"repositories": [
{
"type": "git",
"url": "https://github.com/blackandred/twig-cache-extension"
}
],
and added the dependency also in my composer-json with a changed version to "dev-master":
"require": {
"asm89/twig-cache-extension": "dev-master",
"emanueleminotto/twig-cache-bundle": "1.0.2",
}
But since the emanueleminotto/twig-cache-bundle still requires the original library, composer ignores the fork and installs the original.
Anything i can do here?
I believe the docs have a good example for this scenario.
Basically you need to define an alias in your composer.json as following:
"require": {
"asm89/twig-cache-extension": "dev-master as 1.3",
"emanueleminotto/twig-cache-bundle": "1.0.2",
}
Added by the questioner:
One step was still missing: "composer update asm89/twig-cache-extension"
Add the replace section into composer.json of your fork:
{
"replace": {
"asm89/twig-cache-extension": "self.version"
}
}

TYPO3 - Loading external libraries in my Extbase extension with composer works in development context but not in production

I'm using TYPO3 6.2.26, I added to my extension an external library (sinergi/browser-detector) using composer. We have two servers one for development and another for production. The problem appear in the production context, but in development work it excellent.
I have the next structure on both servers (git subversion):
myext/Resources/Private/composer.json
myext/Resources/Private/Libraries/autoload.php (generate by composer)
myext/Resources/Private/Libraries/sinergi/...
myext/Resources/Private/Libraries/composer/... (generate by composer)
myext/ext_autoload.php
I load the composer loader in the ext_autoload.php:
require __DIR__ . '/Resources/Private/Libraries/autoload.php';
My composer.json look like this:
{
"name": "vendor/vendor",
"description": "My description",
"type": "library",
"require-dev": {
"sinergi/browser-detector": "^6.1"
},
"config": {
"vendor-dir": "Libraries"
},
"authors": [
{
"name": "xxx",
"email": "xxx"
}
]
}
With this configurations it works without problems in the development environment. In production occurs a strange situation, when I delete the cache it works only one time, at the second time the web server returns a 500 Error:
PHP Fatal Error: class Sinergi\\BrowserDetector\\...not found...
I tried some solution which I founded in Internet like:
Adding to my composer.json:
"autoload":
"prs-4": {
"Sinergi\BrowserDetector\" : "Libraries/sinergi/browser-detector/src/"
}
Dumping the autoload
composer dump-autoload
Disabling opcache
Deleting composer.lock and new install
But, the problem is still there only in production. I remove too the content of the typo3temp directory, and then it works one time, but at the second 500 Error. Do anybody know what can I make?
I don't know how your files end up on production but you should use
"require": {
"sinergi/browser-detector": "^6.1"
},
instead of require-dev, otherwise, it is just for dev.

Composer - autoload classes in CodeIgniter outside vendor folder

I've been working on setting up a CodeIgniter project with composer. I'm wanting to include php classes stored in files outside the vendor folder - in a shared folder.
My directory structure:
/
--application/
--shared/
-application/
-class1.php
-class2.php
-class3.php
-base/
-classb1.php
--vendor/
--composer.json
--composer.lock
Looking at the composer documentation, I see there is an autoload property in the root package that I'm trying to use to load the classes in the shared directory. These classes aren't namespaced.
My composer.json file is as follows:
{
"description" : "The CodeIgniter Application with Composer",
"require": {
"php": ">=5.3.2",
"codeigniter/framework": "3.1.*"
},
"require-dev": {
"mikey179/vfsStream": "1.1.*"
},
"autoload":{
"psr-0":{
"":"shared/application/",
"":"shared/base/",
"":"shared/data/"
}
}
}
My search led me to this question, but the classes are still not being loaded. I've ran composer update on the terminal.
Well after looking further, there's a property called classmap (documentation) in the root package.
"autoload":{
"classmap":["shared/application/","shared/base/", "shared/data/"]
}
This loads all the required files in the folders.

Composer : how to add a dependency without network connection?

My profesionnal network block internet access. Some month ago I download the Silex framework from an archive (which contains composer.json file) and the composer.phar one's, then I transfer them on my desktop throught HDD.
My composer.json that I customized:
{
"name": "user/silex",
"require": {
"silex/silex": "1.2"
, "twig/twig": ">=1.8,<2.0-dev"
, "doctrine/dbal": "2.2.*"
, "symfony/security": "~2.3"
, "symfony/security": "~2.3"
},
"autoload": {
"psr-4": {
"Portal\\": "src/"
}
}
}
It works fine, my autoload customization too.
Today I want to add the monolog/monolog package, so I manually import it from an other computer.
I place it into my vendor folder, I add the following line to my composer.json file:
, "monolog/monolog": ">=1.0.0"
I run on the console:
php composer.phar dumpautoload
It outputs:
Generating autoload files
Then it stop without error, but the monolog namespace doesn't appear into my /vendor/composer/autoload_*.php files.
What did I miss?
Thanks to edmondscommerce's comment I found the solution:
I update my main composer.json file with an artifact respository (and I disable the packagist one):
{
"name": "user/silex",
"repositories": [
{
"type": "artifact",
"url": "artifact/"
}, {
"packagist": false
}
], "require": {
"silex/silex": "1.2"
, "twig/twig": ">=1.8,<2.0-dev"
, "monolog/monolog": "1.*"
, "doctrine/dbal": "2.2.*"
, "symfony/security": "~2.3"
},
"autoload": {
"psr-4": {
"Portal\\": "src/"
}
}
}
Then I put a folder called artifact according to the url put in the composer.json file.
I create into this folder a zip called monolog-monolog-1.8.zip with the library I want to add.
Then just launch a composer update command!
Be carefull, zip's root must contain a composer.json file, and this composer.json file must contain a version!
If you do not want to create a custom repository, you can also run composer install (or composer update) on a copy that is on a network-connected computer. Then you can copy over the newly added and extracted component into the vendor folder on the machine without internet access. Note that you also need to copy vendor/composer/installed.json to let composer know that the new package has been installed. Once you have copied all these files, you can run composer install on the machine without internet access and it will not try to install anything and dump autoload files.

Laravel 4 - Extend application controller from a package

Background
I know what I'm trying to do sounds a bit wrong but I do have my reasons.
Basically I have a central core app that's a default laravel app with a few tweaks and boilerplate code, I have then developed a series of packages that can be used to extend the app through composer. These packages are not meant to function without the core framework so a dependency upon it is fully expected.
What I want to do
What I would like to do is have a BaseController in my core app and have the various controllers in my package extend this BaseController to provide universal functionality throughout the various module packages.
I was expecting to be able to place the base controller in app/controllers/BaseController.php
and then extend it from my package using:
class PackageController extends \BaseController{}
Unfortunately when I do this it still looks within the package (currently workbenched) for the controller and I get the error:
include(/var/www/l4core.dev/workbench/myvendor/mypackage/src/controllers/BaseController.php):
failed to open stream: No such file or directory
Can anyone tell me what I'm doing wrong here. I am looking for a solution which allows me to easily move my packages between vendor dir and workbench for development. Any help greatly appreciated
Update
The previously mentioned error message appears to have been due to an include in my packages /vendor/composer/classloader.php - I have now deleted the vendor directory and done a fresh composer install. This has not solved the problem but it has at least shifted it as I now get the following error message:
Class 'BaseController' not found
My Packages composer.json
{
"name": "modules/sesame",
"description": "",
"authors": [
{
"name": "any",
"email": ""
}
],
"require": {
"php": ">=5.4.0",
"illuminate/support": "4.0.x",
"zizaco/confide": "dev-master",
"zizaco/entrust": "dev-master",
"conarwelsh/mustache-l4": "dev-master"
},
"autoload": {
"classmap": [
"src/controllers",
"src/models",
"src/migrations",
"src/seeds"
],
"psr-0": {
"Modules\\Sesame": "src/"
}
},
"minimum-stability": "dev"
}
Be sure to execute:
php artisan dump-autoload
And verify that your class BaseController is in /vendor/composer/autoload_classmap.php.
OR like the OP stated, removing the vendor directory and running composer install again could sometimes solve the problem.

Categories