PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, January 31, 2022

[FIXED] Can Composer treat binary dependencies in PATH?

 January 31, 2022     composer-php, php     No comments   

Issue

I know that Composer can determine php, hhvm, ext-<name> and some lib-<name> dependencies. Would the same possible over commands and binaries on PATH? Actually, for instance, I wrote scripts to ensure that Tesseract OCR is present. It can be done with own Composer features?


Solution

You can achieve this using a Composer hook, like pre-install-cmd or pre-update-cmd, which executes a PHP method. Here is my test:

composer.json

{
  "require": { "pimple/pimple": "*" },
  "autoload": { "psr-0": { "Acme\\": "src/" } }
  "scripts": {
    "pre-install-cmd": "Acme\\Composer\\Hooks::checkBinary",
    "pre-update-cmd": "Acme\\Composer\\Hooks::checkBinary"
  }
}

src/Acme/Composer/Hooks.php

<?php
namespace Acme\Composer;

use Composer\Script\Event;

class Hooks
{
    public static function checkBinary(Event $event) {
        $io = $event->getIO();
        $path = explode(':', getenv('PATH'));
        // do something with $path elements or anything else
        if ($somethingWentWrong) {
            // Throwing an Exception will cause Composer to stop processing.
            throw new \Exception('Check your PATH');
        } else {
            $io->write('checkBinary() completed.');
        }
    }
}


Answered By - Gianluca Mancini
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing