Skip to content
This repository has been archived by the owner on Sep 20, 2019. It is now read-only.

Commit

Permalink
Version 1.0 import
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeymakinen committed Aug 2, 2016
1 parent d404ea8 commit 2479b0e
Show file tree
Hide file tree
Showing 22 changed files with 947 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.idea
/vendor
composer.phar
phpunit.phar
/phpunit.xml
27 changes: 27 additions & 0 deletions Asset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace sergeymakinen\facades;

/** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */
/**
* Asset facade.
*
* @method static string|boolean getAssetPath(\yii\web\AssetBundle $bundle, string $asset) Returns the actual file path for the specified asset.
* @method static string getAssetUrl(\yii\web\AssetBundle $bundle, string $asset) Returns the actual URL for the specified asset.
* @method static \yii\web\AssetBundle getBundle(string $name, boolean $publish = true) Returns the named asset bundle.
* @method static \yii\web\AssetConverterInterface getConverter() Returns the asset converter.
* @method static string|false getPublishedPath(string $path) Returns the published path of a file path.
* @method static string|false getPublishedUrl(string $path) Returns the URL of a published file path.
* @method static array publish(string $path, array $options = []) Publishes a file or a directory.
* @method static setConverter(array|\yii\web\AssetConverterInterface $value) Sets the asset converter.
*/
class Asset extends Facade
{
/**
* @inheritdoc
*/
public static function getFacadeComponentId()
{
return 'assetManager';
}
}
51 changes: 51 additions & 0 deletions Auth.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace sergeymakinen\facades;

/** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */
/**
* Auth facade.
*
* @method static boolean add($object) Adds a role, permission or rule to the RBAC system.
* @method static boolean addChild($parent, $child) Adds an item as a child of another item.
* @method static \yii\rbac\Assignment assign($role, string|integer $userId) Assigns a role to a user.
* @method static boolean canAddChild(\yii\rbac\Item $parent, \yii\rbac\Item $child) Checks the possibility of adding a child to parent
* @method static boolean checkAccess(string|integer $userId, string $permissionName, array $params = []) Checks if the user has the specified permission.
* @method static \yii\rbac\Permission createPermission(string $name) Creates a new Permission object.
* @method static \yii\rbac\Role createRole(string $name) Creates a new Role object.
* @method static null|\yii\rbac\Assignment getAssignment(string $roleName, string|integer $userId) Returns the assignment information regarding a role and a user.
* @method static \yii\rbac\Assignment getAssignments(string|integer $userId) Returns all role assignment information for the specified user.
* @method static \yii\rbac\Item getChildren(string $name) Returns the child permissions and/or roles.
* @method static null|\yii\rbac\Permission getPermission(string $name) Returns the named permission.
* @method static \yii\rbac\Permission getPermissions() Returns all permissions in the system.
* @method static \yii\rbac\Permission getPermissionsByRole(string $roleName) Returns all permissions that the specified role represents.
* @method static \yii\rbac\Permission getPermissionsByUser(string|integer $userId) Returns all permissions that the user has.
* @method static null|\yii\rbac\Role getRole(string $name) Returns the named role.
* @method static \yii\rbac\Role getRoles() Returns all roles in the system.
* @method static \yii\rbac\Role getRolesByUser(string|integer $userId) Returns the roles that are assigned to the user via [[assign()]].
* @method static null|\yii\rbac\Rule getRule(string $name) Returns the rule of the specified name.
* @method static \yii\rbac\Rule getRules() Returns all rules available in the system.
* @method static array getUserIdsByRole($roleName) Returns all user IDs assigned to the role specified.
* @method static boolean hasChild($parent, $child) Returns a value indicating whether the child already exists for the parent.
* @method static boolean remove($object) Removes a role, permission or rule from the RBAC system.
* @method static removeAll() Removes all authorization data, including roles, permissions, rules, and assignments.
* @method static removeAllAssignments() Removes all role assignments.
* @method static removeAllPermissions() Removes all permissions.
* @method static removeAllRoles() Removes all roles.
* @method static removeAllRules() Removes all rules.
* @method static boolean removeChild($parent, $child) Removes a child from its parent.
* @method static boolean removeChildren($parent) Removed all children form their parent.
* @method static boolean revoke($role, string|integer $userId) Revokes a role from a user.
* @method static boolean revokeAll(mixed $userId) Revokes all roles from a user.
* @method static boolean update(string $name, $object) Updates the specified role, permission or rule in the system.
*/
class Auth extends Facade
{
/**
* @inheritdoc
*/
public static function getFacadeComponentId()
{
return 'auth';
}
}
36 changes: 36 additions & 0 deletions Cache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace sergeymakinen\facades;

/** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */
/**
* Cache facade.
*
* @method static boolean add(mixed $key, mixed $value, integer $duration = 0, \yii\caching\Dependency $dependency = null) Stores a value identified by a key into cache if the cache does not contain this key.
* @method static string buildKey(mixed $key) Builds a normalized cache key from a given key.
* @method static boolean delete(mixed $key) Deletes a value with the specified key from cache
* @method static boolean exists(mixed $key) Checks whether a specified key exists in the cache.
* @method static boolean flush() Deletes all values from cache.
* @method static mixed get(mixed $key) Retrieves a value from cache with a specified key.
* @method static boolean madd(array $items, integer $duration = 0, \yii\caching\Dependency $dependency = null) Stores multiple items in cache. Each item contains a value identified by a key.
* @method static array mget($keys) Retrieves multiple values from cache with the specified keys.
* @method static boolean mset(array $items, integer $duration = 0, \yii\caching\Dependency $dependency = null) Stores multiple items in cache. Each item contains a value identified by a key.
* @method static boolean multiAdd(array $items, integer $duration = 0, \yii\caching\Dependency $dependency = null) Stores multiple items in cache. Each item contains a value identified by a key.
* @method static array multiGet($keys) Retrieves multiple values from cache with the specified keys.
* @method static boolean multiSet(array $items, integer $duration = 0, \yii\caching\Dependency $dependency = null) Stores multiple items in cache. Each item contains a value identified by a key.
* @method static boolean offsetExists(string $key) Returns whether there is a cache entry with a specified key.
* @method static mixed offsetGet(string $key) Retrieves the value from cache with a specified key.
* @method static offsetSet(string $key, mixed $value) Stores the value identified by a key into cache.
* @method static offsetUnset(string $key) Deletes the value with the specified key from cache
* @method static boolean set(mixed $key, mixed $value, integer $duration = 0, \yii\caching\Dependency $dependency = null) Stores a value identified by a key into cache.
*/
class Cache extends Facade
{
/**
* @inheritdoc
*/
public static function getFacadeComponentId()
{
return 'cache';
}
}
43 changes: 43 additions & 0 deletions Db.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace sergeymakinen\facades;

/** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */
/**
* Db facade.
*
* @method static \yii\db\Transaction beginTransaction(string|null $isolationLevel = null) Starts a transaction.
* @method static mixed cache(callable $callable, integer $duration = null, \yii\caching\Dependency $dependency = null) Uses query cache for the queries performed with the callable.
* @method static close() Closes the currently active DB connection.
* @method static \yii\db\Command createCommand(string $sql = null, array $params = []) Creates a command for execution.
* @method static string getDriverName() Returns the name of the DB driver. Based on the the current [[dsn]], in case it was not set explicitly
* @method static boolean getIsActive() Returns a value indicating whether the DB connection is established.
* @method static string getLastInsertID(string $sequenceName = '') Returns the ID of the last inserted row or sequence value.
* @method static \PDO getMasterPdo() Returns the PDO instance for the currently active master connection.
* @method static \yii\db\QueryBuilder getQueryBuilder() Returns the query builder for the current DB connection.
* @method static array getQueryCacheInfo(integer $duration, \yii\caching\Dependency $dependency) Returns the current query cache information.
* @method static \yii\db\Schema getSchema() Returns the schema information for the database opened by this connection.
* @method static \yii\db\Connection getSlave(boolean $fallbackToMaster = true) Returns the currently active slave connection.
* @method static \PDO getSlavePdo(boolean $fallbackToMaster = true) Returns the PDO instance for the currently active slave connection.
* @method static \yii\db\TableSchema getTableSchema(string $name, boolean $refresh = false) Obtains the schema information for the named table.
* @method static \yii\db\Transaction getTransaction() Returns the currently active transaction.
* @method static mixed noCache(callable $callable) Disables query cache temporarily.
* @method static open() Establishes a DB connection.
* @method static string quoteColumnName(string $name) Quotes a column name for use in a query.
* @method static string quoteSql(string $sql) Processes a SQL statement by quoting table and column names that are enclosed within double brackets.
* @method static string quoteTableName(string $name) Quotes a table name for use in a query.
* @method static string quoteValue(string $value) Quotes a string value for use in a query.
* @method static setDriverName(string $driverName) Changes the current driver name.
* @method static mixed transaction(callable $callback, string|null $isolationLevel = null) Executes callback provided in a transaction.
* @method static mixed useMaster(callable $callback) Executes the provided callback by using the master connection.
*/
class Db extends Facade
{
/**
* @inheritdoc
*/
public static function getFacadeComponentId()
{
return 'db';
}
}
41 changes: 41 additions & 0 deletions ErrorHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace sergeymakinen\facades;

/** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */
/**
* ErrorHandler facade.
*
* @method static string addTypeLinks(string $code) Adds informational links to the given PHP type/class.
* @method static string argumentsToString(array $args) Converts arguments array to its string representation
* @method static clearOutput() Removes all output echoed before calling this method.
* @method static convertExceptionToError(\Exception $exception) Converts an exception into a PHP error.
* @method static string convertExceptionToString(\Exception $exception) Converts an exception into a simple string.
* @method static string createFrameworkVersionLink() Creates string containing HTML link which refers to the page with the current version
* @method static string createHttpStatusLink(integer $statusCode, string $statusDescription) Creates HTML containing link to the page with the information on given HTTP status code.
* @method static string createServerInformationLink() Creates string containing HTML link which refers to the home page of determined web-server software
* @method static string getExceptionName($exception) Returns human-readable exception name
* @method static boolean handleError(integer $code, string $message, string $file, integer $line) Handles PHP execution errors such as warnings and notices.
* @method static handleException(\Exception $exception) Handles uncaught PHP exceptions.
* @method static handleFatalError() Handles fatal PHP errors
* @method static boolean handleHhvmError(integer $code, string $message, string $file, integer $line, $context, mixed $backtrace) Handles HHVM execution errors such as warnings and notices.
* @method static string htmlEncode(string $text) Converts special characters to HTML entities.
* @method static boolean isCoreFile(string $file) Determines whether given name of the file belongs to the framework.
* @method static logException(\Exception $exception) Logs the given exception
* @method static register() Register this error handler
* @method static string renderCallStackItem(string|null $file, integer|null $line, string|null $class, string|null $method, array $args, integer $index) Renders a single call stack element.
* @method static string renderFile(string $_file_, array $_params_) Renders a view file as a PHP script.
* @method static string renderPreviousExceptions(\Exception $exception) Renders the previous exception stack for a given Exception.
* @method static string renderRequest() Renders the global variables of the request.
* @method static unregister() Unregisters this error handler by restoring the PHP error and exception handlers.
*/
class ErrorHandler extends Facade
{
/**
* @inheritdoc
*/
public static function getFacadeComponentId()
{
return 'errorHandler';
}
}
107 changes: 107 additions & 0 deletions Facade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

namespace sergeymakinen\facades;

use yii\base\Application;
use yii\base\InvalidConfigException;

