Skip to content

Commit

Permalink
Merge 19946cd into 925d60f
Browse files Browse the repository at this point in the history
  • Loading branch information
azjezz committed Dec 29, 2021
2 parents 925d60f + 19946cd commit 1b55134
Show file tree
Hide file tree
Showing 54 changed files with 594 additions and 453 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* introduced a new `Psl\Math\asin` function.
* introduced a new `Psl\Math\atan` function.
* introduced a new `Psl\Math\atan2` function.
* **BC** - The type of the $numbers argument of `Psl\Math\mean` has changed to `list<int|float>` instead of `iterable<int|float>`.
* **BC** - The type of the $numbers argument of `Psl\Math\mean` has changed to `list<int|float>` instead of `iterable<int|float>`.
* **BC** - The type of the $numbers argument of `Psl\Math\median` has changed to `list<int|float>` instead of `iterable<int|float>`.
* introduced a new `Psl\Promise` component.
* **BC** - `Psl\Result\ResultInterface` now implements `Psl\Promise\PromiseInterface`
Expand All @@ -47,3 +47,11 @@
> To preserve the same behavior as the old function, use `Psl\File\write($file, $content, Filesystem\is_file($file) ? File\WriteMode::TRUNCATE : File\WriteMode::OPEN_OR_CREATE)`.
* **BC** - `Psl\Filesystem\read_file($file, $offset, $length)` function has been removed, use `Psl\File\read($file, $offset, $length)` instead.
* **BC** - `Psl\Filesystem\append_file($file, $contents)` function has been removed, use `Psl\File\write($file, $contents, File\WriteMode::APPEND)` instead.
* **BC** - `Psl\Filesystem` functions no longer throw `Psl\Exception\InvariantViolationException`.

New exceptions:
- `Psl\Filesystem\Exception\NotReadableException` thrown when attempting to read from a non-readable node
- `Psl\Filesystem\Exception\NotFileException` thrown when attempting a file operation on a non-file node.
- `Psl\Filesystem\Exception\NotDirectoryException` thrown when attempting a directory operation on a non-directory node.
- `Psl\Filesystem\Exception\NotSymbolicLinkException` thrown when attempting a symbolic link operation on a non-symbolic link node.
- `Psl\Filesystem\Exception\NotFoundException` thrown when attempting an operation on a non-existing node.
58 changes: 29 additions & 29 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/component/env.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#### `Functions`

