Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/vendor/captainhook/captainhook/src/Hook/Template/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/captainhook/captainhook/src/Hook/Template/PathInfo.php
<?php

/**
 * This file is part of CaptainHook.
 *
 * (c) Sebastian Feldmann <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CaptainHook\App\Hook\Template;

use SebastianFeldmann\Camino\Check;
use SebastianFeldmann\Camino\Path;
use SebastianFeldmann\Camino\Path\Directory;
use SebastianFeldmann\Camino\Path\File;

class PathInfo
{
    /**
     * Absolute path to repository
     * @var string
     */
    private string $repositoryAbsolute;

    /**
     * @var \SebastianFeldmann\Camino\Path\Directory
     */
    protected Directory $repository;

    /**
     * Absolute path to config file
     * @var string
     */
    private string $configAbsolute;

    /**
     * @var \SebastianFeldmann\Camino\Path\File
     */
    protected File $config;

    /**
     * Absolute path to captainhook executable
     * @var string
     */
    protected string $executableAbsolute;

    /**
     * @var \SebastianFeldmann\Camino\Path\File
     */
    private File $executable;

    /**
     * @param string $repositoryPath
     * @param string $configPath
     * @param string $execPath
     */
    public function __construct(string $repositoryPath, string $configPath, string $execPath)
    {
        $this->repositoryAbsolute = self::toAbsolutePath($repositoryPath);
        $this->repository         = new Directory($this->repositoryAbsolute);
        $this->configAbsolute     = self::toAbsolutePath($configPath);
        $this->config             = new File($this->configAbsolute);
        $this->executableAbsolute = self::toAbsolutePath($execPath);
        $this->executable         = new File($this->executableAbsolute);
    }

    public function getExecutablePath(): string
    {
        // check if the captainhook binary is in the repository bin directory
        // this should only be the case if we work in the captainhook repository
        if (file_exists($this->repositoryAbsolute . '/bin/captainhook')) {
            return './bin/captainhook';
        }
        return $this->getPathFromTo($this->repository, $this->executable);
    }

    public function getConfigPath(): string
    {
        return $this->getPathFromTo($this->repository, $this->config);
    }

    /**
     * Return the path to the target path from inside the .git/hooks directory f.e. __DIR__ ../../vendor
     *
     * @param  \SebastianFeldmann\Camino\Path\Directory $repo
     * @param  \SebastianFeldmann\Camino\Path           $target
     * @return string
     */
    private function getPathFromTo(Directory $repo, Path $target): string
    {
        if (!$target->isChildOf($repo)) {
            return $target->getPath();
        }
        return $target->getRelativePathFrom($repo);
    }


    /**
     * Make sure the given path is absolute
     *
     * @param  string $path
     * @return string
     */
    private static function toAbsolutePath(string $path): string
    {
        if (Check::isAbsolutePath($path)) {
            return $path;
        }
        return (string) realpath($path);
    }
}

Spamworldpro Mini