0

Say I downloaded a PHP library (which I suppose usually comes as a bunch of .php files - is this correct?)

The only way I can think of using the library in my project is simply copy the files to my server and include or require them.

Is there a better or more standard way?

Also, how does yum relate to using PHP libraries?

baao
  • 71,625
  • 17
  • 143
  • 203
Aviv Cohn
  • 15,543
  • 25
  • 68
  • 131

2 Answers2

2

The most popular way of installing and using packages in php is using composer. You can get more information on composer at https://getcomposer.org. Composer will handle the auto loading for you so that you don't need to include every single file into the files.

You may also be interested in having a look at packagist.org where you can find a bunch of packages to use with composer/your projects.

baao
  • 71,625
  • 17
  • 143
  • 203
  • 1
    How is an arbitrary third party tool "standard"? – Siguza Aug 01 '15 at 13:24
  • @Siguza, like it or not, Composer IS a standard nowadays. – walther Aug 01 '15 at 13:25
  • 1
    @walther No, it is *popular*, not a standard. Something closer to a standard would be the PSR-* autoloaders. – Sverri M. Olsen Aug 01 '15 at 13:25
  • 1
    @SverriM.Olsen, playing with words, aren't we? If you need to handle dependencies, you really don't have a choice. Either do it manually (who does this today anyway??) or use a tool (composer). When a tool becomes as widely used and popular (almost every single framework uses composer in one way or another), it becomes the standard. As long as someone doesn't come up with something better, of course. – walther Aug 01 '15 at 13:29
  • That's exactly my point of view @walther. But as we're playing with words, I changed the answer to most popular instead of standard so that everybody is satisfied. – baao Aug 01 '15 at 13:30
  • @walther It is quite trivial to manually implement a PSR autoloader and simply clone the projects that you need. Composer is essentially just a glorified autoloader with automated cloning of projects (I love Composer, but that is pretty much what it is). – Sverri M. Olsen Aug 01 '15 at 13:33
  • The really nice thing about `composer` and the 'PSR' standards is that 'vendor' directory structures and namespaces became 'common'. So, it is easier to control the 'dependencies' manually. ;-/ I use an 'autoloader' utility. – Ryan Vincent Aug 01 '15 at 13:33
  • But implementing a PSR autoloader is something 1/10 people who are using auto loading/dependency management do, composer is used by the rest of the ten. So how can you call PSR more standard??? @SverriM.Olsen – baao Aug 01 '15 at 13:35
  • I see. How does yum relate to this? – Aviv Cohn Aug 01 '15 at 13:35
  • yum is a package manager for openSUSE and has nothing to do with php autoloading. @AvivCohn. It's releated to it like apples and bananas are to each other. – baao Aug 01 '15 at 13:37
  • @SverriM.Olsen, it's not only about including some files, but about managing dependencies. Part `with automated cloning of projects` is important here, because yes, you can implement an autoloader, but managing dependencies is a whole new topic. OP doesn't ask only about autoloading, but about using a 3rd party library. Composer makes sure you use the correct version and you don't have to do it manually. Your manual approach may work in small projects, but as it grows, it becomes really difficult to manage by hand. – walther Aug 01 '15 at 13:37
  • @michael So when I want to use a PHP library in my code, yum has nothing to do with it? If so, than how *does* it relate to php? – Aviv Cohn Aug 01 '15 at 13:39
  • 1
    I'm not sure what you are asking. Again yum is a package manager for openSUSE, not for php in any way. @AvivCohn – baao Aug 01 '15 at 13:40
2

According to my experience, all you have to do is import the right files and that's all. There is no "standard" way to use 3rd party libraries I think.

But the library you are using should have documentation. Make sure to read it because maybe you only have to import one file and that file is importing the others.

Asier Paz
  • 631
  • 1
  • 5
  • 16
  • I see. How does yum relate to this? – Aviv Cohn Aug 01 '15 at 13:35
  • @AvivCohn, as michael already said, yum has nothing to do with it. YUM is a package manager for openSUSE (linux-based operating system), it has nothing to do with managing libraries in PHP. – walther Aug 01 '15 at 14:24
  • As @walther said, yum doesn't relate to php libraries. As I know, yum has repos for php modules like mysqli, or pdo, etc... But not libraries. – Asier Paz Aug 01 '15 at 19:50