Skip to content

Commit

Permalink
commit 9.0 to 9.1
Browse files Browse the repository at this point in the history
  • Loading branch information
indianmodassir committed Nov 8, 2024
1 parent 1e3cf45 commit e0398c8
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 11 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Release Notes
## [Unreleased](https://github.com/lazervel/path/compare/v8.2.2...v9.0.0)
## [Unreleased](https://github.com/lazervel/path/compare/v9.0.0...v9.1.0)

## [9.1.0](https://github.com/lazervel/path/compare/v9.0.0...v9.1.0) - 08 November 2024
- Added `Path::apply()` method in PHP `path` develope by [@shahzadamodassir](https://github.com/shahzadamodassir).
- Added `Path::real()` method in PHP `path` develope by [@shahzadamodassir](https://github.com/shahzadamodassir).
- Removed Temporarily `Path::callMap()` This method has been temporarily removed due to performance issues. It will be reintroduced in a future version (v9.3.0) after optimizations are completed.
- Fixed bugs `Path::canonicalize()` that caused [e.g., incorrect output].
- Fixed bugs `Path::isLocal()` that caused [e.g., incorrect output].
- Fixed bugs `Path::rootname()` that caused [e.g., incorrect output].

## [9.0.0](https://github.com/lazervel/path/compare/v8.2.2...v9.0.0) - 08 November 2024
- [BC BREAK] Since v8.x, Due to significant updates in the library, all previous configurations may no longer work as expected. Users will need to reconfigure their settings to align with the new structure and behavior introduced in this update.
Expand Down
67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,72 @@ require 'vendor/autoload.php';

## Path::basename($path[, $suffix])
```php
Path::basename('C:/xampp/htdocs/example.html');
// Returns: 'example.html'

Path::basename('C:/xampp/htdocs/example.html', '.html');
// Returns: 'example'
```

```php
Path::basename('/home/local/user/example.html');
// Returns: 'example.html'

Path::basename('/home/local/user/example.html', '.html');
// Returns: 'example'
```

## Path::callMap($method, $args)
```php

```

## Path::canonicalize($path)
```php
Path::canonicalize('C:/XamPP/HtDocS/DatA/comPoseR.jSon');
// Returns: 'C:\xampp\htdocs\data\composer.json'

Path::posix::canonicalize('/path/composer.json');
// Returns: 'G:\path\composer.json'
```

## Path::combine($paths, $names)
```php
Path::combine(['C:/xampp/htdocs'], ['example.html']);
// Returns: ['C:\xampp\htdocs\example.html']

Path::combine(['C:/xampp/htdocs', '/path'], ['example.html']);
// Returns: ['C:\xampp\htdocs\example.html', '\path\example.html']

Path::combine(['C:/xampp/htdocs'], ['example.html', 'foo.txt']);
// Returns: ['C:\xampp\htdocs\example.html', 'C:\xampp\htdocs\foo.txt']

Path::combine(['C:/xampp/htdocs', '/path'], ['example.html', 'foot.txt', '.env']);
// Returns: ['C:\xampp\htdocs\example.html', 'C:\xampp\htdocs\foot.txt', 'C:\xampp\htdocs\.env', '\path\example.html', '\path\foot.txt', '\path\.env']

/**
* For POSIX (Linux/macOs) operating system.
*/
Path::posix::combine(['C:\xampp\htdocs'], ['example.html']);
// Returns: ['C:/xampp/htdocs/example.html']

Path::posix::combine(['C:\xampp\htdocs', '\path'], ['example.html']);
// Returns: ['C:/xampp/htdocs/example.html', '/path/example.html']

Path::posix::combine(['C:\xampp\htdocs'], ['example.html', 'foo.txt']);
// Returns: ['C:/xampp/htdocs/example.html', 'C:/xampp/htdocs/foo.txt']

Path::posix::combine(['C:\xampp\htdocs', '\path'], ['example.html', 'foot.txt', '.env']);
// Returns: ['C:/xampp/htdocs/example.html', 'C:/xampp/htdocs/foot.txt', 'C:/xampp/htdocs/.env', '/path/example.html', '/path/foot.txt', '/path/.env']
```

## Path::checkLength($path)
```php
// Check maximum path length on your system use \PHP_MAXPATHLEN constant.
Path::checkLength('your-path');

// Returns: if given path of length are valid so return (void) otherwise throwing RTException Error.
// PHP Fatal error: Uncaught Path\Exception\RTException: Invalid path because path length exceeds [2048] characters.
```

## Path::delimiter
Expand All @@ -88,6 +138,23 @@ require 'vendor/autoload.php';

## Path::extname($path)
```php
Path::extname('C:/xampp/htdocs/example.html');
// Returns: '.html'

Path::extname('index.coffee.md');
// Returns: '.md'

Path::extname('index.');
// Returns: '.'

Path::extname('index');
// Returns: ''

Path::extname('.index');
// Returns: '.index'

Path::extname('C:/xampp/htdocs/example.md');
// Returns: '.md'
```

## Path::filename($path)
Expand Down
44 changes: 34 additions & 10 deletions src/Model/PathModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

use Path\Exception\RTException;
use Path\Utils\PathUtils;
use Path\Win32\Win32;
use Url\Url;

/**
Expand Down Expand Up @@ -123,8 +124,8 @@ public static function isAbsolute(string $path) : bool
*/
public static function isLocal(string $path) : bool
{
$absPath = \realpath($path);
return $absPath && self::isAbsolute($absPath);
$absPath = self::real($path);
return $absPath && Win32::isAbsolute($absPath);
}

/**
Expand All @@ -139,26 +140,38 @@ public static function optimize(string $path) : string

/**
*
* @param callable|string $method [required]
* @param string[] $args [required]
* @param callable $method [required]
* @param string[] $args [required]
*
* @return string[]
*/
public static function callMap($method, array $args) : array
// public static function callMap($method, array $args) : array
// {
// return \array_map(static function() use ($method, $args) {
// return self::apply($method, ...\func_get_args());
// }, [$args]);
// }

/**
*
* @param callable $method [required]
* @param string[] $args [required]
*/
public static function apply($method, array $args)
{
return \array_map(!\is_callable($method) ? [self::class, $method] : $method, $args);
$fn = !\is_callable($method) ? [self::class, $method] : $method;
return \call_user_func_array($fn, $args);
}


/**
*
* @param string $path [required]
* @return string|false
*/
public static function canonicalize(string $path)
{
$absPath = self::resolve($path);
return self::isLocal($absPath) ? $absPath : false;
$absPath = self::normalize($path);
return self::isLocal($absPath) ? self::real($absPath) : false;
}

/**
Expand All @@ -168,7 +181,8 @@ public static function canonicalize(string $path)
*/
public static function extname(string $path) : string
{
return self::info($path)->extension;
$src = \explode('.', $path);
return \count($src) > 1 ? ('.'.@end($src)) : '';
}

/**
Expand Down Expand Up @@ -201,6 +215,16 @@ public static function resolve(string ...$paths) : string
return self::normalize(self::doResolve($paths));
}

/**
*
* @param string $path [required]
* @return string|false
*/
public static function real(string $path)
{
return \realpath($path);
}

/**
*
* @param array $paths [required]
Expand Down

0 comments on commit e0398c8

Please sign in to comment.