Skip to content

Commit

Permalink
complete copyright comment & some class comment
Browse files Browse the repository at this point in the history
  • Loading branch information
heqiming committed Jul 26, 2024
1 parent d11a35e commit c3f45e5
Show file tree
Hide file tree
Showing 31 changed files with 587 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/Attributes/GenericAttribute.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
<?php

/*
* This file is part of the Leoboy\Desensitization package.
*
* (c) messikiller <messikiller@aliyun.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package Leoboy\Desensitization
* @author messikiller <messikiller@aliyun.com>
*/

namespace Leoboy\Desensitization\Attributes;

use Leoboy\Desensitization\Contracts\AttributeContract;
Expand All @@ -9,8 +21,17 @@
*/
class GenericAttribute implements AttributeContract
{
/**
* the virtual key of the attribute
*/
protected string $key;

/**
* the type of the attribute. it can be one of the following:
*
* 1. a shorthand string value for the specified rule
* 2. any string value for data type
*/
protected string $type;

/**
Expand Down
12 changes: 12 additions & 0 deletions src/Attributes/InvokableAttribute.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
<?php

/*
* This file is part of the Leoboy\Desensitization package.
*
* (c) messikiller <messikiller@aliyun.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package Leoboy\Desensitization
* @author messikiller <messikiller@aliyun.com>
*/

namespace Leoboy\Desensitization\Attributes;

use Leoboy\Desensitization\Contracts\AttributeContract;
Expand Down
42 changes: 42 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
<?php

/*
* This file is part of the Leoboy\Desensitization package.
*
* (c) messikiller <messikiller@aliyun.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package Leoboy\Desensitization
* @author messikiller <messikiller@aliyun.com>
*/

namespace Leoboy\Desensitization;

use ArrayAccess;
Expand Down Expand Up @@ -27,53 +39,83 @@ public function __construct(array $config)
$this->config = array_merge_recursive($this->config, $config);
}

/**
* set congiuration item.
*/
public function set(string $path, mixed $value): static
{
Helper::arraySet($this->config, $path, $value);

return $this;
}

/**
* get congiuration item.
*/
public function get(string $path, mixed $default = null): mixed
{
return Helper::arrayGet($this->config, $path, $default);
}

/**
* get all configuration items as array.
*/
public function toArray(): array
{
return $this->config;
}

/**
* get wildcard character configuration.
*/
public function getWildcardChar(): string
{
return $this->get('wildcard_char');
}

/**
* get key dot character configuration.
*/
public function getKeyDot(): string
{
return $this->get('key_dot');
}

/**
* whether skip transformation exception.
*/
public function shouldSkipTransformationException(): bool
{
return boolval($this->get('skip_transformation_exception'));
}

/**
* {@inheritDoc}
*/
public function offsetExists(mixed $offset): bool
{
return isset($this->config[$offset]);
}

/**
* {@inheritDoc}
*/
public function offsetGet(mixed $offset): mixed
{
return $this->get($offset);
}

/**
* {@inheritDoc}
*/
public function offsetSet(mixed $offset, mixed $value): void
{
$this->set($offset, $value);
}