/**
* Base facade class.
*/
abstract class Facade
{
/**
* The facaded application.
*
* @var Application
*/
private static $_app;

/**
* Facaded components.
*
* @var object[]
*/
private static $_components = [];

/**
* Returns a component ID being facaded.
*
* @return string
*/
public static function getFacadeComponentId()
{
throw new InvalidConfigException('Facade must impelemnt getFacadeComponentId method.');
}

/**
* Returns a component being facaded.
*
* @return mixed
*/
public static function getFacadeComponent()
{
$id = static::getFacadeComponentId();
if (!isset(self::$_components[$id])) {
self::$_components[$id] = static::getFacadeApplication()->get($id);
}
return self::$_components[$id];
}

/**
* Returns the facaded application.
*
* @return Application
*/
public static function getFacadeApplication()
{
if (!isset(self::$_app)) {
self::$_app = \Yii::$app;
}
return self::$_app;
}

/**
* Sets the facaded application.
*
* @param Application $value
*
* @return void
*/
public static function setFacadeApplication(Application $value)
{
self::$_app = $value;
}

/**
* Redirects static calls to component instance calls.
*
* @inheritDoc
*/
public static function __callStatic($name, $arguments)
{
return call_user_func_array([
static::getFacadeComponent(),
$name
], $arguments);
}

/**
* @inheritDoc
*/
private function __construct()
{}

/**
* @inheritDoc
*/
private function __wakeup()
{}

/**
* @inheritDoc
*/
private function __clone()
{}

}
44 changes: 44 additions & 0 deletions Formatter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace sergeymakinen\facades;

/** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */
/**
* Formatter facade.
*
* @method static string asBoolean(mixed $value) Formats the value as a boolean.
* @method static string asCurrency(mixed $value, string $currency = null, array $options = [], array $textOptions = []) Formats the value as a currency number.
* @method static string asDate(integer|string|\DateTime $value, string $format = null) Formats the value as a date.
* @method static string asDatetime(integer|string|\DateTime $value, string $format = null) Formats the value as a datetime.
* @method static string asDecimal(mixed $value, integer $decimals = null, array $options = [], array $textOptions = []) Formats the value as a decimal number.
* @method static string asDuration(\DateInterval|string|integer $value, string $implodeString = ', ', string $negativeSign = '-') Represents the value as duration in human readable format.
* @method static string asEmail(string $value, array $options = []) Formats the value as a mailto link.
* @method static string asHtml(string $value, array|null $config = null) Formats the value as HTML text.
* @method static string asImage(mixed $value, array $options = []) Formats the value as an image tag.
* @method static string asInteger(mixed $value, array $options = [], array $textOptions = []) Formats the value as an integer number by removing any decimal digits without rounding.
* @method static string asNtext(string $value) Formats the value as an HTML-encoded plain text with newlines converted into breaks.
* @method static string asOrdinal(mixed $value) Formats the value as a ordinal value of a number.
* @method static string asParagraphs(string $value) Formats the value as HTML-encoded text paragraphs.
* @method static string asPercent(mixed $value, integer $decimals = null, array $options = [], array $textOptions = []) Formats the value as a percent number with "%" sign.
* @method static string asRaw(mixed $value) Formats the value as is without any formatting.
* @method static string asRelativeTime(integer|string|\DateTime|\DateInterval $value, integer|string|\DateTime $referenceTime = null) Formats the value as the time interval between a date and now in human readable form.
* @method static string asScientific(mixed $value, integer $decimals = null, array $options = [], array $textOptions = []) Formats the value as a scientific number.
* @method static string asShortSize(string|integer|float $value, integer $decimals = null, array $options = [], array $textOptions = []) Formats the value in bytes as a size in human readable form for example `12 KB`.
* @method static string asSize(string|integer|float $value, integer $decimals = null, array $options = [], array $textOptions = []) Formats the value in bytes as a size in human readable form, for example `12 kilobytes`.
* @method static string asSpellout(mixed $value) Formats the value as a number spellout.
* @method static string asText(string $value) Formats the value as an HTML-encoded plain text.
* @method static string asTime(integer|string|\DateTime $value, string $format = null) Formats the value as a time.
* @method static string asTimestamp(integer|string|\DateTime $value) Formats a date, time or datetime in a float number as UNIX timestamp (seconds since 01-01-1970).
* @method static string asUrl(mixed $value, array $options = []) Formats the value as a hyperlink.
* @method static string format(mixed $value, string|array $format) Formats the value based on the given format type.
*/
class Formatter extends Facade
{
/**
* @inheritdoc
*/
public static function getFacadeComponentId()
{
return 'formatter';
}
}
Loading

0 comments on commit 2479b0e

Please sign in to comment.