Giter Club home page Giter Club logo

Comments (5)

Gemorroj avatar Gemorroj commented on June 18, 2024

Can you show similar functionality in other projects or describe why you need this method in real life?

from archive7z.

wapmorgan avatar wapmorgan commented on June 18, 2024

I don't have examples in other projects, but what if for some reason 7z executable disapper from os? Update problems/etc. Just simple isBinaryAvailable() could be called to check it.

from archive7z.

Gemorroj avatar Gemorroj commented on June 18, 2024

You can call null !== $obj7z->getBinary7z().
But in General, there should be no situation when binary path is not available. An exception must be thrown.

Archive7z/src/Archive7z.php

Lines 171 to 186 in 68eddc4

public function setBinary7z($path)
{
$binary7z = \realpath($path);
if (false === $binary7z) {
throw new Exception('Binary of 7-zip is not available');
}
if (!\is_executable($binary7z)) {
throw new Exception('Binary of 7-zip is not executable');
}
$this->binary7z = $binary7z;
return $this;
}

from archive7z.

wapmorgan avatar wapmorgan commented on June 18, 2024

Ok, but now this method seems to be deleted. Can you provide another static one to avoid object creation?

from archive7z.

Gemorroj avatar Gemorroj commented on June 18, 2024

I would suggest, for example, overriding the makeBinary7z method.

public function __construct($filename, $binary7z = null, $timeout = 60)
{
if (!\is_string($filename)) {
throw new Exception('Filename must be string');
}
$this->filename = $filename;
$this->binary7z = static::makeBinary7z($binary7z);
if (!\is_numeric($timeout) && $timeout !== null) {
throw new Exception('Timeout must be a numeric or null');
}
$this->timeout = $timeout;
}

protected static function makeBinary7z($binary7z = null)
{
if (null === $binary7z) {
$binary7z = static::getAutoBinary7z();
if (null === $binary7z) {
throw new Exception('Can\'t auto detect binary of 7-zip');
}
}
$binary7z = \realpath($binary7z);
if (false === $binary7z) {
throw new Exception('Binary of 7-zip is not available');
}
if (!\is_executable($binary7z)) {
throw new Exception('Binary of 7-zip is not executable');
}
return $binary7z;
}

The ideology of the library is based on the fact that its base class will be extended.

from archive7z.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.