- [args](./../../src/Psl/Env/args.php#L12)
- [current_dir](./../../src/Psl/Env/current_dir.php#L16)
- [current_dir](./../../src/Psl/Env/current_dir.php#L18)
- [current_exec](./../../src/Psl/Env/current_exec.php#L12)
- [get_var](./../../src/Psl/Env/get_var.php#L19)
- [get_vars](./../../src/Psl/Env/get_vars.php#L14)
Expand Down
2 changes: 1 addition & 1 deletion docs/component/file.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
- [open_read_write](./../../src/Psl/File/open_read_write.php#L18)
- [open_write_only](./../../src/Psl/File/open_write_only.php#L18)
- [read](./../../src/Psl/File/read.php#L23)
- [temporary](./../../src/Psl/File/temporary.php#L22)
- [temporary](./../../src/Psl/File/temporary.php#L26)
- [write](./../../src/Psl/File/write.php#L24)

#### `Interfaces`
Expand Down
40 changes: 20 additions & 20 deletions docs/component/filesystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,37 @@
#### `Functions`

- [canonicalize](./../../src/Psl/Filesystem/canonicalize.php#L15)
- [change_group](./../../src/Psl/Filesystem/change_group.php#L20)
- [change_owner](./../../src/Psl/Filesystem/change_owner.php#L22)
- [change_permissions](./../../src/Psl/Filesystem/change_permissions.php#L21)
- [copy](./../../src/Psl/Filesystem/copy.php#L24)
- [create_directory](./../../src/Psl/Filesystem/create_directory.php#L17)
- [change_group](./../../src/Psl/Filesystem/change_group.php#L21)
- [change_owner](./../../src/Psl/Filesystem/change_owner.php#L21)
- [change_permissions](./../../src/Psl/Filesystem/change_permissions.php#L20)
- [copy](./../../src/Psl/Filesystem/copy.php#L22)
- [create_directory](./../../src/Psl/Filesystem/create_directory.php#L19)
- [create_file](./../../src/Psl/Filesystem/create_file.php#L24)
- [create_hard_link](./../../src/Psl/Filesystem/create_hard_link.php#L22)
- [create_hard_link](./../../src/Psl/Filesystem/create_hard_link.php#L23)
- [create_symbolic_link](./../../src/Psl/Filesystem/create_symbolic_link.php#L22)
- [create_temporary_file](./../../src/Psl/Filesystem/create_temporary_file.php#L26)
- [delete_directory](./../../src/Psl/Filesystem/delete_directory.php#L24)
- [delete_file](./../../src/Psl/Filesystem/delete_file.php#L22)
- [exists](./../../src/Psl/Filesystem/exists.php#L19)
- [file_size](./../../src/Psl/Filesystem/file_size.php#L19)
- [delete_directory](./../../src/Psl/Filesystem/delete_directory.php#L23)
- [delete_file](./../../src/Psl/Filesystem/delete_file.php#L21)
- [exists](./../../src/Psl/Filesystem/exists.php#L21)
- [file_size](./../../src/Psl/Filesystem/file_size.php#L22)
- [get_access_time](./../../src/Psl/Filesystem/get_access_time.php#L20)
- [get_basename](./../../src/Psl/Filesystem/get_basename.php#L23)
- [get_change_time](./../../src/Psl/Filesystem/get_change_time.php#L21)
- [get_directory](./../../src/Psl/Filesystem/get_directory.php#L24)
- [get_extension](./../../src/Psl/Filesystem/get_extension.php#L16)
- [get_filename](./../../src/Psl/Filesystem/get_filename.php#L18)
- [get_extension](./../../src/Psl/Filesystem/get_extension.php#L18)
- [get_filename](./../../src/Psl/Filesystem/get_filename.php#L20)
- [get_group](./../../src/Psl/Filesystem/get_group.php#L20)
- [get_inode](./../../src/Psl/Filesystem/get_inode.php#L20)
- [get_modification_time](./../../src/Psl/Filesystem/get_modification_time.php#L21)
- [get_modification_time](./../../src/Psl/Filesystem/get_modification_time.php#L20)
- [get_owner](./../../src/Psl/Filesystem/get_owner.php#L20)
- [get_permissions](./../../src/Psl/Filesystem/get_permissions.php#L20)
- [is_directory](./../../src/Psl/Filesystem/is_directory.php#L22)
- [is_executable](./../../src/Psl/Filesystem/is_executable.php#L20)
- [is_file](./../../src/Psl/Filesystem/is_file.php#L22)
- [is_readable](./../../src/Psl/Filesystem/is_readable.php#L20)
- [is_symbolic_link](./../../src/Psl/Filesystem/is_symbolic_link.php#L21)
- [is_writable](./../../src/Psl/Filesystem/is_writable.php#L20)
- [is_directory](./../../src/Psl/Filesystem/is_directory.php#L21)
- [is_executable](./../../src/Psl/Filesystem/is_executable.php#L19)
- [is_file](./../../src/Psl/Filesystem/is_file.php#L21)
- [is_readable](./../../src/Psl/Filesystem/is_readable.php#L19)
- [is_symbolic_link](./../../src/Psl/Filesystem/is_symbolic_link.php#L19)
- [is_writable](./../../src/Psl/Filesystem/is_writable.php#L19)
- [read_directory](./../../src/Psl/Filesystem/read_directory.php#L21)
- [read_symbolic_link](./../../src/Psl/Filesystem/read_symbolic_link.php#L22)
- [read_symbolic_link](./../../src/Psl/Filesystem/read_symbolic_link.php#L23)


4 changes: 4 additions & 0 deletions src/Psl/Env/current_dir.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
* Returns the current working directory.
*
* @throws Psl\Exception\InvariantViolationException If unable to retrieve the current working directory.
*
* @return non-empty-string
*/
function current_dir(): string
{
$directory = getcwd();
Psl\invariant(false !== $directory, 'Unable to retrieve current working directory.');

/** @var non-empty-string */
return $directory;
}
1 change: 1 addition & 0 deletions src/Psl/Env/current_exec.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/
function current_exec(): string
{
/** @var non-empty-string $executable */
$executable = (string) Filesystem\canonicalize((string) $_SERVER['SCRIPT_NAME']);
// @codeCoverageIgnoreStart
if (Filesystem\is_symbolic_link($executable)) {
Expand Down
6 changes: 5 additions & 1 deletion src/Psl/File/temporary.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
* the system default temporary directory.
* @param non-empty-string|null $prefix The prefix of the generated temporary filename.
*
* @throws Filesystem\Exception\RuntimeException If unable to create the file.
* @throws Filesystem\Exception\RuntimeException If unable to create the file.
* @throws Filesystem\Exception\NotFoundException If $directory is not found.
* @throws Filesystem\Exception\NotDirectoryException If $directory is not a directory.
* @throws Filesystem\Exception\InvalidArgumentException If $prefix contains a directory separator.
* @throws Psl\Exception\InvariantViolationException If $directory doesn't exist or is not writable.
* @throws Psl\Exception\InvariantViolationException If $prefix contains a directory separator.
* @throws Filesystem\Exception\RuntimeException If unable to create the file.
*/
function temporary(?string $directory = null, ?string $prefix = null): ReadWriteHandleInterface
{
Expand Down
11 changes: 11 additions & 0 deletions src/Psl/Filesystem/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace Psl\Filesystem\Exception;

use Psl\Exception;

class InvalidArgumentException extends Exception\InvalidArgumentException implements ExceptionInterface
{
}
15 changes: 15 additions & 0 deletions src/Psl/Filesystem/Exception/NotDirectoryException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Psl\Filesystem\Exception;

use Psl\Str;

final class NotDirectoryException extends InvalidArgumentException
{
public static function for(string $path): NotDirectoryException
{
return new self(Str\format('Path "%s" does not point to a directory.', $path));
}
}
15 changes: 15 additions & 0 deletions src/Psl/Filesystem/Exception/NotFileException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Psl\Filesystem\Exception;

use Psl\Str;

final class NotFileException extends InvalidArgumentException
{
public static function for(string $path): NotFileException
{
return new self(Str\format('Path "%s" does not point to a file.', $path));
}
}
35 changes: 35 additions & 0 deletions src/Psl/Filesystem/Exception/NotFoundException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Psl\Filesystem\Exception;

use Psl\Str;

final class NotFoundException extends InvalidArgumentException
{
public static function forNode(string $node): NotFoundException
{
return new self(Str\format('Node "%s" is not found.', $node));
}

public static function forFile(string $file): NotFoundException
{
return new self(Str\format('File "%s" is not found.', $file));
}

public static function forDirectory(string $directory): NotFoundException
{
return new self(Str\format('Directory "%s" is not found.', $directory));
}

public static function forSymbolicLink(string $symbolic_link): NotFoundException
{
return new self(Str\format('Symbolic link "%s" is not found.', $symbolic_link));
}

public static function forLink(string $link): NotFoundException
{
return new self(Str\format('Link "%s" is not found.', $link));
}
}

0 comments on commit 1b55134

Please sign in to comment.