/**
* {@inheritDoc}
*/
public function offsetUnset(mixed $offset): void
{
unset($this->config[$offset]);
Expand Down
17 changes: 17 additions & 0 deletions src/Contracts/AttributeContract.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
<?php

/*
* This file is part of the Leoboy\Desensitization package.
*
* (c) messikiller <messikiller@aliyun.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package Leoboy\Desensitization
* @author messikiller <messikiller@aliyun.com>
*/

namespace Leoboy\Desensitization\Contracts;

/**
* we use a 'attribute' to initialize the definition from user input.
* the initilized atrribute will be used to execute the rule transfomation
* or the specified security policy or guard.
*/
interface AttributeContract
{
/**
Expand Down
15 changes: 15 additions & 0 deletions src/Contracts/GuardContract.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
<?php

/*
* This file is part of the Leoboy\Desensitization package.
*
* (c) messikiller <messikiller@aliyun.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package Leoboy\Desensitization
* @author messikiller <messikiller@aliyun.com>
*/

namespace Leoboy\Desensitization\Contracts;

use Exception;

/**
* we get specifiec security policy for each data attribute.
*/
interface GuardContract
{
/**
Expand Down
15 changes: 15 additions & 0 deletions src/Contracts/RuleContract.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
<?php

/*
* This file is part of the Leoboy\Desensitization package.
*
* (c) messikiller <messikiller@aliyun.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package Leoboy\Desensitization
* @author messikiller <messikiller@aliyun.com>
*/

namespace Leoboy\Desensitization\Contracts;

/**
* we transform the data attributes according to the rules.
*/
interface RuleContract extends TransformerContract
{
//
Expand Down
15 changes: 15 additions & 0 deletions src/Contracts/SecurityPolicyContract.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
<?php

/*
* This file is part of the Leoboy\Desensitization package.
*
* (c) messikiller <messikiller@aliyun.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package Leoboy\Desensitization
* @author messikiller <messikiller@aliyun.com>
*/

namespace Leoboy\Desensitization\Contracts;

/**
* the security policy tells us which rule to use for a given attribute
*/
interface SecurityPolicyContract
{
/**
Expand Down
16 changes: 16 additions & 0 deletions src/Contracts/TransformerContract.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
<?php

/*
* This file is part of the Leoboy\Desensitization package.
*
* (c) messikiller <messikiller@aliyun.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package Leoboy\Desensitization
* @author messikiller <messikiller@aliyun.com>
*/

namespace Leoboy\Desensitization\Contracts;

use Leoboy\Desensitization\Exceptions\TransformException;

interface TransformerContract
{
/**
* invoke data transformation
*
* @param mixed $input
* @return mixed
*
* @throws TransformException
*/
public function transform($input);
}
15 changes: 15 additions & 0 deletions src/Desensitizer.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
<?php

/*
* This file is part of the Leoboy\Desensitization package.
*
* (c) messikiller <messikiller@aliyun.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package Leoboy\Desensitization
* @author messikiller <messikiller@aliyun.com>
*/

namespace Leoboy\Desensitization;

use Leoboy\Desensitization\Contracts\AttributeContract;
Expand All @@ -12,6 +24,9 @@
use Leoboy\Desensitization\Guards\NoneGuard;
use Throwable;

/**
* the main desensitization utility class.
*/
class Desensitizer
{
/**
Expand Down
15 changes: 15 additions & 0 deletions src/Exceptions/DesensitizationException.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
<?php

/*
* This file is part of the Leoboy\Desensitization package.
*
* (c) messikiller <messikiller@aliyun.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package Leoboy\Desensitization
* @author messikiller <messikiller@aliyun.com>
*/

namespace Leoboy\Desensitization\Exceptions;

use Exception;

/**
* the main exception class for the package.
*/
class DesensitizationException extends Exception
{
//
Expand Down
15 changes: 15 additions & 0 deletions src/Exceptions/InvalidRuleException.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
<?php

/*
* This file is part of the Leoboy\Desensitization package.
*
* (c) messikiller <messikiller@aliyun.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package Leoboy\Desensitization
* @author messikiller <messikiller@aliyun.com>
*/

namespace Leoboy\Desensitization\Exceptions;

/**
* throws when the rule is invalid.
*/
class InvalidRuleException extends DesensitizationException
{
//
Expand Down
15 changes: 15 additions & 0 deletions src/Exceptions/InvalidTypeException.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
<?php

/*
* This file is part of the Leoboy\Desensitization package.
*
* (c) messikiller <messikiller@aliyun.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package Leoboy\Desensitization
* @author messikiller <messikiller@aliyun.com>
*/

namespace Leoboy\Desensitization\Exceptions;

/**
* throws when the data type is invalid.
*/
class InvalidTypeException extends DesensitizationException
{
//
Expand Down
Loading

0 comments on commit c3f45e5

Please sign in to comment.