repo
stringlengths
7
63
file_url
stringlengths
81
284
file_path
stringlengths
5
200
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:02:33
2026-01-05 05:24:06
truncated
bool
2 classes
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/AuthModule.php
AuthModule.php
<?php /** * AuthModule class file. * @author Christoffer Niska <ChristofferNiska@gmail.com> * @copyright Copyright &copy; Christoffer Niska 2012- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @package auth * @version 1.7.0 */ /** * Web module for managing Yii's built-in authorization manager (CAuthManager). */ class AuthModule extends CWebModule { /** * @var boolean whether to enable the RBAC strict mode. * When enabled items cannot be assigned children of the same type. */ public $strictMode = true; /** * @var string name of the user model class. * Change this if your user model name is different than the default value. */ public $userClass = 'User'; /** * @var string name of the user id column. * Change this if the id column in your user table is different than the default value. */ public $userIdColumn = 'id'; /** * @var string name of the user name column. * Change this if the name column in your user table is different than the default value. */ public $userNameColumn = 'name'; /** * @var string the application layout. * Change this if you wish to use a different layout with the module. */ public $defaultLayout = 'application.views.layouts.main'; /** * @var array map of flash message keys to use for the module. */ public $flashKeys = array(); /** * @var string string the id of the default controller for this module. */ public $defaultController = 'assignment'; /** * @var boolean whether to force copying of assets. * Useful during development and when upgrading the module. */ public $forceCopyAssets = false; /** * @var string path to view files for this module. * Specify this to use your own views instead of those shipped with the module. */ public $viewDir; private $_assetsUrl; /** * Initializes the module. */ public function init() { $this->setImport( array( 'auth.components.*', 'auth.controllers.*', 'auth.models.*', 'auth.widgets.*', ) ); $this->registerCss(); $this->flashKeys = array_merge( $this->flashKeys, array( 'error' => 'error', 'info' => 'info', 'success' => 'success', 'warning' => 'warning', ) ); if (isset($this->viewDir)) { if (strpos($this->viewDir, '.')) { $this->viewDir = Yii::getPathOfAlias($this->viewDir); } $this->setLayoutPath($this->viewDir . DIRECTORY_SEPARATOR . 'layouts'); $this->setViewPath($this->viewDir); } } /** * Registers the module CSS. */ public function registerCss() { Yii::app()->clientScript->registerCssFile($this->getAssetsUrl() . '/css/auth.css'); } /** * The pre-filter for controller actions. * @param CController $controller the controller. * @param CAction $action the action. * @return boolean whether the action should be executed. * @throws CException|CHttpException if user is denied access. */ public function beforeControllerAction($controller, $action) { if (parent::beforeControllerAction($controller, $action)) { $user = Yii::app()->getUser(); if ($user instanceof AuthWebUser) { if ($user->isAdmin) { return true; } elseif ($user->isGuest) { $user->loginRequired(); } } else { throw new CException('WebUser component is not an instance of AuthWebUser.'); } } throw new CHttpException(401, Yii::t('AuthModule.main', 'Access denied.')); } /** * Returns the URL to the published assets folder. * @return string the URL. */ protected function getAssetsUrl() { if (isset($this->_assetsUrl)) { return $this->_assetsUrl; } else { $assetsPath = Yii::getPathOfAlias('auth.assets'); $assetsUrl = Yii::app()->assetManager->publish($assetsPath, false, -1, $this->forceCopyAssets); return $this->_assetsUrl = $assetsUrl; } } /** * Returns the module version number. * @return string the version. */ public function getVersion() { return '1.7.0'; } }
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/controllers/AssignmentController.php
controllers/AssignmentController.php
<?php /** * AssignmentController class file. * @author Christoffer Niska <ChristofferNiska@gmail.com> * @copyright Copyright &copy; Christoffer Niska 2012- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @package auth.controllers */ /** * Controller for assignment related actions. */ class AssignmentController extends AuthController { /** * Displays the a list of all the assignments. */ public function actionIndex() { $dataProvider = new CActiveDataProvider($this->module->userClass); $this->render( 'index', array( 'dataProvider' => $dataProvider ) ); } /** * Displays the assignments for the user with the given id. * @param string $id the user id. */ public function actionView($id) { $formModel = new AddAuthItemForm(); /* @var $am CAuthManager|AuthBehavior */ $am = Yii::app()->getAuthManager(); if (isset($_POST['AddAuthItemForm'])) { $formModel->attributes = $_POST['AddAuthItemForm']; if ($formModel->validate()) { if (!$am->isAssigned($formModel->items, $id)) { $am->assign($formModel->items, $id); if ($am instanceof CPhpAuthManager) { $am->save(); } if ($am instanceof ICachedAuthManager) { $am->flushAccess($formModel->items, $id); } } } } $model = CActiveRecord::model($this->module->userClass)->findByPk($id); $assignments = $am->getAuthAssignments($id); $authItems = $am->getItemsPermissions(array_keys($assignments)); $authItemDp = new AuthItemDataProvider(); $authItemDp->setAuthItems($authItems); $assignmentOptions = $this->getAssignmentOptions($id); if (!empty($assignmentOptions)) { $assignmentOptions = array_merge( array('' => Yii::t('AuthModule.main', 'Select item') . ' ...'), $assignmentOptions ); } $this->render( 'view', array( 'model' => $model, 'authItemDp' => $authItemDp, 'formModel' => $formModel, 'assignmentOptions' => $assignmentOptions, ) ); } /** * Revokes an assignment from the given user. * @throws CHttpException if the request is invalid. */ public function actionRevoke() { if (isset($_GET['itemName'], $_GET['userId'])) { $itemName = $_GET['itemName']; $userId = $_GET['userId']; /* @var $am CAuthManager|AuthBehavior */ $am = Yii::app()->getAuthManager(); if ($am->isAssigned($itemName, $userId)) { $am->revoke($itemName, $userId); if ($am instanceof CPhpAuthManager) { $am->save(); } if ($am instanceof ICachedAuthManager) { $am->flushAccess($itemName, $userId); } } if (!isset($_POST['ajax'])) { $this->redirect(array('view', 'id' => $userId)); } } else { throw new CHttpException(400, Yii::t('AuthModule.main', 'Invalid request.')); } } /** * Returns a list of possible assignments for the user with the given id. * @param string $userId the user id. * @return array the assignment options. */ protected function getAssignmentOptions($userId) { $options = array(); /* @var $am CAuthManager|AuthBehavior */ $am = Yii::app()->authManager; $assignments = $am->getAuthAssignments($userId); $assignedItems = array_keys($assignments); /* @var $authItems CAuthItem[] */ $authItems = $am->getAuthItems(); foreach ($authItems as $itemName => $item) { if (!in_array($itemName, $assignedItems)) { $options[$this->capitalize($this->getItemTypeText($item->type, true))][$itemName] = $item->description; } } return $options; } }
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/controllers/TaskController.php
controllers/TaskController.php
<?php /** * TaskController class file. * @author Christoffer Niska <ChristofferNiska@gmail.com> * @copyright Copyright &copy; Christoffer Niska 2012- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @package auth.controllers */ /** * Controller for task related actions. */ class TaskController extends AuthItemController { /** * @var integer the item type (0=operation, 1=task, 2=role). */ public $type = CAuthItem::TYPE_TASK; }
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/controllers/AuthItemController.php
controllers/AuthItemController.php
<?php /** * AuthItemController class file. * @author Christoffer Niska <ChristofferNiska@gmail.com> * @copyright Copyright &copy; Christoffer Niska 2012- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @package auth.controllers */ /** * Base controller for authorization item related actions. */ abstract class AuthItemController extends AuthController { /** * @var integer the item type (0=operation, 1=task, 2=role). */ public $type; /** * Displays a list of items of the given type. */ public function actionIndex() { $dataProvider = new AuthItemDataProvider(); $dataProvider->type = $this->type; $this->render( 'index', array( 'dataProvider' => $dataProvider, ) ); } /** * Displays a form for creating a new item of the given type. */ public function actionCreate() { $model = new AuthItemForm('create'); if (isset($_POST['AuthItemForm'])) { $model->attributes = $_POST['AuthItemForm']; if ($model->validate()) { /* @var $am CAuthManager|AuthBehavior */ $am = Yii::app()->getAuthManager(); if (($item = $am->getAuthItem($model->name)) === null) { $item = $am->createAuthItem($model->name, $model->type, $model->description); if ($am instanceof CPhpAuthManager) { $am->save(); } } $this->redirect(array('view', 'name' => $item->name)); } } $model->type = $this->type; $this->render( 'create', array( 'model' => $model, ) ); } /** * Displays a form for updating the item with the given name. * @param string $name name of the item. * @throws CHttpException if the authorization item is not found. */ public function actionUpdate($name) { /* @var $am CAuthManager|AuthBehavior */ $am = Yii::app()->getAuthManager(); $item = $am->getAuthItem($name); if ($item === null) { throw new CHttpException(404, Yii::t('AuthModule.main', 'Page not found.')); } $model = new AuthItemForm('update'); if (isset($_POST['AuthItemForm'])) { $model->attributes = $_POST['AuthItemForm']; if ($model->validate()) { $item->description = $model->description; $am->saveAuthItem($item); if ($am instanceof CPhpAuthManager) { $am->save(); } $this->redirect(array('index')); } } $model->name = $name; $model->description = $item->description; $model->type = $item->type; $this->render( 'update', array( 'item' => $item, 'model' => $model, ) ); } /** * Displays the item with the given name. * @param string $name name of the item. */ public function actionView($name) { $formModel = new AddAuthItemForm(); /* @var $am CAuthManager|AuthBehavior */ $am = Yii::app()->getAuthManager(); if (isset($_POST['AddAuthItemForm'])) { $formModel->attributes = $_POST['AddAuthItemForm']; if ($formModel->validate()) { if (!$am->hasItemChild($name, $formModel->items)) { $am->addItemChild($name, $formModel->items); if ($am instanceof CPhpAuthManager) { $am->save(); } } } } $item = $am->getAuthItem($name); $dpConfig = array( 'pagination' => false, 'sort' => array('defaultOrder' => 'depth asc'), ); $ancestors = $am->getAncestors($name); $ancestorDp = new PermissionDataProvider(array_values($ancestors), $dpConfig); $descendants = $am->getDescendants($name); $descendantDp = new PermissionDataProvider(array_values($descendants), $dpConfig); $childOptions = $this->getItemChildOptions($item->name); if (!empty($childOptions)) { $childOptions = array_merge(array('' => Yii::t('AuthModule.main', 'Select item') . ' ...'), $childOptions); } $this->render( 'view', array( 'item' => $item, 'ancestorDp' => $ancestorDp, 'descendantDp' => $descendantDp, 'formModel' => $formModel, 'childOptions' => $childOptions, ) ); } /** * Deletes the item with the given name. * @throws CHttpException if the item does not exist or if the request is invalid. */ public function actionDelete() { if (isset($_GET['name'])) { $name = $_GET['name']; /* @var $am CAuthManager|AuthBehavior */ $am = Yii::app()->getAuthManager(); $item = $am->getAuthItem($name); if ($item instanceof CAuthItem) { $am->removeAuthItem($name); if ($am instanceof CPhpAuthManager) { $am->save(); } if (!isset($_POST['ajax'])) { $this->redirect(array('index')); } } else { throw new CHttpException(404, Yii::t('AuthModule.main', 'Item does not exist.')); } } else { throw new CHttpException(400, Yii::t('AuthModule.main', 'Invalid request.')); } } /** * Removes the parent from the item with the given name. * @param string $itemName name of the item. * @param string $parentName name of the parent. */ public function actionRemoveParent($itemName, $parentName) { /* @var $am CAuthManager|AuthBehavior */ $am = Yii::app()->getAuthManager(); if ($am->hasItemChild($parentName, $itemName)) { $am->removeItemChild($parentName, $itemName); if ($am instanceof CPhpAuthManager) { $am->save(); } } $this->redirect(array('view', 'name' => $itemName)); } /** * Removes the child from the item with the given name. * @param string $itemName name of the item. * @param string $childName name of the child. */ public function actionRemoveChild($itemName, $childName) { /* @var $am CAuthManager|AuthBehavior */ $am = Yii::app()->getAuthManager(); if ($am->hasItemChild($itemName, $childName)) { $am->removeItemChild($itemName, $childName); if ($am instanceof CPhpAuthManager) { $am->save(); } } $this->redirect(array('view', 'name' => $itemName)); } /** * Returns a list of possible children for the item with the given name. * @param string $itemName name of the item. * @return array the child options. */ protected function getItemChildOptions($itemName) { $options = array(); /* @var $am CAuthManager|AuthBehavior */ $am = Yii::app()->getAuthManager(); $item = $am->getAuthItem($itemName); if ($item instanceof CAuthItem) { $exclude = $am->getAncestors($itemName); $exclude[$itemName] = $item; $exclude = array_merge($exclude, $item->getChildren()); $authItems = $am->getAuthItems(); $validChildTypes = $this->getValidChildTypes(); foreach ($authItems as $childName => $childItem) { if (in_array($childItem->type, $validChildTypes) && !isset($exclude[$childName])) { $options[$this->capitalize( $this->getItemTypeText($childItem->type, true) )][$childName] = $childItem->description; } } } return $options; } /** * Returns a list of the valid child types for the given type. * @return array the valid types. */ protected function getValidChildTypes() { $validTypes = array(); switch ($this->type) { case CAuthItem::TYPE_OPERATION: break; case CAuthItem::TYPE_TASK: $validTypes[] = CAuthItem::TYPE_OPERATION; break; case CAuthItem::TYPE_ROLE: $validTypes[] = CAuthItem::TYPE_OPERATION; $validTypes[] = CAuthItem::TYPE_TASK; break; } if (!$this->module->strictMode) { $validTypes[] = $this->type; } return $validTypes; } /** * Returns the authorization item type as a string. * @param boolean $plural whether to return the name in plural. * @return string the text. */ public function getTypeText($plural = false) { return parent::getItemTypeText($this->type, $plural); } /** * Returns the directory containing view files for this controller. * @return string the directory containing the view files for this controller. */ public function getViewPath() { return $this->module->getViewPath() . DIRECTORY_SEPARATOR . 'authItem'; } }
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/controllers/OperationController.php
controllers/OperationController.php
<?php /** * OperationController class file. * @author Christoffer Niska <ChristofferNiska@gmail.com> * @copyright Copyright &copy; Christoffer Niska 2012- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @package auth.controllers */ /** * Controller for operation related actions. */ class OperationController extends AuthItemController { /** * @var integer the item type (0=operation, 1=task, 2=role). */ public $type = CAuthItem::TYPE_OPERATION; }
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/controllers/RoleController.php
controllers/RoleController.php
<?php /** * RoleController class file. * @author Christoffer Niska <ChristofferNiska@gmail.com> * @copyright Copyright &copy; Christoffer Niska 2012- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @package auth.controllers */ /** * Controller for role related actions. */ class RoleController extends AuthItemController { /** * @var integer the item type (0=operation, 1=task, 2=role). */ public $type = CAuthItem::TYPE_ROLE; }
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/components/PermissionDataProvider.php
components/PermissionDataProvider.php
<?php /** * PermissionDataProvider class file. * @author Christoffer Niska <ChristofferNiska@gmail.com> * @copyright Copyright &copy; Christoffer Niska 2012- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @package auth.components */ /** * Data provider for listing permissions. */ class PermissionDataProvider extends CArrayDataProvider { /** * @var string */ public $keyField = 'name'; }
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/components/AuthWebUser.php
components/AuthWebUser.php
<?php /** * AuthWebUser class file. * @author Christoffer Niska <ChristofferNiska@gmail.com> * @copyright Copyright &copy; Christoffer Niska 2013- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @package auth.components */ /** * Web user that allows for passing access checks when enlisted as an administrator. * * @property boolean $isAdmin whether the user is an administrator. */ class AuthWebUser extends CWebUser { /** * @var string[] a list of names for the users that should be treated as administrators. */ public $admins = array('admin'); /** * Initializes the component. */ public function init() { parent::init(); $this->setIsAdmin(in_array($this->name, $this->admins)); } /** * Returns whether the logged in user is an administrator. * @return boolean the result. */ public function getIsAdmin() { return $this->getState('__isAdmin', false); } /** * Sets the logged in user as an administrator. * @param boolean $value whether the user is an administrator. */ public function setIsAdmin($value) { $this->setState('__isAdmin', $value); } /** * Performs access check for this user. * @param string $operation the name of the operation that need access check. * @param array $params name-value pairs that would be passed to business rules associated * with the tasks and roles assigned to the user. * @param boolean $allowCaching whether to allow caching the result of access check. * @return boolean whether the operations can be performed by this user. */ public function checkAccess($operation, $params = array(), $allowCaching = true) { if ($this->getIsAdmin()) { return true; } return parent::checkAccess($operation, $params, $allowCaching); } }
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/components/AuthBehavior.php
components/AuthBehavior.php
<?php /** * AuthBehavior class file. * @author Christoffer Niska <ChristofferNiska@gmail.com> * @copyright Copyright &copy; Christoffer Niska 2012- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @package auth.components */ /** * Auth module behavior for the authorization manager. * * @property CAuthManager|IAuthManager $owner The authorization manager. */ class AuthBehavior extends CBehavior { /** * @var array cached relations between the auth items. */ private $_items = array(); /** * Return thee parents and children of specific item or all items * @param string $itemName name of the item. * @return array */ public function getItems($itemName = null) { if ($itemName && isset($this->_items[$itemName])) { return $this->_items[$itemName]; } return $this->_items; } /** * Sets the parents of specific item * @param string $itemName name of the item. * @param array $parents */ public function setItemParents($itemName, $parents) { $this->_items[$itemName]['parents'] = $parents; } /** * Sets the children of specific item * @param string $itemName name of the item. * @param array $children */ public function setItemChildren($itemName, $children) { $this->_items[$itemName]['children'] = $children; } /** * Gets the parents of specific item if exists * @param string $itemName name of the item. * @return array */ public function getParents($itemName) { $items = $this->getItems($itemName); if (isset($items['parents'])) { return $items['parents']; } return array(); } /** * Gets the children of specific item if exists * @param string $itemName name of the item. * @return array */ public function getChildren($itemName) { $items = $this->getItems($itemName); if (isset($items['children'])) { return $items['children']; } return array(); } /** * Returns whether the given item has a specific parent. * @param string $itemName name of the item. * @param string $parentName name of the parent. * @return boolean the result. */ public function hasParent($itemName, $parentName) { $parents = $this->getParents($itemName); if (in_array($parentName, $parents)) { return true; } return false; } /** * Returns whether the given item has a specific child. * @param string $itemName name of the item. * @param string $childName name of the child. * @return boolean the result. */ public function hasChild($itemName, $childName) { $children = $this->getChildren($itemName); if (in_array($childName, $children)) { return true; } return false; } /** * Returns whether the given item has a specific ancestor. * @param string $itemName name of the item. * @param string $ancestorName name of the ancestor. * @return boolean the result. */ public function hasAncestor($itemName, $ancestorName) { $ancestors = $this->getAncestors($itemName); return isset($ancestors[$ancestorName]); } /** * Returns whether the given item has a specific descendant. * @param string $itemName name of the item. * @param string $descendantName name of the descendant. * @return boolean the result. */ public function hasDescendant($itemName, $descendantName) { $descendants = $this->getDescendants($itemName); return isset($descendants[$descendantName]); } /** * Returns flat array of all ancestors. * @param string $itemName name of the item. * @return array the ancestors. */ public function getAncestors($itemName) { $ancestors = $this->getAncestor($itemName); return $this->flattenPermissions($ancestors); } /** * Returns all ancestors for the given item recursively. * @param string $itemName name of the item. * @param integer $depth current depth. * @return array the ancestors. */ public function getAncestor($itemName, $depth = 0) { $ancestors = array(); $parents = $this->getParents($itemName); if (empty($parents)) { $parents = $this->owner->db->createCommand() ->select('parent') ->from($this->owner->itemChildTable) ->where('child=:child', array(':child' => $itemName)) ->queryColumn(); $this->setItemParents($itemName, $parents); } foreach ($parents as $parent) { $ancestors[] = array( 'name' => $parent, 'item' => $this->owner->getAuthItem($parent), 'parents' => $this->getAncestor($parent, $depth + 1), 'depth' => $depth ); } return $ancestors; } /** * Returns flat array of all the descendants. * @param string $itemName name of the item. * @return array the descendants. */ public function getDescendants($itemName) { $descendants = $this->getDescendant($itemName); return $this->flattenPermissions($descendants); } /** * Returns all the descendants for the given item recursively. * @param string $itemName name of the item. * @param integer $depth current depth. * @return array the descendants. */ public function getDescendant($itemName, $depth = 0) { $descendants = array(); $children = $this->getChildren($itemName); if (empty($children)) { $children = $this->owner->db->createCommand() ->select('child') ->from($this->owner->itemChildTable) ->where('parent=:parent', array(':parent' => $itemName)) ->queryColumn(); $this->setItemChildren($itemName, $children); } foreach ($children as $child) { $descendants[$child] = array( 'name' => $child, 'item' => $this->owner->getAuthItem($child), 'children' => $this->getDescendant($child, $depth + 1), 'depth' => $depth, ); } return $descendants; } /** * Returns the permission tree for the given items. * @param CAuthItem[] $items items to process. If omitted the complete tree will be returned. * @param integer $depth current depth. * @return array the permissions. */ private function getPermissions($items = null, $depth = 0) { $permissions = array(); if ($items === null) { $items = $this->owner->getAuthItems(); } foreach ($items as $itemName => $item) { $permissions[$itemName] = array( 'name' => $itemName, 'item' => $item, 'children' => $this->getPermissions($item, $depth + 1), 'depth' => $depth, ); } return $permissions; } /** * Builds the permissions for the given item. * @param string $itemName name of the item. * @return array the permissions. */ private function getItemPermissions($itemName) { $item = $this->owner->getAuthItem($itemName); return $item instanceof CAuthItem ? $this->getPermissions($item->getChildren()) : array(); } /** * Returns the permissions for the items with the given names. * @param string[] $names list of item names. * @return array the permissions. */ public function getItemsPermissions($names) { $permissions = array(); $items = $this->getPermissions(); $flat = $this->flattenPermissions($items); foreach ($flat as $itemName => $item) { if (in_array($itemName, $names)) { $permissions[$itemName] = $item; } } return $permissions; } /** * Flattens the given permission tree. * @param array $permissions the permissions tree. * @return array the permissions. */ public function flattenPermissions($permissions) { $flattened = array(); foreach ($permissions as $itemName => $itemPermissions) { $flattened[$itemName] = $itemPermissions; if (isset($itemPermissions['children'])) { $children = $itemPermissions['children']; unset($itemPermissions['children']); // not needed in a flat tree $flattened = array_merge($flattened, $this->flattenPermissions($children)); } if (isset($itemPermissions['parents'])) { $parents = $itemPermissions['parents']; unset($itemPermissions['parents']); $flattened = array_merge($flattened, $this->flattenPermissions($parents)); } } return $flattened; } }
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/components/CachedDbAuthManager.php
components/CachedDbAuthManager.php
<?php /** * CachedDbAuthManager class file. * @author Christoffer Niska <ChristofferNiska@gmail.com> * @copyright Copyright &copy; Christoffer Niska 2012- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @package auth.components */ Yii::import('auth.components.ICachedAuthManager'); /** * Caching layer for CDbAuthManager that allows for caching access checks. */ class CachedDbAuthManager extends CDbAuthManager implements ICachedAuthManager { const CACHE_KEY_PREFIX = 'Auth.CachedDbAuthManager.'; /** * @var integer the time in seconds that the messages can remain valid in cache. * Defaults to 0, meaning the caching is disabled. */ public $cachingDuration = 0; /** * @var string the ID of the cache application component that is used to cache the messages. * Defaults to 'cache' which refers to the primary cache application component. * Set this property to false if you want to disable caching. */ public $cacheID = 'cache'; /** * Performs access check for the specified user. * @param string $itemName the name of the operation that need access check. * @param integer $userId the user id. * @param array $params name-value pairs that would be passed to biz rules associated * with the tasks and roles assigned to the user. * @param boolean $allowCaching whether to allow caching the result of access check. * @return boolean whether the operations can be performed by the user. */ public function checkAccess($itemName, $userId, $params = array(), $allowCaching = true) { $cacheKey = $this->resolveCacheKey($itemName, $userId); $key = serialize($params); if ($allowCaching && ($cache = $this->getCache()) !== null) { if (($data = $cache->get($cacheKey)) !== false) { $data = unserialize($data); if (isset($data[$key])) { return $data[$key]; } } } else { $data = array(); } $result = $data[$key] = parent::checkAccess($itemName, $userId, $params); if (isset($cache)) { $cache->set($cacheKey, serialize($data), $this->cachingDuration); } return $result; } /** * Flushes the access cache for the specified user. * @param string $itemName the name of the operation that need access check. * @param integer $userId the user id. * @return boolean whether access was flushed. */ public function flushAccess($itemName, $userId) { if (($cache = $this->getCache()) !== null) { $cacheKey = $this->resolveCacheKey($itemName, $userId); return $cache->delete($cacheKey); } return false; } /** * Returns the key to use when caching. * @param string $itemName the name of the operation that need access check. * @param array $params name-value pairs that would be passed to biz rules associated * with the tasks and roles assigned to the user. * @return string the key. */ protected function resolveCacheKey($itemName, $userId) { return self::CACHE_KEY_PREFIX . 'checkAccess.' . $itemName . '.' . $userId; } /** * Returns the caching component for this component. * @return CCache|null the caching component. */ protected function getCache() { return $this->cachingDuration > 0 && $this->cacheID !== false ? Yii::app()->getComponent($this->cacheID) : null; } }
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/components/AuthController.php
components/AuthController.php
<?php /** * AuthController class file. * @author Christoffer Niska <ChristofferNiska@gmail.com> * @copyright Copyright &copy; Christoffer Niska 2012- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @package auth.components */ /** * Base controller for the module. * Note: Do NOT extend your controllers from this class! */ abstract class AuthController extends CController { /** * @var array context menu items. This property will be assigned to {@link CMenu::items}. */ public $menu = array(); /** * @var array the breadcrumbs of the current page. */ public $breadcrumbs = array(); /** * Initializes the controller. */ public function init() { parent::init(); $this->layout = $this->module->defaultLayout; $this->menu = $this->getSubMenu(); } /** * Returns the authorization item type as a string. * @param string $type the item type (0=operation, 1=task, 2=role). * @param boolean $plural whether to return the name in plural. * @return string the text. * @throws CException if the item type is invalid. */ public function getItemTypeText($type, $plural = false) { // todo: change the default value for $plural to false. $n = $plural ? 2 : 1; switch ($type) { case CAuthItem::TYPE_OPERATION: $name = Yii::t('AuthModule.main', 'operation|operations', $n); break; case CAuthItem::TYPE_TASK: $name = Yii::t('AuthModule.main', 'task|tasks', $n); break; case CAuthItem::TYPE_ROLE: $name = Yii::t('AuthModule.main', 'role|roles', $n); break; default: throw new CException('Auth item type "' . $type . '" is valid.'); } return $name; } /** * Returns the controllerId for the given authorization item. * @param string $type the item type (0=operation, 1=task, 2=role). * @return string the controllerId. * @throws CException if the item type is invalid. */ public function getItemControllerId($type) { $controllerId = null; switch ($type) { case CAuthItem::TYPE_OPERATION: $controllerId = 'operation'; break; case CAuthItem::TYPE_TASK: $controllerId = 'task'; break; case CAuthItem::TYPE_ROLE: $controllerId = 'role'; break; default: throw new CException('Auth item type "' . $type . '" is valid.'); } return $controllerId; } /** * Capitalizes the first word in the given string. * @param string $string the string to capitalize. * @return string the capitalized string. * @see http://stackoverflow.com/questions/2517947/ucfirst-function-for-multibyte-character-encodings */ public function capitalize($string) { if (!extension_loaded('mbstring')) { return ucfirst($string); } $encoding = Yii::app()->charset; $firstChar = mb_strtoupper(mb_substr($string, 0, 1, $encoding), $encoding); return $firstChar . mb_substr($string, 1, mb_strlen($string, $encoding) - 1, $encoding); } /** * Returns the sub menu configuration. * @return array the configuration. */ protected function getSubMenu() { return array( array( 'label' => Yii::t('AuthModule.main', 'Assignments'), 'url' => array('/auth/assignment/index'), 'active' => $this instanceof AssignmentController, ), array( 'label' => $this->capitalize($this->getItemTypeText(CAuthItem::TYPE_ROLE, true)), 'url' => array('/auth/role/index'), 'active' => $this instanceof RoleController, ), array( 'label' => $this->capitalize($this->getItemTypeText(CAuthItem::TYPE_TASK, true)), 'url' => array('/auth/task/index'), 'active' => $this instanceof TaskController, ), array( 'label' => $this->capitalize($this->getItemTypeText(CAuthItem::TYPE_OPERATION, true)), 'url' => array('/auth/operation/index'), 'active' => $this instanceof OperationController, ), ); } }
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/components/ICachedAuthManager.php
components/ICachedAuthManager.php
<?php /** * ICachedAuthManager class file. * @author Christoffer Niska <ChristofferNiska@gmail.com> * @copyright Copyright &copy; Christoffer Niska 2012- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @package auth.components */ /** * Interface for cached authorization managers. */ interface ICachedAuthManager { /** * Performs access check for the specified user. * @param string $itemName the name of the operation that need access check. * @param integer $userId the user id. * @param array $params name-value pairs that would be passed to biz rules associated * with the tasks and roles assigned to the user. * @param boolean $allowCaching whether to allow caching the result of access check. * @return boolean whether the operations can be performed by the user. */ public function checkAccess($itemName, $userId, $params = array(), $allowCaching = true); /** * Flushes the access cache for the specified user. * @param string $itemName the name of the operation that need access check. * @param integer $userId the user id. * @return boolean whether access was flushed. */ public function flushAccess($itemName, $userId); }
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/components/AuthItemDataProvider.php
components/AuthItemDataProvider.php
<?php /** * AuthItemDataProvider class file. * @author Christoffer Niska <ChristofferNiska@gmail.com> * @copyright Copyright &copy; Christoffer Niska 2012- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @package auth.components */ /** * Data provider for listing authorization items. */ class AuthItemDataProvider extends CDataProvider { /** * @var string the item type (0=operation, 1=task, 2=role). */ public $type; private $_items = array(); /** * Sets the authorization items. * @param CAuthItem[] $authItems the items. */ public function setAuthItems($authItems) { $this->_items = array_values($authItems); } /** * Fetches the data from the persistent data storage. * @return array list of data items */ protected function fetchData() { if (empty($this->_items) && $this->type !== null) { $authItems = Yii::app()->authManager->getAuthItems($this->type); $this->setAuthItems($authItems); } return $this->_items; } /** * Fetches the data item keys from the persistent data storage. * @return array list of data item keys. */ protected function fetchKeys() { return array('name', 'description', 'type', 'bizrule', 'data'); } /** * Calculates the total number of data items. * @return integer the total number of data items. */ protected function calculateTotalItemCount() { return count($this->_items); } }
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/messages/de/main.php
messages/de/main.php
<?php /** * Message translations. * * This file is automatically generated by 'yiic message' command. * It contains the localizable messages extracted from source code. * You may modify this file by translating the extracted messages. * * Each array element represents the translation (value) of a message (key). * If the value is empty, the message is considered as not translated. * Messages that no longer need translation will have their translations * enclosed between a pair of '@@' marks. * * Message string can be used with plural forms format. Check i18n section * of the guide for details. * * NOTE, this file must be saved in UTF-8 encoding. * * @version $Id: $ */ return array ( 'Access denied.' => 'Zugriff verweigert.', 'Add' => 'Hinzufügen', 'Add child' => 'Untergeordnetes Element hinzufügen', 'Add {type}' => '{type} hinzufügen', 'Ancestors' => 'Übergeordnete', 'Are you sure you want to delete this item?' => 'Sind sie sicher, dass sie dieses Element löschen möchten?', 'Assign' => 'Zuordnen', 'Assign permission' => 'Berechtigung zuweisen', 'Assigned items' => 'Zugeordnete Elemente', 'Assignments' => 'Zuordnungen', 'Business rule' => 'Geschäftsregel', 'Cancel' => 'Abbrechen', 'Create' => 'Anlegen', 'Data' => 'Daten', 'Descendants' => 'Untergeordnete', 'Description' => 'Beschreibung', 'Edit' => 'Bearbeiten', 'Invalid request.' => 'Ungültige Anfrage.', 'Item does not exist.' => 'Element existiert nicht.', 'Items' => 'Elemente', 'Items assigned to this user' => 'Diesem Benutzer zugeordnete Elemente', 'New {type}' => 'Neu {type}', 'No assignments found.' => 'Keine Zuordnungen gefunden', 'No {type} found.' => '{type} nicht gefunden.', 'Page not found.' => 'Seite nicht gefunden.', 'Permissions' => 'Berechtigungen', 'Permissions granted by this item' => 'Durch dieses Element gewährte Berechtigungen', 'Permissions that inherit this item' => 'Berechtigungen, die diesen Element erben', 'Remove' => 'Entfernen', 'Revoke' => 'Zurückziehen', 'Save' => 'Speichern', 'Select item' => 'Element auswählen', 'System name' => 'Systemname', 'System name cannot be changed after creation.' => 'Systemname kann nach dem Erstellen nicht geändert werden.', 'This item does not have any ancestors.' => 'Dieser Element hat keine übergeordneten Elemente.', 'This item does not have any descendants.' => 'Dieser Element hat keine untergeordneten Elemente.', 'This user does not have any assignments.' => 'Dieser Benutzer hat keine Zuordnungen.', 'Type' => 'Typ', 'User' => 'Benutzer', 'View' => 'Anzeigen', 'operation|operations' => 'Operation|Operationen', 'role|roles' => 'Rolle|Rollen', 'task|tasks' => 'Aufgabe|Aufgaben', );
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/messages/uk/main.php
messages/uk/main.php
<?php /** * Message translations. * * This file is automatically generated by 'yiic message' command. * It contains the localizable messages extracted from source code. * You may modify this file by translating the extracted messages. * * Each array element represents the translation (value) of a message (key). * If the value is empty, the message is considered as not translated. * Messages that no longer need translation will have their translations * enclosed between a pair of '@@' marks. * * Message string can be used with plural forms format. Check i18n section * of the guide for details. * * NOTE, this file must be saved in UTF-8 encoding. * * @version $Id: $ */ return array ( 'Access denied.' => 'Доступ заборонено.', 'Add' => 'Додати', 'Add child' => 'Додати нащадка', 'Add {type}' => 'Додати {type}', 'Ancestors' => 'Предки', 'Are you sure you want to delete this item?' => 'Ви дійсно хочете видалити цей елемент?', 'Assign' => 'Призначити', 'Assign permission' => 'Призначити дозвіл', 'Assigned items' => 'Призначені елементи', 'Assignments' => 'Призначення', 'Business rule' => 'Бізнес правило', 'Cancel' => 'Скасувати', 'Create' => 'Створити', 'Delete' => 'Видалити', 'Data' => 'Дані', 'Descendants' => 'Нащадки', 'Description' => 'Опис', 'Edit' => 'Редагувати', 'Invalid request.' => 'Некоректний запит.', 'Item does not exist.' => 'Елемент не існує.', 'Items' => 'Елементи', 'Items assigned to this user' => 'Елементи призначені цьому користувачу', 'New {type}' => 'Нова {type}', 'No assignments found.' => 'Не знайдено призначень.', 'No {type} found.' => 'Не знайдено {type}.', 'Page not found.' => 'Сторінку не знайдено.', 'Permissions' => 'Дозволи', 'Permissions granted by this item' => 'Дозволи надані цим елементом', 'Permissions that inherit this item' => 'Дозволи які успадковують цей елемент.', 'Remove' => 'Видалити', 'Revoke' => 'Відкликати', 'Save' => 'Зберегти', 'Select item' => 'Виберіть елемент', 'System name' => 'Системна назва', 'System name cannot be changed after creation.' => 'Системна назва не може бути змінена після створення.', 'This item does not have any ancestors.' => 'Цей елемент не має предків.', 'This item does not have any descendants.' => 'Цей елемент не має нащадків.', 'This user does not have any assignments.' => 'Цей елемент не має призначень.', 'Type' => 'Тип', 'User' => 'Користувач', 'View' => 'Перегляд', 'operation|operations' => 'операція|операції', 'role|roles' => 'роль|ролі', 'task|tasks' => 'завдання|завдання', );
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/messages/pt_br/main.php
messages/pt_br/main.php
<?php /** * Message translations. * * This file is automatically generated by 'yiic message' command. * It contains the localizable messages extracted from source code. * You may modify this file by translating the extracted messages. * * Each array element represents the translation (value) of a message (key). * If the value is empty, the message is considered as not translated. * Messages that no longer need translation will have their translations * enclosed between a pair of '@@' marks. * * Message string can be used with plural forms format. Check i18n section * of the guide for details. * * NOTE, this file must be saved in UTF-8 encoding. * * @version $Id: $ */ return array ( 'Access denied.' => 'Acesso negado.', 'Add' => 'Adicionar', 'Add child' => 'Adicionar descendente', 'Add {type}' => 'Adicionar {type}', 'Ancestors' => 'Ancestrais', 'Are you sure you want to delete this item?' => 'Tem certeza que deseja apagar este item?', 'Assign' => 'Atribuir', 'Assign permission' => 'Atribuir permissão', 'Assigned items' => 'Itens atribuídos', 'Assignments' => 'Atribuições', 'Business rule' => 'Regra', 'Cancel' => 'Cancelar', 'Create' => 'Criar', 'Delete' => 'Apagar', 'Data' => 'Dados', 'Descendants' => 'Descendentes', 'Description' => 'Descrição', 'Edit' => 'Editar', 'Invalid request.' => 'Pedido inválido.', 'Item does not exist.' => 'O item não existe.', 'Items' => 'Itens', 'Items assigned to this user' => 'Itens atribuídos a este usuário', 'New {type}' => 'Novo {type}', 'No assignments found.' => 'Atribuições não encontradas.', 'No {type} found.' => '"{type}" Não encontrado.', 'Page not found.' => 'Página não encontrada.', 'Permissions' => 'Permissões', 'Permissions granted by this item' => 'Permissões concedidas por este item', 'Permissions that inherit this item' => 'Permissões que herdam este item', 'Remove' => 'Remover', 'Revoke' => 'Anular', 'Save' => 'Salvar', 'Select item' => 'Selecionar item', 'System name' => 'Nome de sistema', 'System name cannot be changed after creation.' => 'Nome de sistema não poderá ser alterado após a criação.', 'This item does not have any ancestors.' => 'Este item não possui ancestrais.', 'This item does not have any descendants.' => 'Este item não possui descendentes.', 'This user does not have any assignments.' => 'Este usuário não possui atribuições.', 'Type' => 'Tipo', 'User' => 'Usuário', 'View' => 'Exibir', 'operation|operations' => 'operação|operações', 'role|roles' => 'função|funções', 'task|tasks' => 'tarefa|tarefas', );
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/messages/zh/main.php
messages/zh/main.php
<?php /** * Message translations. * * This file is automatically generated by 'yiic message' command. * It contains the localizable messages extracted from source code. * You may modify this file by translating the extracted messages. * * Each array element represents the translation (value) of a message (key). * If the value is empty, the message is considered as not translated. * Messages that no longer need translation will have their translations * enclosed between a pair of '@@' marks. * * Message string can be used with plural forms format. Check i18n section * of the guide for details. * * NOTE, this file must be saved in UTF-8 encoding. * * @version $Id: $ */ return array ( 'Access denied.' => '拒绝访问', 'Add' => '添加', 'Add child' => '添加子项', 'Add {type}' => '添加{type}', 'Ancestors' => '祖先', 'Are you sure you want to delete this item?' => '您确定要删除指定授权项?', 'Assign' => '指派', 'Assign permission' => '已指派的权限', 'Assigned items' => '已指派的授权项', 'Assignments' => '授权', 'Business rule' => '业务逻辑', 'Cancel' => '取消', 'Create' => '创建', 'Delete' => '删除', 'Data' => '资料', 'Descendants' => '后代', 'Description' => '描述', 'Edit' => '编辑', 'Invalid request.' => '无效的请求', 'Item does not exist.' => '授权项不存在', 'Items' => '授权项', 'Items assigned to this user' => '授权项已指派给用户', 'New {type}' => '新的{type}', 'No assignments found.' => '没有找到授权项', 'No {type} found.' => '没有找到{type}', 'Page not found.' => '页面未找到', 'Permissions' => '权限', 'Permissions granted by this item' => '此授权项的权限', 'Permissions that inherit this item' => '此授权项继承的权限', 'Remove' => '移除', 'Revoke' => '撤消', 'Save' => '储存', 'Select item' => '选择授权项', 'System name' => '系统名称', 'System name cannot be changed after creation.' => '不允许更改系统名称', 'This item does not have any ancestors.' => '此授权项并没有祖先', 'This item does not have any descendants.' => '此授权项并没有后代', 'This user does not have any assignments.' => '此用户并没有任何授权项', 'Type' => '种类', 'User' => '用户', 'View' => '查看', 'operation|operations' => '操作', 'role|roles' => '角色', 'task|tasks' => '任务', );
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/messages/ja/main.php
messages/ja/main.php
<?php /** * Message translations. * * This file is automatically generated by 'yiic message' command. * It contains the localizable messages extracted from source code. * You may modify this file by translating the extracted messages. * * Each array element represents the translation (value) of a message (key). * If the value is empty, the message is considered as not translated. * Messages that no longer need translation will have their translations * enclosed between a pair of '@@' marks. * * Message string can be used with plural forms format. Check i18n section * of the guide for details. * * NOTE, this file must be saved in UTF-8 encoding. * * @version $Id: $ */ return array ( 'Access denied.' => 'アクセスが許可されていません。', 'Add' => '追加', 'Add child' => '子を追加する', 'Add {type}' => '{type} を追加する', 'Ancestors' => '親アイテム', 'Are you sure you want to delete this item?' => 'このアイテムを削除します。よろしいですか?', 'Assign' => '割り当て', 'Assign permission' => '権限を割り当てる', 'Assigned items' => '割り当てられたアイテム', 'Assignments' => '割り当て', 'Business rule' => 'ビジネスルール', 'Cancel' => 'キャンセル', 'Create' => '作成', 'Delete' => '削除', 'Data' => 'データ', 'Descendants' => '子アイテム', 'Description' => '説明', 'Edit' => '編集', 'Invalid request.' => '', 'Item does not exist.' => 'アイテムが存在しません。', 'Items' => 'アイテム', 'Items assigned to this user' => 'このユーザに割り当てられたアイテム', 'New {type}' => '新しい {type}', 'No assignments found.' => '割り当てられたアイテムが見つかりません。', 'No {type} found.' => '{type} が見つかりません。', 'Page not found.' => 'ページが見つかりません。', 'Permissions' => '権限', 'Permissions granted by this item' => 'このアイテムによって許可される権限', 'Permissions that inherit this item' => 'このアイテムを継承する権限', 'Remove' => '削除', 'Revoke' => '取り消す', 'Save' => '保存', 'Select item' => 'アイテムを選択してください', 'System name' => 'システム名称', 'System name cannot be changed after creation.' => 'システム名称は作成後に変更することは出来ません。', 'This item does not have any ancestors.' => 'このアイテムには親がありません。', 'This item does not have any descendants.' => 'このアイテムには子がありません。', 'This user does not have any assignments.' => 'このユーザにはアイテムの割り当てがありません。', 'Type' => 'タイプ', 'User' => 'ユーザ', 'View' => '閲覧', 'operation|operations' => 'オペレーション', 'role|roles' => 'ロール', 'task|tasks' => 'タスク', );
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/messages/pl/main.php
messages/pl/main.php
<?php /** * Message translations. * * This file is automatically generated by 'yiic message' command. * It contains the localizable messages extracted from source code. * You may modify this file by translating the extracted messages. * * Each array element represents the translation (value) of a message (key). * If the value is empty, the message is considered as not translated. * Messages that no longer need translation will have their translations * enclosed between a pair of '@@' marks. * * Message string can be used with plural forms format. Check i18n section * of the guide for details. * * NOTE, this file must be saved in UTF-8 encoding. * * @version $Id: $ */ return array ( 'Access denied.' => 'Dostęp zabroniony.', 'Add' => 'Dodaj', 'Add child' => 'Dodaj potomka', 'Add {type}' => 'Dodaj {type}', 'Ancestors' => 'Rodzice', 'Are you sure you want to delete this item?' => 'Jesteś pewien, że chcesz usunąć ten element?', 'Assign' => 'Przydziel', 'Assign permission' => 'Przydziel uprawnienie', 'Assigned items' => 'Przydzielone elementy', 'Assignments' => 'Przydziały', 'Business rule' => 'Reguła biznesowa', 'Cancel' => 'Anuluj', 'Create' => 'Utwórz', 'Delete' => 'Usuń', 'Data' => 'Dane', 'Descendants' => 'Potomkowie', 'Description' => 'Opis', 'Edit' => 'Edytuj', 'Invalid request.' => 'Nieprawidłowe żądanie.', 'Item does not exist.' => 'Element nie istnieje.', 'Items' => 'Elementy', 'Items assigned to this user' => 'Elementy przydzielone temu użytkownikowi', 'New {type}' => 'Nowy {type}', 'No assignments found.' => 'Nie odnaleziono żadnych przydziałów.', 'No {type} found.' => 'Nie odnaleziono {type}.', 'Page not found.' => 'Strona nie odnaleziona.', 'Permissions' => 'Uprawnienia', 'Permissions granted by this item' => 'Uprawnienia nadane przez ten element', 'Permissions that inherit this item' => 'Uprawnienia, które dziedziczą ten element', 'Remove' => 'Usuń', 'Revoke' => 'Odbierz', 'Save' => 'Zapisz', 'Select item' => 'Wybierz element', 'System name' => 'Nazwa systemowa', 'System name cannot be changed after creation.' => 'Nazwa systemowa nie może zostać zmieniona po utworzeniu', 'This item does not have any ancestors.' => 'Ten element nie ma rodziców.', 'This item does not have any descendants.' => 'Ten element nie ma potomków.', 'This user does not have any assignments.' => 'Ten użytkownik nie ma żadnych przydzielonych elementów.', 'Type' => 'Typ', 'User' => 'Użytkownik', 'View' => 'Obejrzyj', 'operation|operations' => 'operacja|operacje|operacji|operacji', 'role|roles' => 'rola|role|roli|roli', 'task|tasks' => 'zadanie|zadania|zadań|zadania', );
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/messages/fr/main.php
messages/fr/main.php
<?php /** * Message translations. * * This file is automatically generated by 'yiic message' command. * It contains the localizable messages extracted from source code. * You may modify this file by translating the extracted messages. * * Each array element represents the translation (value) of a message (key). * If the value is empty, the message is considered as not translated. * Messages that no longer need translation will have their translations * enclosed between a pair of '@@' marks. * * Message string can be used with plural forms format. Check i18n section * of the guide for details. * * NOTE, this file must be saved in UTF-8 encoding. * * @version $Id: $ */ return array ( 'Access denied.' => 'Accès refusé', 'Add' => 'Ajouter', 'Add child' => 'Ajouter enfant', 'Add {type}' => 'Ajouter {type}', 'Ancestors' => 'Ancêtres', 'Are you sure you want to delete this item?' => 'Etes-vous sûr de vouloir supprimer cet item ?', 'Assign' => 'Assigner', 'Assign permission' => 'Assigner permission', 'Assigned items' => 'Assigner item', 'Assignments' => 'Assignements', 'Business rule' => 'Règle métier', 'Cancel' => 'Annuler', 'Create' => 'Créer', 'Delete' => 'Supprimer', 'Data' => 'Donné', 'Descendants' => 'Descendants', 'Description' => 'Description', 'Edit' => 'Modifier', 'Invalid request.' => 'Requête invalide.', 'Item does not exist.' => 'Cet item n\'existe pas', 'Items' => 'Items', 'Items assigned to this user' => 'Items assignés à cet utilisateur', 'New {type}' => 'Nouveau {type}', 'No assignments found.' => 'Aucune assignation trouvée', 'No {type} found.' => 'Aucun(e) {type} trouvé(e)', 'Page not found.' => 'Page introuvable', 'Permissions' => 'Permissions', 'Permissions granted by this item' => 'Permissions fournies par cet item', 'Permissions that inherit this item' => 'Permissions qui héritent de cet item', 'Remove' => 'Supprimer', 'Revoke' => 'Revoquer', 'Save' => 'Sauver', 'Select item' => 'Sélectionner item', 'System name' => 'Nom système', 'System name cannot be changed after creation.' => 'Le nom système ne peut pas être modifié après création.', 'This item does not have any ancestors.' => 'Cet item n\'a pas d\'ancêtre.', 'This item does not have any descendants.' => 'Cet item n\'a pas de descendant.', 'This user does not have any assignments.' => 'Cet utilisateur n\'a pas d\'assignation.', 'Type' => 'Type', 'User' => 'Utilisateur', 'View' => 'Vue', 'operation|operations' => 'opération|opérations', 'role|roles' => 'rôle|rôles', 'task|tasks' => 'tâche|tâches', );
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/messages/pt/main.php
messages/pt/main.php
<?php /** * Message translations. * * This file is automatically generated by 'yiic message' command. * It contains the localizable messages extracted from source code. * You may modify this file by translating the extracted messages. * * Each array element represents the translation (value) of a message (key). * If the value is empty, the message is considered as not translated. * Messages that no longer need translation will have their translations * enclosed between a pair of '@@' marks. * * Message string can be used with plural forms format. Check i18n section * of the guide for details. * * NOTE, this file must be saved in UTF-8 encoding. * * @version $Id: $ */ return array ( 'Access denied.' => 'Acesso negado.', 'Add' => 'Adicionar', 'Add child' => 'Adicionar filho', 'Add {type}' => 'Adicionar {type}', 'Ancestors' => 'Ancestrais', 'Are you sure you want to delete this item?' => 'Tem a certeza que deseja apagar este item?', 'Assign' => 'Atribuir', 'Assign permission' => 'Atribuir permissão', 'Assigned items' => 'Itens atribuídos', 'Assignments' => 'Atribuições', 'Business rule' => '', 'Cancel' => 'Cancelar', 'Create' => 'Criar', 'Delete' => 'Apagar', 'Data' => 'Dados', 'Descendants' => 'Descendentes', 'Description' => 'Descrição', 'Edit' => 'Editar', 'Invalid request.' => 'Pedido inválido.', 'Item does not exist.' => 'O item não existe.', 'Items' => 'Itens', 'Items assigned to this user' => 'Itens atribuídos a este utilizador', 'New {type}' => 'Novo {type}', 'No assignments found.' => 'Atribuições não encontradas.', 'No {type} found.' => 'Nenhum "{type}" encontrado.', 'Page not found.' => 'Página não encontrada.', 'Permissions' => 'Permissões', 'Permissions granted by this item' => 'Permissões concedidas por este item', 'Permissions that inherit this item' => 'Permissões que herdam este item', 'Remove' => 'Remover', 'Revoke' => 'Revogar', 'Save' => 'Guardar', 'Select item' => 'Selecionar item', 'System name' => 'Nome de sistema', 'System name cannot be changed after creation.' => 'Nome de sistema não poderá ser alterado após a criação.', 'This item does not have any ancestors.' => 'Este item ainda não possui ancestrais.', 'This item does not have any descendants.' => 'Este item ainda não possui descendentes.', 'This user does not have any assignments.' => 'Este utilizador ainda não possui atribuições.', 'Type' => 'Tipo', 'User' => 'Utilizador', 'View' => 'Ver', 'operation|operations' => 'operação|operações', 'role|roles' => 'função|funções', 'task|tasks' => 'tarefa|tarefas', );
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/messages/it/main.php
messages/it/main.php
<?php /** * Message translations. * * This file is automatically generated by 'yiic message' command. * It contains the localizable messages extracted from source code. * You may modify this file by translating the extracted messages. * * Each array element represents the translation (value) of a message (key). * If the value is empty, the message is considered as not translated. * Messages that no longer need translation will have their translations * enclosed between a pair of '@@' marks. * * Message string can be used with plural forms format. Check i18n section * of the guide for details. * * NOTE, this file must be saved in UTF-8 encoding. * * @version $Id: $ */ return array ( 'Access denied.' => 'Accesso negato.', 'Add' => 'Aggiungi', 'Add child' => 'Aggiungi come figlio', 'Add {type}' => 'Aggiungi {type}', 'Ancestors' => 'Antenati', 'Are you sure you want to delete this item?' => 'Sei sicuro di voler cancellare questo elemento?', 'Assign' => 'Associa', 'Assign permission' => 'Associa autorizzazione', 'Assigned items' => 'Elementi associati', 'Assignments' => 'Incarichi', 'Business rule' => 'Regole di attività', 'Cancel' => 'Annulla', 'Create' => 'Crea', 'Delete' => 'Cancella', 'Data' => 'Dati', 'Descendants' => 'Discendenti', 'Description' => 'Descrizione', 'Edit' => 'Modifica', 'Invalid request.' => 'Richiesta non valida.', 'Item does not exist.' => 'L\'elemento non esiste.', 'Items' => 'Elementi', 'Items assigned to this user' => 'Elementi associati a questo utente', 'New {type}' => 'Aggiungi {type}', 'No assignments found.' => 'Nessun incarico trovato.', 'No {type} found.' => 'Impossibile trovare {type}', 'Page not found.' => 'Pagina non trovata.', 'Permissions' => 'Autorizzazioni', 'Permissions granted by this item' => 'Autorizzazioni concesse da questo elemento', 'Permissions that inherit this item' => 'Autorizzazioni che ereditano questo elemento', 'Remove' => 'Cancella', 'Revoke' => 'Revoca', 'Save' => 'Salva', 'Select item' => 'Seleziona elemento', 'System name' => 'Etichetta', 'System name cannot be changed after creation.' => 'L\'etichetta non può essere cambiata una volta creata.', 'This item does not have any ancestors.' => 'Questo elemento non ha antenati.', 'This item does not have any descendants.' => 'Questo elemento non ha discendenti.', 'This user does not have any assignments.' => 'Questo utente è privo incarichi.', 'Type' => 'Tipo', 'User' => 'Utente', 'View' => 'Dettagli', 'operation|operations' => 'operazione|operazioni', 'role|roles' => 'ruolo|ruoli', 'task|tasks' => 'compito|compiti', );
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/messages/template/main.php
messages/template/main.php
<?php /** * Message translations. * * This file is automatically generated by 'yiic message' command. * It contains the localizable messages extracted from source code. * You may modify this file by translating the extracted messages. * * Each array element represents the translation (value) of a message (key). * If the value is empty, the message is considered as not translated. * Messages that no longer need translation will have their translations * enclosed between a pair of '@@' marks. * * Message string can be used with plural forms format. Check i18n section * of the guide for details. * * NOTE, this file must be saved in UTF-8 encoding. * * @version $Id: $ */ return array ( 'Access denied.' => '', 'Add' => '', 'Add child' => '', 'Add {type}' => '', 'Ancestors' => '', 'Are you sure you want to delete this item?' => '', 'Assign' => '', 'Assign permission' => '', 'Assigned items' => '', 'Assignments' => '', 'Business rule' => '', 'Cancel' => '', 'Create' => '', 'Delete' => '', 'Data' => '', 'Descendants' => '', 'Description' => '', 'Edit' => '', 'Invalid request.' => '', 'Item does not exist.' => '', 'Items' => '', 'Items assigned to this user' => '', 'New {type}' => '', 'No assignments found.' => '', 'No {type} found.' => '', 'Page not found.' => '', 'Permissions' => '', 'Permissions granted by this item' => '', 'Permissions that inherit this item' => '', 'Remove' => '', 'Revoke' => '', 'Save' => '', 'Select item' => '', 'System name' => '', 'System name cannot be changed after creation.' => '', 'This item does not have any ancestors.' => '', 'This item does not have any descendants.' => '', 'This user does not have any assignments.' => '', 'Type' => '', 'User' => '', 'View' => '', 'operation|operations' => '', 'role|roles' => '', 'task|tasks' => '', );
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/messages/ru/main.php
messages/ru/main.php
<?php /** * Message translations. * * This file is automatically generated by 'yiic message' command. * It contains the localizable messages extracted from source code. * You may modify this file by translating the extracted messages. * * Each array element represents the translation (value) of a message (key). * If the value is empty, the message is considered as not translated. * Messages that no longer need translation will have their translations * enclosed between a pair of '@@' marks. * * Message string can be used with plural forms format. Check i18n section * of the guide for details. * * NOTE, this file must be saved in UTF-8 encoding. * * @version $Id: $ */ return array ( 'Access denied.' => 'Доступ запрещен.', 'Add' => 'Добавить', 'Add child' => 'Добавить потомка', 'Add {type}' => 'Добавить {type}', 'Ancestors' => 'Предки', 'Are you sure you want to delete this item?' => 'Вы уверены, что хотите удалить данный элемент?', 'Assign' => 'Назначить', 'Assign permission' => 'Назначить права', 'Assigned items' => 'Назначенные элементы', 'Assignments' => 'Соответствия', 'Business rule' => 'Бизнес правило', 'Cancel' => 'Отменить', 'Create' => 'Создать', 'Delete' => 'Удалить', 'Data' => 'Данные', 'Descendants' => 'Потомки', 'Description' => 'Описание', 'Edit' => 'Редактировать', 'Invalid request.' => 'Неверный запрос.', 'Item does not exist.' => 'Элемент не существует.', 'Items' => 'Элементы', 'Items assigned to this user' => 'Элемент назначен данному пользователю', 'New {type}' => 'Новый {type}', 'No assignments found.' => 'Не найдено назначений', 'No {type} found.' => 'Не найдено {type}', 'Page not found.' => 'Страница не найдена', 'Permissions' => 'Права', 'Permissions granted by this item' => 'Права, предоставляемые элементом', 'Permissions that inherit this item' => 'Права, которые наследует данный элемент', 'Remove' => 'Удалить', 'Revoke' => 'Отнять', 'Save' => 'Сохранить', 'Select item' => 'Выбрать элемент', 'System name' => 'Системное название', 'System name cannot be changed after creation.' => 'Системное название не может быть изменено после создания', 'This item does not have any ancestors.' => 'Данный элемент не имеет предков', 'This item does not have any descendants.' => 'Данный элемент не имеет потомков', 'This user does not have any assignments.' => 'Данный пользователь не имеет прав', 'Type' => 'Тип', 'User' => 'Пользователь', 'View' => 'Просмотреть', 'operation|operations' => 'операция|операции', 'role|roles' => 'роль|роли', 'task|tasks' => 'задание|задания', );
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/messages/es/main.php
messages/es/main.php
<?php /** * Message translations. * * This file is automatically generated by 'yiic message' command. * It contains the localizable messages extracted from source code. * You may modify this file by translating the extracted messages. * * Each array element represents the translation (value) of a message (key). * If the value is empty, the message is considered as not translated. * Messages that no longer need translation will have their translations * enclosed between a pair of '@@' marks. * * Message string can be used with plural forms format. Check i18n section * of the guide for details. * * NOTE, this file must be saved in UTF-8 encoding. * * @version $Id: $ */ return array ( 'Access denied.' => 'Acceso denegado.', 'Add' => 'Agregar', 'Add child' => 'Agregar hijo', 'Add {type}' => 'Agregar {type}', 'Ancestors' => 'Ancestros', 'Are you sure you want to delete this item?' => '¿Está seguro de querer eliminar este elemento?', 'Assign' => 'Asignar', 'Assign permission' => 'Asignar permiso', 'Assigned items' => 'Elementos asignados', 'Assignments' => 'Asignaciones', 'Business rule' => 'Regla de negocio', 'Cancel' => 'Cancelar', 'Create' => 'Crear', 'Delete' => 'Eliminar', 'Data' => 'Datos', 'Descendants' => 'Descendientes', 'Description' => 'Descripción', 'Edit' => 'Editar', 'Invalid request.' => 'Solicitud inválida.', 'Item does not exist.' => 'El elemento no existe.', 'Items' => 'Elementos', 'Items assigned to this user' => 'Elementos asignados a este usuario', 'New {type}' => 'Nuevo {type}', 'No assignments found.' => 'No se encontraron asignaciones.', 'No {type} found.' => '{type} no encontrado(s).', 'Page not found.' => 'Página no encontrada.', 'Permissions' => 'Permisos', 'Permissions granted by this item' => 'Permisos otorgados a este elemento', 'Permissions that inherit this item' => 'Permisos que hereda este elemento', 'Remove' => 'Eliminar', 'Revoke' => 'Revocar', 'Save' => 'Guardar', 'Select item' => 'Seleccionar elemento', 'System name' => 'Nombre de sistema', 'System name cannot be changed after creation.' => 'El nombre de sistema no puede cambiarse después de crearse.', 'This item does not have any ancestors.' => 'Este elemento no tiene ancestros.', 'This item does not have any descendants.' => 'Este elemento no tiene descendientes.', 'This user does not have any assignments.' => 'Este usuario no tiene asignaciones.', 'Type' => 'Tipo', 'User' => 'Usuario', 'View' => 'Ver', 'operation|operations' => 'operación|operaciones', 'role|roles' => 'rol|roles', 'task|tasks' => 'tarea|tareas', );
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/messages/da/main.php
messages/da/main.php
<?php /** * Message translations. * * This file is automatically generated by 'yiic message' command. * It contains the localizable messages extracted from source code. * You may modify this file by translating the extracted messages. * * Each array element represents the translation (value) of a message (key). * If the value is empty, the message is considered as not translated. * Messages that no longer need translation will have their translations * enclosed between a pair of '@@' marks. * * Message string can be used with plural forms format. Check i18n section * of the guide for details. * * NOTE, this file must be saved in UTF-8 encoding. * * @version $Id: $ */ return array ( 'Access denied.' => 'Afgang nægtet.', 'Add' => 'Tilføj', 'Add child' => 'Tilføj barn', 'Add {type}' => 'Tilføj {type}', 'Ancestors' => 'Forfædre', 'Are you sure you want to delete this item?' => 'Er du sikker på at du vil slette dette element?', 'Assign' => 'Tildel', 'Assign permission' => 'Tildel rettighed', 'Assigned items' => 'Tildelte elementer', 'Assignments' => 'Tildelinger', 'Business rule' => 'Forretningsregel', 'Cancel' => 'Annuller', 'Create' => 'Opret', 'Delete' => 'SLet', 'Data' => 'Data', 'Descendants' => 'Efterkommere', 'Description' => 'Beskrivelse', 'Edit' => 'Ret', 'Invalid request.' => 'Ugyldig forespørgsel.', 'Item does not exist.' => 'Elementet eksisterer ikke.', 'Items' => 'Elementer', 'Items assigned to this user' => 'Elementer tildelt denne bruger', 'New {type}' => 'Ny {type}', 'No assignments found.' => 'Ingen tildelinger fundet.', 'No {type} found.' => 'Ingen {type} fundet.', 'Page not found.' => 'Siden blev ikke fundet.', 'Permissions' => 'Rettigheder', 'Permissions granted by this item' => 'Rettigheder tildelt dette element', 'Permissions that inherit this item' => 'Rettigheder som arver fra dette element', 'Remove' => 'Fjern', 'Revoke' => 'Tilbagekald', 'Save' => 'Gem', 'Select item' => 'Vælg element', 'System name' => 'Systemnavn', 'System name cannot be changed after creation.' => 'Systemnavn kan ikke skiftes efter oprettelse.', 'This item does not have any ancestors.' => 'Dette element har ikke nogen forfædre', 'This item does not have any descendants.' => 'Dette element har ikke nogen efterkommere.', 'This user does not have any assignments.' => 'Denne bruger har ikke nogen tildelinger.', 'Type' => 'Type', 'User' => 'Bruger', 'View' => 'Vis', 'operation|operations' => 'operation|operationer', 'role|roles' => 'role|roler', 'task|tasks' => 'opgave|opgaver', );
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/models/AuthItemForm.php
models/AuthItemForm.php
<?php /** * AuthItemForm class file. * @author Christoffer Niska <ChristofferNiska@gmail.com> * @copyright Copyright &copy; Christoffer Niska 2012- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @package auth.models */ /** * Form model for updating an authorization item. */ class AuthItemForm extends CFormModel { /** * @var string item name. */ public $name; /** * @var string item description. */ public $description; /** * @var string business rule associated with the item. */ public $bizrule; /** * @var string additional data for the item. */ public $data; /** * @var string the item type (0=operation, 1=task, 2=role). */ public $type; /** * Returns the attribute labels. * @return array attribute labels (name=>label) */ public function attributeLabels() { return array( 'name' => Yii::t('AuthModule.main', 'System name'), 'description' => Yii::t('AuthModule.main', 'Description'), 'bizrule' => Yii::t('AuthModule.main', 'Business rule'), 'data' => Yii::t('AuthModule.main', 'Data'), 'type' => Yii::t('AuthModule.main', 'Type'), ); } /** * Returns the validation rules for attributes. * @return array validation rules. */ public function rules() { return array( array('description, type', 'required'), array('name', 'required', 'on' => 'create'), array('name', 'length', 'max' => 64), ); } }
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/models/AddAuthItemForm.php
models/AddAuthItemForm.php
<?php /** * AddAuthItemForm class file. * @author Christoffer Niska <ChristofferNiska@gmail.com> * @copyright Copyright &copy; Christoffer Niska 2012- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @package auth.models */ /** * Form model for displaying a list of authorization items. */ class AddAuthItemForm extends CFormModel { /** * @var array a list of authorization items. */ public $items; /** * Returns the attribute labels. * @return array attribute labels (name=>label) */ public function attributeLabels() { return array( 'items' => Yii::t('AuthModule.main', 'Items'), ); } /** * Returns the validation rules for attributes. * @return array validation rules. */ public function rules() { return array( array('items', 'required'), ); } }
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/views/assignment/view.php
views/assignment/view.php
<?php /* @var $this AssignmentController */ /* @var $model User */ /* @var $authItemDp AuthItemDataProvider */ /* @var $formModel AddAuthItemForm */ /* @var $form TbActiveForm */ /* @var $assignmentOptions array */ $this->breadcrumbs = array( Yii::t('AuthModule.main', 'Assignments') => array('index'), CHtml::value($model, $this->module->userNameColumn), ); ?> <h1><?php echo CHtml::encode(CHtml::value($model, $this->module->userNameColumn)); ?> <small><?php echo Yii::t('AuthModule.main', 'Assignments'); ?></small> </h1> <div class="row"> <div class="span6"> <h3> <?php echo Yii::t('AuthModule.main', 'Permissions'); ?> <small><?php echo Yii::t('AuthModule.main', 'Items assigned to this user'); ?></small> </h3> <?php $this->widget( 'bootstrap.widgets.TbGridView', array( 'type' => 'striped condensed hover', 'dataProvider' => $authItemDp, 'emptyText' => Yii::t('AuthModule.main', 'This user does not have any assignments.'), 'hideHeader' => true, 'template' => "{items}", 'columns' => array( array( 'class' => 'AuthItemDescriptionColumn', 'active' => true, ), array( 'class' => 'AuthItemTypeColumn', 'active' => true, ), array( 'class' => 'AuthAssignmentRevokeColumn', 'userId' => $model->{$this->module->userIdColumn}, ), ), ) ); ?> <?php if (!empty($assignmentOptions)): ?> <h4><?php echo Yii::t('AuthModule.main', 'Assign permission'); ?></h4> <?php $form = $this->beginWidget( 'bootstrap.widgets.TbActiveForm', array( 'layout' => TbHtml::FORM_LAYOUT_INLINE, ) ); ?> <?php echo $form->dropDownList($formModel, 'items', $assignmentOptions, array('label' => false)); ?> <?php echo TbHtml::submitButton( Yii::t('AuthModule.main', 'Assign'), array( 'color' => TbHtml::BUTTON_COLOR_PRIMARY, ) ); ?> <?php $this->endWidget(); ?> <?php endif; ?> </div> </div>
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/views/assignment/index.php
views/assignment/index.php
<?php /* @var $this AssignmentController */ /* @var $dataProvider CActiveDataProvider */ $this->breadcrumbs = array( Yii::t('AuthModule.main', 'Assignments'), ); ?> <h1><?php echo Yii::t('AuthModule.main', 'Assignments'); ?></h1> <?php $this->widget( 'bootstrap.widgets.TbGridView', array( 'type' => 'striped hover', 'dataProvider' => $dataProvider, 'emptyText' => Yii::t('AuthModule.main', 'No assignments found.'), 'template' => "{items}\n{pager}", 'columns' => array( array( 'header' => Yii::t('AuthModule.main', 'User'), 'class' => 'AuthAssignmentNameColumn', ), array( 'header' => Yii::t('AuthModule.main', 'Assigned items'), 'class' => 'AuthAssignmentItemsColumn', ), array( 'class' => 'AuthAssignmentViewColumn', ), ), ) ); ?>
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/views/layouts/main.php
views/layouts/main.php
<?php /* @var $this AuthController */ ?> <div class="auth-module"> <?php $this->widget( 'bootstrap.widgets.TbNav', array( 'type' => TbHtml::NAV_TYPE_TABS, 'items' => array( array( 'label' => Yii::t('AuthModule.main', 'Assignments'), 'url' => array('/auth/assignment/index'), 'active' => $this instanceof AssignmentController, ), array( 'label' => $this->capitalize($this->getItemTypeText(CAuthItem::TYPE_ROLE, true)), 'url' => array('/auth/role/index'), 'active' => $this instanceof RoleController, ), array( 'label' => $this->capitalize($this->getItemTypeText(CAuthItem::TYPE_TASK, true)), 'url' => array('/auth/task/index'), 'active' => $this instanceof TaskController, ), array( 'label' => $this->capitalize($this->getItemTypeText(CAuthItem::TYPE_OPERATION, true)), 'url' => array('/auth/operation/index'), 'active' => $this instanceof OperationController, ), ), ) );?> <?php echo $content; ?> </div>
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/views/authItem/view.php
views/authItem/view.php
<?php /* @var $this OperationController|TaskController|RoleController */ /* @var $item CAuthItem */ /* @var $ancestorDp AuthItemDataProvider */ /* @var $descendantDp AuthItemDataProvider */ /* @var $formModel AddAuthItemForm */ /* @var $form TbActiveForm */ /* @var $childOptions array */ $this->breadcrumbs = array( $this->capitalize($this->getTypeText(true)) => array('index'), $item->description, ); ?> <div class="title-row clearfix"> <h1 class="pull-left"> <?php echo CHtml::encode($item->description); ?> <small><?php echo $this->getTypeText(); ?></small> </h1> <?php echo TbHtml::buttonGroup( array( array( 'label' => Yii::t('AuthModule.main', 'Edit'), 'url' => array('update', 'name' => $item->name), ), array( 'icon' => 'trash', 'url' => array('delete', 'name' => $item->name), 'htmlOptions' => array( 'confirm' => Yii::t('AuthModule.main', 'Are you sure you want to delete this item?'), ), ), ), array('class' => 'pull-right') ); ?> </div> <?php $this->widget( 'zii.widgets.CDetailView', array( 'data' => $item, 'attributes' => array( array( 'name' => 'name', 'label' => Yii::t('AuthModule.main', 'System name'), ), array( 'name' => 'description', 'label' => Yii::t('AuthModule.main', 'Description'), ), /* array( 'name' => 'bizrule', 'label' => Yii::t('AuthModule.main', 'Business rule'), ), array( 'name' => 'data', 'label' => Yii::t('AuthModule.main', 'Data'), ), */ ), ) ); ?> <hr/> <div class="row"> <div class="span6"> <h3> <?php echo Yii::t('AuthModule.main', 'Ancestors'); ?> <small><?php echo Yii::t('AuthModule.main', 'Permissions that inherit this item'); ?></small> </h3> <?php $this->widget( 'bootstrap.widgets.TbGridView', array( 'type' => 'striped condensed hover', 'dataProvider' => $ancestorDp, 'emptyText' => Yii::t('AuthModule.main', 'This item does not have any ancestors.'), 'template' => "{items}", 'hideHeader' => true, 'columns' => array( array( 'class' => 'AuthItemDescriptionColumn', 'itemName' => $item->name, ), array( 'class' => 'AuthItemTypeColumn', 'itemName' => $item->name, ), array( 'class' => 'AuthItemRemoveColumn', 'itemName' => $item->name, ), ), ) ); ?> </div> <div class="span6"> <h3> <?php echo Yii::t('AuthModule.main', 'Descendants'); ?> <small><?php echo Yii::t('AuthModule.main', 'Permissions granted by this item'); ?></small> </h3> <?php $this->widget( 'bootstrap.widgets.TbGridView', array( 'type' => 'striped condensed hover', 'dataProvider' => $descendantDp, 'emptyText' => Yii::t('AuthModule.main', 'This item does not have any descendants.'), 'hideHeader' => true, 'template' => "{items}", 'columns' => array( array( 'class' => 'AuthItemDescriptionColumn', 'itemName' => $item->name, ), array( 'class' => 'AuthItemTypeColumn', 'itemName' => $item->name, ), array( 'class' => 'AuthItemRemoveColumn', 'itemName' => $item->name, ), ), ) ); ?> </div> </div> <div class="row"> <div class="span6 offset6"> <?php if (!empty($childOptions)): ?> <h4><?php echo Yii::t('AuthModule.main', 'Add child'); ?></h4> <?php $form = $this->beginWidget( 'bootstrap.widgets.TbActiveForm', array( 'layout' => TbHtml::FORM_LAYOUT_INLINE, ) ); ?> <?php echo $form->dropDownListControlGroup($formModel, 'items', $childOptions, array('label' => false)); ?> <?php echo TbHtml::submitButton( Yii::t('AuthModule.main', 'Add'), array( 'color' => TbHtml::BUTTON_COLOR_PRIMARY, ) ); ?> <?php $this->endWidget(); ?> <?php endif; ?> </div> </div>
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/views/authItem/index.php
views/authItem/index.php
<?php /* @var $this OperationController|TaskController|RoleController */ /* @var $dataProvider AuthItemDataProvider */ $this->breadcrumbs = array( $this->capitalize($this->getTypeText(true)), ); ?> <h1><?php echo $this->capitalize($this->getTypeText(true)); ?></h1> <?php echo TbHtml::linkButton( Yii::t('AuthModule.main', 'Add {type}', array('{type}' => $this->getTypeText())), array( 'color' => TbHtml::BUTTON_COLOR_PRIMARY, 'url' => array('create'), ) ); ?> <?php $this->widget( 'bootstrap.widgets.TbGridView', array( 'type' => 'striped hover', 'dataProvider' => $dataProvider, 'emptyText' => Yii::t('AuthModule.main', 'No {type} found.', array('{type}' => $this->getTypeText(true))), 'template' => "{items}\n{pager}", 'columns' => array( array( 'name' => 'name', 'type' => 'raw', 'header' => Yii::t('AuthModule.main', 'System name'), 'htmlOptions' => array('class' => 'item-name-column'), 'value' => "CHtml::link(\$data->name, array('view', 'name'=>\$data->name))", ), array( 'name' => 'description', 'header' => Yii::t('AuthModule.main', 'Description'), 'htmlOptions' => array('class' => 'item-description-column'), ), array( 'class' => 'bootstrap.widgets.TbButtonColumn', 'viewButtonLabel' => Yii::t('AuthModule.main', 'View'), 'viewButtonUrl' => "Yii::app()->controller->createUrl('view', array('name'=>\$data->name))", 'updateButtonLabel' => Yii::t('AuthModule.main', 'Edit'), 'updateButtonUrl' => "Yii::app()->controller->createUrl('update', array('name'=>\$data->name))", 'deleteButtonLabel' => Yii::t('AuthModule.main', 'Delete'), 'deleteButtonUrl' => "Yii::app()->controller->createUrl('delete', array('name'=>\$data->name))", 'deleteConfirmation' => Yii::t('AuthModule.main', 'Are you sure you want to delete this item?'), ), ), ) ); ?>
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/views/authItem/update.php
views/authItem/update.php
<?php /* @var $this OperationController|TaskController|RoleController */ /* @var $model AuthItemForm */ /* @var $item CAuthItem */ /* @var $form TbActiveForm */ $this->breadcrumbs = array( $this->capitalize($this->getTypeText(true)) => array('index'), $item->description => array('view', 'name' => $item->name), Yii::t('AuthModule.main', 'Edit'), ); ?> <h1> <?php echo CHtml::encode($item->description); ?> <small><?php echo $this->getTypeText(); ?></small> </h1> <?php $form = $this->beginWidget( 'bootstrap.widgets.TbActiveForm', array( 'layout' => TbHtml::FORM_LAYOUT_HORIZONTAL, ) ); ?> <?php echo $form->hiddenField($model, 'type'); ?> <?php echo $form->textFieldControlGroup( $model, 'name', array( 'disabled' => true, 'title' => Yii::t('AuthModule.main', 'System name cannot be changed after creation.'), ) ); ?> <?php echo $form->textFieldControlGroup($model, 'description'); ?> <div class="form-actions"> <?php echo TbHtml::submitButton( Yii::t('AuthModule.main', 'Save'), array( 'color' => TbHtml::BUTTON_COLOR_PRIMARY, ) ); ?> <?php echo TbHtml::linkButton( Yii::t('AuthModule.main', 'Cancel'), array( 'color' => TbHtml::BUTTON_COLOR_LINK, 'url' => array('view', 'name' => $item->name), ) ); ?> </div> <?php $this->endWidget(); ?>
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/views/authItem/create.php
views/authItem/create.php
<?php /* @var $this OperationController|TaskController|RoleController */ /* @var $model AuthItemForm */ /* @var $form TbActiveForm */ $this->breadcrumbs = array( $this->capitalize($this->getTypeText(true)) => array('index'), Yii::t('AuthModule.main', 'New {type}', array('{type}' => $this->getTypeText())), ); ?> <h1><?php echo Yii::t('AuthModule.main', 'New {type}', array('{type}' => $this->getTypeText())); ?></h1> <?php $form = $this->beginWidget( 'bootstrap.widgets.TbActiveForm', array( 'layout' => TbHtml::FORM_LAYOUT_HORIZONTAL, ) ); ?> <?php echo $form->hiddenField($model, 'type'); ?> <?php echo $form->textFieldControlGroup($model, 'name'); ?> <?php echo $form->textFieldControlGroup($model, 'description'); ?> <div class="form-actions"> <?php echo TbHtml::submitButton( Yii::t('AuthModule.main', 'Create'), array( 'color' => TbHtml::BUTTON_COLOR_PRIMARY, ) ); ?> <?php echo TbHtml::linkButton( Yii::t('AuthModule.main', 'Cancel'), array( 'color' => TbHtml::BUTTON_COLOR_LINK, 'url' => array('index'), ) ); ?> </div> <?php $this->endWidget(); ?>
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/widgets/AuthItemTypeColumn.php
widgets/AuthItemTypeColumn.php
<?php /** * AuthItemTypeColumn class file. * @author Christoffer Niska <ChristofferNiska@gmail.com> * @copyright Copyright &copy; Christoffer Niska 2012- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @package auth.widgets */ /** * Grid column for displaying the type for an authorization item row. */ class AuthItemTypeColumn extends AuthItemColumn { /** * Initializes the column. */ public function init() { if (isset($this->htmlOptions['class'])) { $this->htmlOptions['class'] .= ' item-type-column'; } else { $this->htmlOptions['class'] = 'item-type-column'; } } /** * Renders the data cell content. * @param integer $row the row number (zero-based). * @param mixed $data the data associated with the row. */ protected function renderDataCellContent($row, $data) { /* @var $am CAuthManager|AuthBehavior */ $am = Yii::app()->getAuthManager(); $labelType = $this->active || $am->hasParent($this->itemName, $data['name']) || $am->hasChild( $this->itemName, $data['name'] ) ? 'info' : ''; /* @var $controller AuthItemController */ $controller = $this->grid->getController(); echo TbHtml::labelTb( $controller->getItemTypeText($data['item']->type), array( 'color' => $labelType, ) ); } }
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/widgets/AuthItemColumn.php
widgets/AuthItemColumn.php
<?php /** * AuthItemColumn class file. * @author Christoffer Niska <ChristofferNiska@gmail.com> * @copyright Copyright &copy; Christoffer Niska 2012- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @package auth.widgets */ Yii::import('zii.widgets.grid.CGridColumn'); /** * Grid column for displaying authorization item related data. */ class AuthItemColumn extends CGridColumn { /** * @var string name of the item. */ public $itemName; /** * @var boolean whether the row should appear activated. */ public $active = false; }
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/widgets/AuthAssignmentColumn.php
widgets/AuthAssignmentColumn.php
<?php /** * AuthAssignmentColumn class file. * @author Christoffer Niska <ChristofferNiska@gmail.com> * @copyright Copyright &copy; Christoffer Niska 2012- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @package auth.widgets */ Yii::import('zii.widgets.grid.CGridColumn'); /** * Grid column for displaying assignment related data. * * @property string $idColumn name of the user id column. * @property string $nameColumn name of the user name column. */ class AuthAssignmentColumn extends CGridColumn { /** * @var integer the user id. */ public $userId; /** * Returns the name of the user id column. * @return string the column name. */ protected function getIdColumn() { return $this->grid->controller->module->userIdColumn; } /** * Returns the name of the user name column. * @return string the column name. */ protected function getNameColumn() { return $this->grid->controller->module->userNameColumn; } }
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/widgets/AuthAssignmentItemsColumn.php
widgets/AuthAssignmentItemsColumn.php
<?php /** * AuthAssignmentItemsColumn class file. * @author Christoffer Niska <ChristofferNiska@gmail.com> * @copyright Copyright &copy; Christoffer Niska 2012- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @package auth.widgets */ /** * Grid column for displaying the authorization items for an assignment row. */ class AuthAssignmentItemsColumn extends AuthAssignmentColumn { /** * Initializes the column. */ public function init() { if (isset($this->htmlOptions['class'])) { $this->htmlOptions['class'] .= ' assignment-items-column'; } else { $this->htmlOptions['class'] = 'assignment-items-column'; } } /** * Renders the data cell content. * @param integer $row the row number (zero-based). * @param mixed $data the data associated with the row. */ protected function renderDataCellContent($row, $data) { /* @var $am CAuthManager|AuthBehavior */ $am = Yii::app()->getAuthManager(); /* @var $controller AssignmentController */ $controller = $this->grid->getController(); $assignments = $am->getAuthAssignments($data->{$this->idColumn}); $permissions = $am->getItemsPermissions(array_keys($assignments)); foreach ($permissions as $itemPermission) { echo $itemPermission['item']->description; echo ' <small>' . $controller->getItemTypeText($itemPermission['item']->type, false) . '</small><br />'; } } }
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/widgets/AuthItemRemoveColumn.php
widgets/AuthItemRemoveColumn.php
<?php /** * AuthItemRemoveColumn class file. * @author Christoffer Niska <ChristofferNiska@gmail.com> * @copyright Copyright &copy; Christoffer Niska 2012- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @package auth.widgets */ /** * Grid column for displaying the remove link for an authorization item row. */ class AuthItemRemoveColumn extends AuthItemColumn { /** * Initializes the column. */ public function init() { if (isset($this->htmlOptions['class'])) { $this->htmlOptions['class'] .= ' actions-column'; } else { $this->htmlOptions['class'] = 'actions-column'; } } /** * Renders the data cell content. * @param integer $row the row number (zero-based). * @param mixed $data the data associated with the row. */ protected function renderDataCellContent($row, $data) { /* @var $am CAuthManager|AuthBehavior */ $am = Yii::app()->getAuthManager(); if ($am->hasParent($this->itemName, $data['name'])) { echo TbHtml::linkButton( TbHtml::icon(TbHtml::ICON_REMOVE), array( 'color' => TbHtml::BUTTON_COLOR_LINK, 'size' => TbHtml::BUTTON_SIZE_MINI, 'url' => array('removeParent', 'itemName' => $this->itemName, 'parentName' => $data['name']), 'rel' => 'tooltip', 'title' => Yii::t('AuthModule.main', 'Remove'), ) ); } else { if ($am->hasChild($this->itemName, $data['name'])) { echo TbHtml::linkButton( TbHtml::icon(TbHtml::ICON_REMOVE), array( 'color' => TbHtml::BUTTON_COLOR_LINK, 'size' => TbHtml::BUTTON_SIZE_MINI, 'url' => array('removeChild', 'itemName' => $this->itemName, 'childName' => $data['name']), 'rel' => 'tooltip', 'title' => Yii::t('AuthModule.main', 'Remove'), ) ); } } } }
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/widgets/AuthAssignmentViewColumn.php
widgets/AuthAssignmentViewColumn.php
<?php /** * AuthAssignmentViewColumn class file. * @author Christoffer Niska <ChristofferNiska@gmail.com> * @copyright Copyright &copy; Christoffer Niska 2012- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @package auth.widgets */ /** * Grid column for displaying the view link for an assignment row. */ class AuthAssignmentViewColumn extends AuthAssignmentColumn { /** * Initializes the column. */ public function init() { if (isset($this->htmlOptions['class'])) { $this->htmlOptions['class'] .= ' actions-column'; } else { $this->htmlOptions['class'] = 'actions-column'; } } /** * Renders the data cell content. * @param integer $row the row number (zero-based). * @param mixed $data the data associated with the row. */ protected function renderDataCellContent($row, $data) { if (!Yii::app()->user->isAdmin) { echo TbHtml::linkButton( TbHtml::icon(TbHtml::ICON_EYE_OPEN), array( 'color' => TbHtml::BUTTON_COLOR_LINK, 'size' => TbHtml::BUTTON_SIZE_MINI, 'url' => array('view', 'id' => $data->{$this->idColumn}), 'htmlOptions' => array('rel' => 'tooltip', 'title' => Yii::t('AuthModule.main', 'View')), ) ); } } }
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/widgets/AuthAssignmentNameColumn.php
widgets/AuthAssignmentNameColumn.php
<?php /** * AuthAssignmentNameColumn class file. * @author Christoffer Niska <ChristofferNiska@gmail.com> * @copyright Copyright &copy; Christoffer Niska 2012- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @package auth.widgets */ /** * Grid column for displaying the name of the user for an assignment row. */ class AuthAssignmentNameColumn extends AuthAssignmentColumn { /** * Initializes the column. */ public function init() { if (isset($this->htmlOptions['class'])) { $this->htmlOptions['class'] .= ' name-column'; } else { $this->htmlOptions['class'] = 'name-column'; } } /** * Renders the data cell content. * @param integer $row the row number (zero-based). * @param mixed $data the data associated with the row. */ protected function renderDataCellContent($row, $data) { echo CHtml::link(CHtml::value($data, $this->nameColumn), array('view', 'id' => $data->{$this->idColumn})); } }
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/widgets/AuthAssignmentRevokeColumn.php
widgets/AuthAssignmentRevokeColumn.php
<?php /** * AuthAssignmentRevokeColumn class file. * @author Christoffer Niska <ChristofferNiska@gmail.com> * @copyright Copyright &copy; Christoffer Niska 2012- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @package auth.widgets */ /** * Grid column for displaying the revoke link for an assignment row. */ class AuthAssignmentRevokeColumn extends AuthAssignmentColumn { /** * Initializes the column. */ public function init() { if (isset($this->htmlOptions['class'])) { $this->htmlOptions['class'] .= ' actions-column'; } else { $this->htmlOptions['class'] = 'actions-column'; } } /** * Renders the data cell content. * @param integer $row the row number (zero-based). * @param mixed $data the data associated with the row. */ protected function renderDataCellContent($row, $data) { if ($this->userId !== null) { echo TbHtml::linkButton( TbHtml::icon(TbHtml::ICON_REMOVE), array( 'color' => TbHtml::BUTTON_COLOR_LINK, 'size' => TbHtml::BUTTON_SIZE_MINI, 'url' => array('revoke', 'itemName' => $data['name'], 'userId' => $this->userId), 'rel' => 'tooltip', 'title' => Yii::t('AuthModule.main', 'Revoke'), ) ); } } }
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/widgets/AuthItemDescriptionColumn.php
widgets/AuthItemDescriptionColumn.php
<?php /** * AuthItemColumn class file. * @author Christoffer Niska <ChristofferNiska@gmail.com> * @copyright Copyright &copy; Christoffer Niska 2012- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @package auth.widgets */ /** * Grid column for displaying the description for an authorization item row. */ class AuthItemDescriptionColumn extends AuthItemColumn { /** * Initializes the column. */ public function init() { if (isset($this->htmlOptions['class'])) { $this->htmlOptions['class'] .= ' item-description-column'; } else { $this->htmlOptions['class'] = 'item-description-column'; } } /** * Renders the data cell content. * @param integer $row the row number (zero-based). * @param mixed $data the data associated with the row. */ protected function renderDataCellContent($row, $data) { /* @var $am CAuthManager|AuthBehavior */ $am = Yii::app()->getAuthManager(); $linkCssClass = $this->active || $am->hasParent($this->itemName, $data['name']) || $am->hasChild( $this->itemName, $data['name'] ) ? 'active' : 'disabled'; /* @var $controller AuthItemController */ $controller = $this->grid->getController(); echo CHtml::link( $data['item']->description, array('/auth/' . $controller->getItemControllerId($data['item']->type) . '/view', 'name' => $data['name']), array('class' => $linkCssClass) ); } }
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
crisu83/yii-auth
https://github.com/crisu83/yii-auth/blob/c1b9108a41f78a46c77e073866410d10e283ac9a/filters/AuthFilter.php
filters/AuthFilter.php
<?php /** * AuthFilter class file. * @author Christoffer Niska <ChristofferNiska@gmail.com> * @copyright Copyright &copy; Christoffer Niska 2012- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @package auth.components */ /** * Filter that automatically checks if the user has access to the current controller action. */ class AuthFilter extends CFilter { /** * @var array name-value pairs that would be passed to business rules associated * with the tasks and roles assigned to the user. */ public $params = array(); /** * Performs the pre-action filtering. * @param CFilterChain $filterChain the filter chain that the filter is on. * @return boolean whether the filtering process should continue and the action should be executed. * @throws CHttpException if the user is denied access. */ protected function preFilter($filterChain) { $itemName = ''; $controller = $filterChain->controller; /* @var $user CWebUser */ $user = Yii::app()->getUser(); if (($module = $controller->getModule()) !== null) { $itemName .= $module->getId() . '.'; if ($user->checkAccess($itemName . '*')) { return true; } } $itemName .= $controller->getId(); if ($user->checkAccess($itemName . '.*')) { return true; } $itemName .= '.' . $controller->action->getId(); if ($user->checkAccess($itemName, $this->params)) { return true; } if ($user->isGuest) { $user->loginRequired(); } throw new CHttpException(401, Yii::t('yii', 'You are not authorized to perform this action.')); } }
php
BSD-3-Clause
c1b9108a41f78a46c77e073866410d10e283ac9a
2026-01-05T05:07:34.734757Z
false
ppshobi/psonic
https://github.com/ppshobi/psonic/blob/d7dd830c7512aedc31a9e34647a777566a9b893c/src/Client.php
src/Client.php
<?php namespace Psonic; use Psonic\Exceptions\ConnectionException; use Psonic\Contracts\Client as ClientInterface; use Psonic\Contracts\Command as CommandInterface; use Psonic\Contracts\Response as ResponseInterface; class Client implements ClientInterface { private $resource; private $host; private $port; private $errorNo; private $errorMessage; private $maxTimeout; /** * Client constructor. * @param string $host * @param int $port * @param int $timeout */ public function __construct($host = 'localhost', $port = 1491, $timeout = 30) { $this->host = $host; $this->port = $port; $this->maxTimeout = $timeout; $this->errorNo = null; $this->errorMessage = ''; } /** * @param CommandInterface $command * @return ResponseInterface * @throws ConnectionException */ public function send(CommandInterface $command): ResponseInterface { if (!$this->resource) { throw new ConnectionException(); } fwrite($this->resource, $command); return $this->read(); } /** * reads the buffer from a given stream * @return ResponseInterface */ public function read(): ResponseInterface { $message = explode("\r\n", fgets($this->resource))[0]; return new SonicResponse($message); } /** * @throws ConnectionException * connects to the socket */ public function connect() { if (!$this->resource = stream_socket_client("tcp://{$this->host}:{$this->port}", $this->errorNo, $this->errorMessage, $this->maxTimeout)) { throw new ConnectionException(); } } /** * Disconnects from a socket */ public function disconnect() { stream_socket_shutdown($this->resource, STREAM_SHUT_WR); $this->resource = null; } /** * @return bool * clears the output buffer */ public function clearBuffer() { stream_get_line($this->resource, 4096, "\r\n"); return true; } }
php
MIT
d7dd830c7512aedc31a9e34647a777566a9b893c
2026-01-05T05:07:38.798383Z
false
ppshobi/psonic
https://github.com/ppshobi/psonic/blob/d7dd830c7512aedc31a9e34647a777566a9b893c/src/Ingest.php
src/Ingest.php
<?php namespace Psonic; use Psonic\Channels\Channel; use Psonic\Contracts\Client; use InvalidArgumentException; use Psonic\Commands\Ingest\PopCommand; use Psonic\Commands\Ingest\PushCommand; use Psonic\Commands\Ingest\CountCommand; use Psonic\Commands\Ingest\FlushObjectCommand; use Psonic\Commands\Ingest\FlushBucketCommand; use Psonic\Commands\Ingest\FlushCollectionCommand; use Psonic\Commands\Ingest\StartIngestChannelCommand; class Ingest extends Channel { /** * Ingest constructor. * @param Client $client */ public function __construct(Client $client) { parent::__construct($client); } /** * @return mixed|Contracts\Response|void * @throws Exceptions\ConnectionException */ public function connect($password = 'SecretPassword') { parent::connect(); $response = $this->send(new StartIngestChannelCommand($password)); if ($bufferSize = $response->get('bufferSize')) { $this->bufferSize = (int)$bufferSize; } return $response; } /** * @param string $collection * @param string $bucket * @param string $object * @param string $text * @param string $locale * @return Contracts\Response */ public function push(string $collection, string $bucket, string $object, string $text, $locale = null) { $chunks = $this->splitString($collection, $bucket, $object, $text); if ($text == "" || empty($chunks)) { throw new InvalidArgumentException("The parameter \$text is empty"); } foreach ($chunks as $chunk) { $message = $this->send(new PushCommand($collection, $bucket, $object, $chunk, $locale)); if ($message == false || $message == "") { throw new InvalidArgumentException(); } } return $message; } /** * @param string $collection * @param string $bucket * @param string $object * @param string $text * @return mixed */ public function pop(string $collection, string $bucket, string $object, string $text) { $chunks = $this->splitString($collection, $bucket, $object, $text); $count = 0; foreach ($chunks as $chunk) { $message = $this->send(new PopCommand($collection, $bucket, $object, $chunk)); if ($message == false || $message == "") { throw new InvalidArgumentException(); } $count += $message->get('count'); } return $count; } /** * @param $collection * @param null $bucket * @param null $object * @return mixed */ public function count($collection, $bucket = null, $object = null) { $message = $this->send(new CountCommand($collection, $bucket, $object)); return $message->get('count'); } /** * @param $collection * @return mixed */ public function flushc($collection) { $message = $this->send(new FlushCollectionCommand($collection)); return $message->getCount(); } /** * @param $collection * @param $bucket * @return integer */ public function flushb($collection, $bucket) { $message = $this->send(new FlushBucketCommand($collection, $bucket)); return $message->getCount(); } /** * @param $collection * @param $bucket * @param $object * @return mixed */ public function flusho($collection, $bucket, $object) { $message = $this->send(new FlushObjectCommand($collection, $bucket, $object)); return $message->getCount(); } /** * @param string $collection * @param string $bucket * @param string $key * @param string $text * @return array */ private function splitString(string $collection, string $bucket, string $key, string $text): array { return str_split($text, ($this->bufferSize - (strlen($key . $collection . $bucket) + 20))); } }
php
MIT
d7dd830c7512aedc31a9e34647a777566a9b893c
2026-01-05T05:07:38.798383Z
false
ppshobi/psonic
https://github.com/ppshobi/psonic/blob/d7dd830c7512aedc31a9e34647a777566a9b893c/src/Control.php
src/Control.php
<?php namespace Psonic; use Psonic\Channels\Channel; use Psonic\Contracts\Client; use Psonic\Commands\Control\InfoCommand; use Psonic\Commands\Control\TriggerCommand; use Psonic\Commands\Control\StartControlChannelCommand; class Control extends Channel { /** * Control constructor. * @param Client $client */ public function __construct(Client $client) { parent::__construct($client); } /** * @return mixed|Contracts\Response|void * @throws Exceptions\ConnectionException */ public function connect($password = 'SecretPassword') { parent::connect(); $response = $this->send(new StartControlChannelCommand($password)); if ($bufferSize = $response->get('bufferSize')) { $this->bufferSize = (int)$bufferSize; } return $response; } /** * @param $action * @return Contracts\Response */ public function trigger($action) { return $this->send(new TriggerCommand($action)); } /** * @return Contracts\Response */ public function consolidate() { return $this->trigger('consolidate'); } public function info() { return $this->send(new InfoCommand); } }
php
MIT
d7dd830c7512aedc31a9e34647a777566a9b893c
2026-01-05T05:07:38.798383Z
false
ppshobi/psonic
https://github.com/ppshobi/psonic/blob/d7dd830c7512aedc31a9e34647a777566a9b893c/src/SonicResponse.php
src/SonicResponse.php
<?php namespace Psonic; use Psonic\Contracts\Response as ResponseInterface; use Psonic\Exceptions\CommandFailedException; class SonicResponse implements ResponseInterface { private $message; private $pieces; private $results; /** * SonicResponse constructor. * @param $message */ public function __construct($message) { $this->message = (string) $message; $this->parse(); } /** * parses the read buffer into a readable object * @throws CommandFailedException */ private function parse() { $this->pieces = explode(" ", $this->message); if(preg_match_all("/buffer\((\d+)\)/", $this->message, $matches)) { $this->pieces['bufferSize'] = $matches[1][0]; } $this->pieces['status'] = $this->pieces[0]; unset($this->pieces[0]); if($this->pieces['status'] === 'ERR') { throw new CommandFailedException($this->message); } if($this->pieces['status'] === 'RESULT') { $this->pieces['count'] = (int) $this->pieces[1]; unset($this->pieces[1]); } if($this->pieces['status'] === 'EVENT') { $this->pieces['query_key'] = $this->pieces[2]; $this->results = array_slice($this->pieces, 2, count($this->pieces)-4); } } /** * @return mixed */ public function getResults() { return $this->results; } /** * @return string */ public function __toString() { return implode(" ", $this->pieces); } /** * @param $key * @return mixed */ public function get($key) { if(isset($this->pieces[$key])){ return $this->pieces[$key]; } } /** * @return mixed */ public function getStatus(): string { return $this->get('status'); } /** * @return int */ public function getCount():int { return $this->get('count') ?? 0; } }
php
MIT
d7dd830c7512aedc31a9e34647a777566a9b893c
2026-01-05T05:07:38.798383Z
false
ppshobi/psonic
https://github.com/ppshobi/psonic/blob/d7dd830c7512aedc31a9e34647a777566a9b893c/src/Search.php
src/Search.php
<?php namespace Psonic; use Psonic\Channels\Channel; use Psonic\Contracts\Client; use Psonic\Commands\Search\QueryCommand; use Psonic\Commands\Search\SuggestCommand; use Psonic\Exceptions\CommandFailedException; use Psonic\Commands\Search\StartSearchChannelCommand; class Search extends Channel { /** * Search Channel constructor. * @param Client $client */ public function __construct(Client $client) { parent::__construct($client); } /** * @return mixed|Contracts\Response|void * @throws Exceptions\ConnectionException */ public function connect($password = 'SecretPassword') { parent::connect(); $response = $this->send(new StartSearchChannelCommand($password)); if ($bufferSize = $response->get('bufferSize')) { $this->bufferSize = (int)$bufferSize; } return $response; } /** * @param $collection * @param $bucket * @param $terms * @param $limit * @param $offset * @param $locale * @return array * @throws CommandFailedException */ public function query($collection, $bucket, $terms, $limit = null, $offset = null, $locale = null): array { $response = $this->send(new QueryCommand($collection, $bucket, $terms, $limit, $offset, $locale)); if (!$response->getStatus() == 'PENDING') { throw new CommandFailedException; } $results = $this->read(); if (!$results->getStatus() == 'EVENT') { throw new CommandFailedException; } return $results->getResults(); } /** * @param $collection * @param $bucket * @param $terms * @param $limit * @return array * @throws CommandFailedException */ public function suggest($collection, $bucket, $terms, $limit = null): array { $response = $this->send(new SuggestCommand($collection, $bucket, $terms, $limit)); if (!$response->getStatus() == 'PENDING') { throw new CommandFailedException; } $results = $this->read(); if (!$results->getStatus() == 'EVENT') { throw new CommandFailedException; } return $results->getResults(); } }
php
MIT
d7dd830c7512aedc31a9e34647a777566a9b893c
2026-01-05T05:07:38.798383Z
false
ppshobi/psonic
https://github.com/ppshobi/psonic/blob/d7dd830c7512aedc31a9e34647a777566a9b893c/src/Exceptions/ConnectionException.php
src/Exceptions/ConnectionException.php
<?php namespace Psonic\Exceptions; use Exception; class ConnectionException extends Exception { }
php
MIT
d7dd830c7512aedc31a9e34647a777566a9b893c
2026-01-05T05:07:38.798383Z
false
ppshobi/psonic
https://github.com/ppshobi/psonic/blob/d7dd830c7512aedc31a9e34647a777566a9b893c/src/Exceptions/CommandFailedException.php
src/Exceptions/CommandFailedException.php
<?php namespace Psonic\Exceptions; use Exception; class CommandFailedException extends Exception { }
php
MIT
d7dd830c7512aedc31a9e34647a777566a9b893c
2026-01-05T05:07:38.798383Z
false
ppshobi/psonic
https://github.com/ppshobi/psonic/blob/d7dd830c7512aedc31a9e34647a777566a9b893c/src/Channels/Channel.php
src/Channels/Channel.php
<?php namespace Psonic\Channels; use Psonic\Contracts\Client; use Psonic\Contracts\Command; use Psonic\Contracts\Response; use Psonic\Commands\Misc\PingCommand; use Psonic\Exceptions\ConnectionException; use Psonic\Commands\Misc\QuitChannelCommand; use Psonic\Contracts\Channel as ChannelInterface; abstract class Channel implements ChannelInterface { /** * @var Client */ protected $client; /** * @var integer */ protected $bufferSize; /** * Channel constructor. * @param Client $client */ public function __construct(Client $client) { $this->client = $client; } /** * @return mixed|void * @throws ConnectionException */ public function connect() { $this->client->connect(); $response = $this->client->read(); if($response->getStatus() == "CONNECTED") { return; } throw new ConnectionException; } /** * @return Response */ public function disconnect(): Response { $message = $this->client->send(new QuitChannelCommand); $this->client->disconnect(); return $message; } /** * @return Response */ public function ping(): Response { return $this->client->send(new PingCommand); } /** * @return Response */ public function read(): Response { return $this->client->read(); } /** * @param Command $command * @return Response */ public function send(Command $command): Response { return $this->client->send($command); } }
php
MIT
d7dd830c7512aedc31a9e34647a777566a9b893c
2026-01-05T05:07:38.798383Z
false
ppshobi/psonic
https://github.com/ppshobi/psonic/blob/d7dd830c7512aedc31a9e34647a777566a9b893c/src/Contracts/Command.php
src/Contracts/Command.php
<?php namespace Psonic\Contracts; interface Command { /** * @return string * ultimately a command instance get translated into a string */ public function __toString(): string ; }
php
MIT
d7dd830c7512aedc31a9e34647a777566a9b893c
2026-01-05T05:07:38.798383Z
false
ppshobi/psonic
https://github.com/ppshobi/psonic/blob/d7dd830c7512aedc31a9e34647a777566a9b893c/src/Contracts/Client.php
src/Contracts/Client.php
<?php namespace Psonic\Contracts; use Psonic\Exceptions\ConnectionException; interface Client { /** * Connects to a socket * @throws ConnectionException */ public function connect(); /** * disconnects the socket */ public function disconnect(); /** * @param Command $command * @return Response */ public function send(Command $command): Response; /** * @return Response * reads the output buffer */ public function read(): Response; }
php
MIT
d7dd830c7512aedc31a9e34647a777566a9b893c
2026-01-05T05:07:38.798383Z
false
ppshobi/psonic
https://github.com/ppshobi/psonic/blob/d7dd830c7512aedc31a9e34647a777566a9b893c/src/Contracts/Response.php
src/Contracts/Response.php
<?php namespace Psonic\Contracts; interface Response { /** * fetches an item from the parsed buffer * @param $key * @return mixed */ public function get($key); /** * returns the status of the read buffer * @return string */ public function getStatus(): string; }
php
MIT
d7dd830c7512aedc31a9e34647a777566a9b893c
2026-01-05T05:07:38.798383Z
false
ppshobi/psonic
https://github.com/ppshobi/psonic/blob/d7dd830c7512aedc31a9e34647a777566a9b893c/src/Contracts/Channel.php
src/Contracts/Channel.php
<?php namespace Psonic\Contracts; use Psonic\Exceptions\ConnectionException; interface Channel { /** * @return mixed * @throws ConnectionException */ public function connect(); /** * @return Response */ public function disconnect(): Response; }
php
MIT
d7dd830c7512aedc31a9e34647a777566a9b893c
2026-01-05T05:07:38.798383Z
false
ppshobi/psonic
https://github.com/ppshobi/psonic/blob/d7dd830c7512aedc31a9e34647a777566a9b893c/src/Commands/Command.php
src/Commands/Command.php
<?php namespace Psonic\Commands; use Psonic\Contracts\Command as CommandInterface; abstract class Command implements CommandInterface { private $command; private $parameters; public function __construct($command, $parameters = []) { $this->command = $command; $this->parameters = $parameters; } /** * Wrap the string in quotes, and normalize whitespace. Also remove double quotes. */ protected function wrapInQuotes($string) { $string = preg_replace('/[\r\n\t"]/', ' ', $string); $string = '"' . str_replace('"', '\"', $string) . '"'; return $string; } public function __toString(): string { return $this->command . " " . implode(" ", $this->parameters) . "\n"; } }
php
MIT
d7dd830c7512aedc31a9e34647a777566a9b893c
2026-01-05T05:07:38.798383Z
false
ppshobi/psonic
https://github.com/ppshobi/psonic/blob/d7dd830c7512aedc31a9e34647a777566a9b893c/src/Commands/Misc/PingCommand.php
src/Commands/Misc/PingCommand.php
<?php namespace Psonic\Commands\Misc; use Psonic\Commands\Command; final class PingCommand extends Command { private $command = 'PING'; private $parameters = []; /** * PingCommand constructor. */ public function __construct() { parent::__construct($this->command, $this->parameters); } }
php
MIT
d7dd830c7512aedc31a9e34647a777566a9b893c
2026-01-05T05:07:38.798383Z
false
ppshobi/psonic
https://github.com/ppshobi/psonic/blob/d7dd830c7512aedc31a9e34647a777566a9b893c/src/Commands/Misc/QuitChannelCommand.php
src/Commands/Misc/QuitChannelCommand.php
<?php namespace Psonic\Commands\Misc; use Psonic\Commands\Command; final class QuitChannelCommand extends Command { private $command = 'QUIT'; private $parameters = []; /** * QuitChannelCommand constructor. */ public function __construct() { parent::__construct($this->command, $this->parameters); } }
php
MIT
d7dd830c7512aedc31a9e34647a777566a9b893c
2026-01-05T05:07:38.798383Z
false
ppshobi/psonic
https://github.com/ppshobi/psonic/blob/d7dd830c7512aedc31a9e34647a777566a9b893c/src/Commands/Search/StartSearchChannelCommand.php
src/Commands/Search/StartSearchChannelCommand.php
<?php namespace Psonic\Commands\Search; use Psonic\Commands\Command; final class StartSearchChannelCommand extends Command { private $command = 'START'; private $parameters = []; /** * StartSearchChannelCommand constructor. * @param string $password */ public function __construct($password) { $this->parameters = [ 'mode' => 'search', 'password' => $password, ]; parent::__construct($this->command, $this->parameters); } }
php
MIT
d7dd830c7512aedc31a9e34647a777566a9b893c
2026-01-05T05:07:38.798383Z
false
ppshobi/psonic
https://github.com/ppshobi/psonic/blob/d7dd830c7512aedc31a9e34647a777566a9b893c/src/Commands/Search/SuggestCommand.php
src/Commands/Search/SuggestCommand.php
<?php namespace Psonic\Commands\Search; use Psonic\Commands\Command; final class SuggestCommand extends Command { private $command = 'SUGGEST'; private $parameters = []; /** * SuggestCommand constructor. * @param string $collection * @param string $bucket * @param string $terms * @param null $limit */ public function __construct(string $collection, string $bucket, string $terms, $limit = null) { $this->parameters = [ 'collection' => $collection, 'bucket' => $bucket, 'terms' => self::wrapInQuotes($terms), 'limit' => $limit ? "LIMIT($limit)" : null, ]; parent::__construct($this->command, $this->parameters); } }
php
MIT
d7dd830c7512aedc31a9e34647a777566a9b893c
2026-01-05T05:07:38.798383Z
false
ppshobi/psonic
https://github.com/ppshobi/psonic/blob/d7dd830c7512aedc31a9e34647a777566a9b893c/src/Commands/Search/QueryCommand.php
src/Commands/Search/QueryCommand.php
<?php namespace Psonic\Commands\Search; use Psonic\Commands\Command; final class QueryCommand extends Command { private $command = 'QUERY'; private $parameters = []; /** * QueryCommand constructor. * @param string $collection * @param string $bucket * @param string $terms * @param null $limit * @param null $offset * @param null $locale */ public function __construct(string $collection, string $bucket, string $terms, $limit = null, $offset = null, $locale = null) { $this->parameters = [ 'collection' => $collection, 'bucket' => $bucket, 'terms' => self::wrapInQuotes($terms), 'limit' => $limit ? "LIMIT($limit)": null, 'offset' => $offset ? "OFFSET($offset)": null, 'locale' => $locale ? "LANG($locale)": null, ]; parent::__construct($this->command, $this->parameters); } }
php
MIT
d7dd830c7512aedc31a9e34647a777566a9b893c
2026-01-05T05:07:38.798383Z
false
ppshobi/psonic
https://github.com/ppshobi/psonic/blob/d7dd830c7512aedc31a9e34647a777566a9b893c/src/Commands/Ingest/FlushObjectCommand.php
src/Commands/Ingest/FlushObjectCommand.php
<?php namespace Psonic\Commands\Ingest; use Psonic\Commands\Command; final class FlushObjectCommand extends Command { private $command = 'FLUSHO'; private $parameters = []; /** * Flushes the text from an object * FlushObjectCommand constructor. * @param string $collection * @param string $bucket * @param string $object */ public function __construct(string $collection, string $bucket, string $object) { $this->parameters = [ 'collection' => $collection, 'bucket' => $bucket, 'object' => $object, ]; parent::__construct($this->command, $this->parameters); } }
php
MIT
d7dd830c7512aedc31a9e34647a777566a9b893c
2026-01-05T05:07:38.798383Z
false
ppshobi/psonic
https://github.com/ppshobi/psonic/blob/d7dd830c7512aedc31a9e34647a777566a9b893c/src/Commands/Ingest/FlushCollectionCommand.php
src/Commands/Ingest/FlushCollectionCommand.php
<?php namespace Psonic\Commands\Ingest; use Psonic\Commands\Command; final class FlushCollectionCommand extends Command { private $command = 'FLUSHC'; private $parameters = []; /** * Flushes a given collection * FlushCollectionCommand constructor. * @param string $collection */ public function __construct(string $collection) { $this->parameters = [ 'collection' => $collection, ]; parent::__construct($this->command, $this->parameters); } }
php
MIT
d7dd830c7512aedc31a9e34647a777566a9b893c
2026-01-05T05:07:38.798383Z
false
ppshobi/psonic
https://github.com/ppshobi/psonic/blob/d7dd830c7512aedc31a9e34647a777566a9b893c/src/Commands/Ingest/FlushBucketCommand.php
src/Commands/Ingest/FlushBucketCommand.php
<?php namespace Psonic\Commands\Ingest; use Psonic\Commands\Command; final class FlushBucketCommand extends Command { private $command = 'FLUSHB'; private $parameters = []; /** * Flushes a given bucket in a collection * FlushBucketCommand constructor. * @param string $collection * @param string $bucket */ public function __construct(string $collection, string $bucket) { $this->parameters = [ 'collection' => $collection, 'bucket' => $bucket, ]; parent::__construct($this->command, $this->parameters); } }
php
MIT
d7dd830c7512aedc31a9e34647a777566a9b893c
2026-01-05T05:07:38.798383Z
false
ppshobi/psonic
https://github.com/ppshobi/psonic/blob/d7dd830c7512aedc31a9e34647a777566a9b893c/src/Commands/Ingest/CountCommand.php
src/Commands/Ingest/CountCommand.php
<?php namespace Psonic\Commands\Ingest; use Psonic\Commands\Command; final class CountCommand extends Command { private $command = 'COUNT'; private $parameters = []; /** * Counts the number of objects * CountCommand constructor. * @param string $collection * @param string|null $bucket * @param string|null $object */ public function __construct(string $collection, string $bucket = null, string $object = null) { $this->parameters = [ 'collection' => $collection, 'bucket' => $bucket, 'object' => $object, ]; parent::__construct($this->command, $this->parameters); } }
php
MIT
d7dd830c7512aedc31a9e34647a777566a9b893c
2026-01-05T05:07:38.798383Z
false
ppshobi/psonic
https://github.com/ppshobi/psonic/blob/d7dd830c7512aedc31a9e34647a777566a9b893c/src/Commands/Ingest/PushCommand.php
src/Commands/Ingest/PushCommand.php
<?php namespace Psonic\Commands\Ingest; use Psonic\Commands\Command; final class PushCommand extends Command { private $command = 'PUSH'; private $parameters = []; /** * Push a text/object into an object/bucket respectively * PushCommand constructor. * @param string $collection * @param string $bucket * @param string $object * @param string $text * @param string $locale - a Valid ISO 639-3 locale (eng = English), if set to `none` lexing will be disabled */ public function __construct(string $collection, string $bucket, string $object, string $text, string $locale=null) { $this->parameters = [ 'collection' => $collection, 'bucket' => $bucket, 'object' => $object, 'text' => self::wrapInQuotes($text), 'locale' => $locale ? "LANG($locale)": null, ]; parent::__construct($this->command, $this->parameters); } }
php
MIT
d7dd830c7512aedc31a9e34647a777566a9b893c
2026-01-05T05:07:38.798383Z
false
ppshobi/psonic
https://github.com/ppshobi/psonic/blob/d7dd830c7512aedc31a9e34647a777566a9b893c/src/Commands/Ingest/StartIngestChannelCommand.php
src/Commands/Ingest/StartIngestChannelCommand.php
<?php namespace Psonic\Commands\Ingest; use Psonic\Commands\Command; final class StartIngestChannelCommand extends Command { private $command = 'START'; private $parameters = []; /** * StartIngestChannelCommand constructor. * @param string $password */ public function __construct($password) { $this->parameters = [ 'mode' => 'ingest', 'password' => $password, ]; parent::__construct($this->command, $this->parameters); } }
php
MIT
d7dd830c7512aedc31a9e34647a777566a9b893c
2026-01-05T05:07:38.798383Z
false
ppshobi/psonic
https://github.com/ppshobi/psonic/blob/d7dd830c7512aedc31a9e34647a777566a9b893c/src/Commands/Ingest/PopCommand.php
src/Commands/Ingest/PopCommand.php
<?php namespace Psonic\Commands\Ingest; use Psonic\Commands\Command; final class PopCommand extends Command { private $command = 'POP'; private $parameters = []; /** * pops a text from a given object * PopCommand constructor. * @param string $collection * @param string $bucket * @param string $object * @param string $text */ public function __construct(string $collection, string $bucket, string $object, string $text) { $this->parameters = [ 'collection' => $collection, 'bucket' => $bucket, 'object' => $object, 'text' => self::wrapInQuotes($text), ]; parent::__construct($this->command, $this->parameters); } }
php
MIT
d7dd830c7512aedc31a9e34647a777566a9b893c
2026-01-05T05:07:38.798383Z
false
ppshobi/psonic
https://github.com/ppshobi/psonic/blob/d7dd830c7512aedc31a9e34647a777566a9b893c/src/Commands/Control/StartControlChannelCommand.php
src/Commands/Control/StartControlChannelCommand.php
<?php namespace Psonic\Commands\Control; use Psonic\Commands\Command; final class StartControlChannelCommand extends Command { private $command = 'START'; private $parameters = []; /** * StartControlChannelCommand constructor. * @param string $password */ public function __construct($password) { $this->parameters = [ 'mode' => 'control', 'password' => $password, ]; parent::__construct($this->command, $this->parameters); } }
php
MIT
d7dd830c7512aedc31a9e34647a777566a9b893c
2026-01-05T05:07:38.798383Z
false
ppshobi/psonic
https://github.com/ppshobi/psonic/blob/d7dd830c7512aedc31a9e34647a777566a9b893c/src/Commands/Control/TriggerCommand.php
src/Commands/Control/TriggerCommand.php
<?php namespace Psonic\Commands\Control; use Psonic\Commands\Command; final class TriggerCommand extends Command { private $command = 'TRIGGER'; private $parameters = []; /** * TriggerCommand constructor. * @param string $action */ public function __construct(string $action) { $this->parameters = [ 'action' => $action, ]; parent::__construct($this->command, $this->parameters); } }
php
MIT
d7dd830c7512aedc31a9e34647a777566a9b893c
2026-01-05T05:07:38.798383Z
false
ppshobi/psonic
https://github.com/ppshobi/psonic/blob/d7dd830c7512aedc31a9e34647a777566a9b893c/src/Commands/Control/InfoCommand.php
src/Commands/Control/InfoCommand.php
<?php namespace Psonic\Commands\Control; use Psonic\Commands\Command; final class InfoCommand extends Command { private $command = 'INFO'; private $parameters = []; /** * Info Command constructor. */ public function __construct() { parent::__construct($this->command, $this->parameters); } }
php
MIT
d7dd830c7512aedc31a9e34647a777566a9b893c
2026-01-05T05:07:38.798383Z
false
ppshobi/psonic
https://github.com/ppshobi/psonic/blob/d7dd830c7512aedc31a9e34647a777566a9b893c/tests/TestCase.php
tests/TestCase.php
<?php namespace Tests; class TestCase extends \PHPUnit\Framework\TestCase { protected $collection; protected $bucket; public function __construct() { parent::__construct(); $this->collection = 'basecollection'; $this->bucket = 'basebucket'; $this->password = 'SecretPassword1'; } }
php
MIT
d7dd830c7512aedc31a9e34647a777566a9b893c
2026-01-05T05:07:38.798383Z
false
ppshobi/psonic
https://github.com/ppshobi/psonic/blob/d7dd830c7512aedc31a9e34647a777566a9b893c/tests/bootstrap.php
tests/bootstrap.php
<?php /** * Author: ppshobi@gmail.com * */ require_once ('vendor/autoload.php');
php
MIT
d7dd830c7512aedc31a9e34647a777566a9b893c
2026-01-05T05:07:38.798383Z
false
ppshobi/psonic
https://github.com/ppshobi/psonic/blob/d7dd830c7512aedc31a9e34647a777566a9b893c/tests/Unit/ControlChannelTest.php
tests/Unit/ControlChannelTest.php
<?php /** * Author: ppshobi@gmail.com * */ namespace Tests\Unit; use Psonic\Control; use Psonic\Client; use Tests\TestCase; class ControlChannelTest extends TestCase { public function setUp(): void { $this->control = new Control(new Client()); } /** * @test * @group connected */ public function it_can_trigger_consolidation() { $this->control->connect($this->password); $this->assertEquals("OK", $this->control->consolidate()); } /** * @test * **/ public function it_can_fetch_information_about_the_server() { $this->control->connect($this->password); $this->assertEquals(0, $this->control->info()->getCount()); } }
php
MIT
d7dd830c7512aedc31a9e34647a777566a9b893c
2026-01-05T05:07:38.798383Z
false
ppshobi/psonic
https://github.com/ppshobi/psonic/blob/d7dd830c7512aedc31a9e34647a777566a9b893c/tests/Unit/ClientTest.php
tests/Unit/ClientTest.php
<?php /** * Author: ppshobi@gmail.com * */ namespace Tests\Unit; use Psonic\Client; use Psonic\Commands\Misc\PingCommand; use Psonic\Contracts\Command; use Psonic\Contracts\Response; use Psonic\Exceptions\ConnectionException; use Tests\TestCase; class ClientTest extends TestCase { public function setUp(): void { $this->client = new Client(); } /** * @test * @group connected */ public function the_client_can_connect_to_socket() { $this->client->connect(); $this->assertEquals("CONNECTED", $this->client->read()->getStatus()); } /** * @test * @group connected */ public function the_client_can_disconnect_from_socket_and_throws_exception_if_connection_is_not_present() { $this->client->connect(); $this->client->disconnect(); $this->expectException(ConnectionException::class); $this->client->send(new PingCommand); } /** * @test * @group connected */ public function the_client_can_send_command_and_read_its_response() { $this->client->connect(); $response = $this->client->read(); $this->assertEquals("CONNECTED", $response->getStatus()); } /** * @test * @group connected */ public function the_client_can_clear_the_output_buffer() { $this->client->connect(); $this->assertTrue($this->client->clearBuffer()); } /** * @test * @group connected */ public function the_client_can_send_a_command_to_sonic_and_returns_a_response_object() { $this->client->connect(); $this->client->clearBuffer(); $this->assertInstanceOf(Response::class, $this->client->send(new PingCommand)); } }
php
MIT
d7dd830c7512aedc31a9e34647a777566a9b893c
2026-01-05T05:07:38.798383Z
false
ppshobi/psonic
https://github.com/ppshobi/psonic/blob/d7dd830c7512aedc31a9e34647a777566a9b893c/tests/Unit/SearchChannelTest.php
tests/Unit/SearchChannelTest.php
<?php /** * Author: ppshobi@gmail.com * */ namespace Tests\Unit; use Psonic\Control; use Psonic\Ingest; use Psonic\Search; use Psonic\Client; use Tests\TestCase; class SearchChannelTest extends TestCase { public function setUp(): void { $this->search = new Search(new Client()); $this->ingest = new Ingest(new Client()); $this->control = new Control(new Client()); } /** * @test * @group connected */ public function it_can_query_sonic_protocol_and_return_matched_records() { $this->ingest->connect($this->password); $this->search->connect($this->password); $this->control->connect($this->password); $this->ingest->flushc($this->collection); $this->assertEquals("OK", $this->ingest->push($this->collection, $this->bucket, "1234", "hi Shobi how are you?")->getStatus()); $this->assertEquals("OK", $this->ingest->push($this->collection, $this->bucket, "1235", "hi are you fine ?")->getStatus()); $this->assertEquals("OK", $this->ingest->push($this->collection, $this->bucket, "3456", "Jomit? How are you?")->getStatus()); $this->control->consolidate(); $this->assertTrue(is_array($this->search->query($this->collection, $this->bucket, "are"))); } /** * @test * @group connected */ public function it_can_apply_limit_on_returned_records_for_a_query() { $this->ingest->connect($this->password); $this->search->connect($this->password); $this->control->connect($this->password); $this->ingest->flushc($this->collection); $this->assertEquals("OK", $this->ingest->push($this->collection, $this->bucket, "1234", "hi Shobi how are you?")->getStatus()); $this->assertEquals("OK", $this->ingest->push($this->collection, $this->bucket, "1235", "hi are you fine ?")->getStatus()); $this->assertEquals("OK", $this->ingest->push($this->collection, $this->bucket, "3456", "Jomit? How are you?")->getStatus()); $this->control->consolidate(); $this->assertCount(2, $this->search->query($this->collection, $this->bucket, "are", 2)); $this->assertCount(1, $this->search->query($this->collection, $this->bucket, "are", 1)); } /** * @test * @group connected */ public function it_can_apply_limit_and_offset_on_returned_records_for_a_query() { $this->ingest->connect($this->password); $this->search->connect($this->password); $this->control->connect($this->password); $this->ingest->flushc($this->collection); $this->assertEquals("OK", $this->ingest->push($this->collection, $this->bucket, "1234", "hi how are you")->getStatus()); $this->assertEquals("OK", $this->ingest->push($this->collection, $this->bucket, "1235", "hi are you fine ?")->getStatus()); $this->assertEquals("OK", $this->ingest->push($this->collection, $this->bucket, "3456", "Jomit? How are you?")->getStatus()); $this->assertEquals("OK", $this->ingest->push($this->collection, $this->bucket, "4567", "Annie, are you ok?")->getStatus()); $this->assertEquals("OK", $this->ingest->push($this->collection, $this->bucket, "5678", "So Annie are you ok")->getStatus()); $this->assertEquals("OK", $this->ingest->push($this->collection, $this->bucket, "6789", "are you ok, Annie")->getStatus()); $this->control->consolidate(); $responses = $this->search->query($this->collection, $this->bucket, "are you", 10); $this->assertCount(6, $responses); $responses = $this->search->query($this->collection, $this->bucket, "are", 2, 3); $this->assertCount(2, $responses); } /** * @test * @group connected */ public function it_can_apply_limit_on_returned_records_for_a_suggest_command() { $this->ingest->connect($this->password); $this->search->connect($this->password); $this->control->connect($this->password); $this->ingest->flushc($this->collection); $this->assertEquals("OK", $this->ingest->push($this->collection, $this->bucket, "1234", "coincident")->getStatus()); $this->assertEquals("OK", $this->ingest->push($this->collection, $this->bucket, "1235", "coincidental")->getStatus()); $this->assertEquals("OK", $this->ingest->push($this->collection, $this->bucket, "3456", "coinciding")->getStatus()); $this->control->consolidate(); $this->assertCount(3, $this->search->suggest($this->collection, $this->bucket, "coin")); $this->assertCount(2, $this->search->suggest($this->collection, $this->bucket, "coin", 2)); $this->assertCount(1, $this->search->suggest($this->collection, $this->bucket, "coin", 1)); } /** * @test * @group connected */ public function it_can_query_sonic_protocol_and_return_suggestions() { $this->ingest->connect($this->password); $this->search->connect($this->password); $this->control->connect($this->password); $this->ingest->flushc($this->collection); $this->assertEquals("OK", $this->ingest->push($this->collection, $this->bucket, "1234", "hi Shobi how are you?")->getStatus()); $this->assertEquals("OK", $this->ingest->push($this->collection, $this->bucket, "1235", "hi are you fine ?")->getStatus()); $this->assertEquals("OK", $this->ingest->push($this->collection, $this->bucket, "3456", "Jomit? How are you?")->getStatus()); $this->control->consolidate(); $results = $this->search->suggest($this->collection, $this->bucket, "sho"); $this->assertTrue(is_array($results)); $this->assertContains("shobi", $results); } // @todo /** * Implement tests for locale based query and suggest commands */ }
php
MIT
d7dd830c7512aedc31a9e34647a777566a9b893c
2026-01-05T05:07:38.798383Z
false
ppshobi/psonic
https://github.com/ppshobi/psonic/blob/d7dd830c7512aedc31a9e34647a777566a9b893c/tests/Unit/ChannelTest.php
tests/Unit/ChannelTest.php
<?php /** * Author: ppshobi@gmail.com * */ namespace Tests\Unit; use Psonic\Control; use Psonic\Ingest; use Psonic\Search; use Psonic\Client; use Psonic\Commands\Misc\PingCommand; use Psonic\Contracts\Response; use Tests\TestCase; class ChannelTest extends TestCase { public function setUp(): void { $this->search = new Search(new Client()); $this->ingest = new Ingest(new Client()); $this->control = new Control(new Client()); } /** * @test * @group connected **/ public function channels_can_connect_to_sonic_channel_protocol() { $this->assertEquals("STARTED", $this->search->connect($this->password)->getStatus()); $this->assertEquals("STARTED", $this->ingest->connect($this->password)->getStatus()); $this->assertEquals("STARTED", $this->control->connect($this->password)->getStatus()); } /** * @test * @group connected **/ public function channels_can_send_a_command_and_returns_a_response() { $this->connect_all_channels(); $searchResponse = $this->search->send(new PingCommand); $ingestResponse = $this->ingest->send(new PingCommand); $controlResponse = $this->control->send(new PingCommand); $this->assertInstanceOf(Response::class, $searchResponse); $this->assertInstanceOf(Response::class, $ingestResponse); $this->assertInstanceOf(Response::class, $controlResponse); $this->assertEquals("PONG", $searchResponse); $this->assertEquals("PONG", $ingestResponse); $this->assertEquals("PONG", $controlResponse); } /** * @test * @group connected */ public function channels_can_disconnect_from_sonic_protocol() { $this->connect_all_channels(); $searchResponse = $this->search->disconnect(); $ingestResponse = $this->ingest->disconnect(); $controlResponse = $this->control->disconnect(); $this->assertEquals("ENDED", $searchResponse->getStatus()); $this->assertEquals("ENDED", $ingestResponse->getStatus()); $this->assertEquals("ENDED", $controlResponse->getStatus()); } private function connect_all_channels() { $this->search->connect('SecretPassword1'); $this->ingest->connect('SecretPassword1'); $this->control->connect('SecretPassword1'); } }
php
MIT
d7dd830c7512aedc31a9e34647a777566a9b893c
2026-01-05T05:07:38.798383Z
false
ppshobi/psonic
https://github.com/ppshobi/psonic/blob/d7dd830c7512aedc31a9e34647a777566a9b893c/tests/Unit/IngestChannelTest.php
tests/Unit/IngestChannelTest.php
<?php /** * Author: ppshobi@gmail.com * */ namespace Tests\Unit; use Psonic\Control; use Psonic\Ingest; use Psonic\Client; use Tests\TestCase; class IngestChannelTest extends TestCase { public function setUp(): void { $this->ingest = new Ingest(new Client()); $this->control = new Control(new Client()); } /** * @test * @group connected **/ public function it_can_push_items_to_the_index() { $this->ingest->connect($this->password); $this->assertEquals("OK", $this->ingest->push($this->collection, $this->bucket, "1234", "hi Shobi how are you")->getStatus()); $this->assertEquals("OK", $this->ingest->push($this->collection, $this->bucket, "4567", "hi Naveen")->getStatus()); $this->assertEquals("OK", $this->ingest->push($this->collection, $this->bucket, "7890", "hi Jomit")->getStatus()); $this->assertEquals("OK", $this->ingest->push($this->collection, $this->bucket, "1122", 'hi "quoted" text')->getStatus()); $this->assertEquals("OK", $this->ingest->push($this->collection, $this->bucket, "1133", "Newlines\nshould\nbe\nnormalized\nto\nspaces")->getStatus()); } /** * @test * @group connected **/ public function it_can_push_huge_items_to_the_index() { $this->ingest->connect($this->password); $this->assertEquals("OK", $this->ingest->push($this->collection, $this->bucket, "1234", bin2hex(openssl_random_pseudo_bytes(30000)))->getStatus()); } /** * @test * @group connected **/ public function it_can_pop_items_from_index() { $this->ingest->connect($this->password); $this->control->connect($this->password); $this->ingest->flushc($this->collection); $this->assertEquals(0, $this->ingest->count($this->collection, $this->bucket)); $this->assertEquals("OK", $this->ingest->push($this->collection, $this->bucket, "1234", "hi Shobi how are you")->getStatus()); $this->control->consolidate(); $this->assertEquals(1, $this->ingest->count($this->collection, $this->bucket)); $this->assertEquals(1, $this->ingest->pop($this->collection, $this->bucket, "1234", "hi Shobi how are you")); $this->control->consolidate(); $this->assertEquals(0, $this->ingest->count($this->collection, $this->bucket, "1234")); } /** * @test * @group connected **/ public function it_can_count_the_objects() { $this->ingest->connect($this->password); $this->control->connect($this->password); $this->ingest->flushc($this->collection); $this->control->consolidate(); $this->assertEquals(0, $this->ingest->count($this->collection)); $this->assertEquals(0, $this->ingest->count($this->collection, $this->bucket)); $this->assertEquals("OK", $this->ingest->push($this->collection, $this->bucket, "1234", "hi Shobi how are you?")->getStatus()); $this->assertEquals("OK", $this->ingest->push($this->collection, $this->bucket, "1235", "hi Naveen how are you?")->getStatus()); $this->assertEquals("OK", $this->ingest->push($this->collection, $this->bucket, "3456", "Hi Jomit How are you?")->getStatus()); $this->control->consolidate(); $this->assertEquals(3, $this->ingest->count($this->collection, $this->bucket)); } /** * @test * @group connected **/ public function it_can_flush_a_collection() { $this->ingest->connect($this->password); $this->ingest->flushc($this->collection); $this->assertEquals("OK", $this->ingest->push($this->collection, $this->bucket, "1234", "hi Shobi how are you?")->getStatus()); $this->assertEquals(1, $this->ingest->flushc($this->collection)); } /** * @test * @group connected **/ public function it_can_flush_a_bucket() { $this->ingest->connect($this->password); $this->ingest->flushc($this->collection); $this->assertEquals("OK", $this->ingest->push($this->collection, $this->bucket, "123", "hi Shobi how are you?")->getStatus()); $this->assertEquals(1, $this->ingest->flushb($this->collection, $this->bucket)); } /** * @test * @group connected **/ public function it_can_flush_an_object() { $this->ingest->connect($this->password); $this->ingest->flushc($this->collection); $this->assertEquals("OK", $this->ingest->push($this->collection, $this->bucket, "1234", "hi Shobi how are you?")->getStatus()); $this->assertEquals(1, $this->ingest->flusho($this->collection, $this->bucket, "1234")); } // @todo /** * Implement tests for locale based ingestion */ }
php
MIT
d7dd830c7512aedc31a9e34647a777566a9b893c
2026-01-05T05:07:38.798383Z
false
claudiodekker/inertia-laravel-testing
https://github.com/claudiodekker/inertia-laravel-testing/blob/1e4f320bd85146c5e85cd189126d46a21ec470ef/_ide_helpers.php
_ide_helpers.php
<?php /** @noinspection PhpUndefinedClassInspection */ /** @noinspection PhpFullyQualifiedNameUsageInspection */ /** @noinspection PhpUnusedAliasInspection */ namespace Illuminate\Testing { /** * @see \ClaudioDekker\Inertia\TestResponseMacros * * @method self assertInertia(\Closure $assert = null) */ class TestResponse { // } } namespace Illuminate\Foundation\Testing { /** * @see \ClaudioDekker\Inertia\TestResponseMacros * * @method self assertInertia(\Closure $assert = null) */ class TestResponse { // } }
php
MIT
1e4f320bd85146c5e85cd189126d46a21ec470ef
2026-01-05T05:07:58.862099Z
false
claudiodekker/inertia-laravel-testing
https://github.com/claudiodekker/inertia-laravel-testing/blob/1e4f320bd85146c5e85cd189126d46a21ec470ef/src/TestResponseMacros.php
src/TestResponseMacros.php
<?php namespace ClaudioDekker\Inertia; use Closure; class TestResponseMacros { public function assertInertia() { return function (Closure $callback = null) { $assert = Assert::fromTestResponse($this); if (is_null($callback)) { return $this; } $callback($assert); if (config('inertia.force_top_level_property_interaction', true)) { $assert->interacted(); } return $this; }; } public function inertiaPage() { return function () { return Assert::fromTestResponse($this)->toArray(); }; } }
php
MIT
1e4f320bd85146c5e85cd189126d46a21ec470ef
2026-01-05T05:07:58.862099Z
false
claudiodekker/inertia-laravel-testing
https://github.com/claudiodekker/inertia-laravel-testing/blob/1e4f320bd85146c5e85cd189126d46a21ec470ef/src/Assert.php
src/Assert.php
<?php namespace ClaudioDekker\Inertia; use Closure; use Illuminate\Contracts\Support\Arrayable; use Illuminate\Support\Traits\Macroable; use PHPUnit\Framework\Assert as PHPUnit; use PHPUnit\Framework\AssertionFailedError; class Assert implements Arrayable { use Concerns\Has, Concerns\Matching, Concerns\Debugging, Concerns\PageObject, Concerns\Interaction, Macroable; /** @var string */ private $component; /** @var array */ private $props; /** @var string */ private $url; /** @var mixed|null */ private $version; /** @var string */ private $path; protected function __construct(string $component, array $props, string $url, $version = null, string $path = null) { $this->path = $path; $this->component = $component; $this->props = $props; $this->url = $url; $this->version = $version; } protected function dotPath($key): string { if (is_null($this->path)) { return $key; } return implode('.', [$this->path, $key]); } protected function scope($key, Closure $callback): self { $props = $this->prop($key); $path = $this->dotPath($key); PHPUnit::assertIsArray($props, sprintf('Inertia property [%s] is not scopeable.', $path)); $scope = new self($this->component, $props, $this->url, $this->version, $path); $callback($scope); $scope->interacted(); return $this; } public static function fromTestResponse($response): self { try { $response->assertViewHas('page'); $page = json_decode(json_encode($response->viewData('page')), true); PHPUnit::assertIsArray($page); PHPUnit::assertArrayHasKey('component', $page); PHPUnit::assertArrayHasKey('props', $page); PHPUnit::assertArrayHasKey('url', $page); PHPUnit::assertArrayHasKey('version', $page); } catch (AssertionFailedError $e) { PHPUnit::fail('Not a valid Inertia response.'); } return new self($page['component'], $page['props'], $page['url'], $page['version']); } }
php
MIT
1e4f320bd85146c5e85cd189126d46a21ec470ef
2026-01-05T05:07:58.862099Z
false
claudiodekker/inertia-laravel-testing
https://github.com/claudiodekker/inertia-laravel-testing/blob/1e4f320bd85146c5e85cd189126d46a21ec470ef/src/InertiaTestingServiceProvider.php
src/InertiaTestingServiceProvider.php
<?php namespace ClaudioDekker\Inertia; use Illuminate\Foundation\Testing\TestResponse as LegacyTestResponse; use Illuminate\Support\Facades\App; use Illuminate\Support\ServiceProvider; use Illuminate\Testing\TestResponse; use Illuminate\View\FileViewFinder; use Inertia\Assert as InertiaAssertions; use LogicException; class InertiaTestingServiceProvider extends ServiceProvider { public function boot() { // When the installed Inertia adapter has our assertions bundled, // we'll skip registering and/or booting this package. if (class_exists(InertiaAssertions::class)) { return; } if (App::runningUnitTests()) { $this->registerTestingMacros(); } $this->publishes([ __DIR__.'/../config/inertia.php' => config_path('inertia.php'), ]); } public function register() { // When the installed Inertia adapter has our assertions bundled, // we'll skip registering and/or booting this package. if (class_exists(InertiaAssertions::class)) { return; } $this->mergeConfigFrom( __DIR__.'/../config/inertia.php', 'inertia' ); $this->app->bind('inertia.view.finder', function ($app) { return new FileViewFinder( $app['files'], $app['config']->get('inertia.page.paths'), $app['config']->get('inertia.page.extensions') ); }); } protected function registerTestingMacros() { // Laravel >= 7.0 if (class_exists(TestResponse::class)) { TestResponse::mixin(new TestResponseMacros()); return; } // Laravel <= 6.0 if (class_exists(LegacyTestResponse::class)) { LegacyTestResponse::mixin(new TestResponseMacros()); return; } throw new LogicException('Could not detect TestResponse class.'); } }
php
MIT
1e4f320bd85146c5e85cd189126d46a21ec470ef
2026-01-05T05:07:58.862099Z
false
claudiodekker/inertia-laravel-testing
https://github.com/claudiodekker/inertia-laravel-testing/blob/1e4f320bd85146c5e85cd189126d46a21ec470ef/src/Concerns/Interaction.php
src/Concerns/Interaction.php
<?php namespace ClaudioDekker\Inertia\Concerns; use Illuminate\Support\Str; use PHPUnit\Framework\Assert as PHPUnit; trait Interaction { /** @var array */ protected $interacted = []; protected function interactsWith(string $key): void { $prop = Str::before($key, '.'); if (! in_array($prop, $this->interacted, true)) { $this->interacted[] = $prop; } } public function interacted(): void { PHPUnit::assertSame( [], array_diff(array_keys($this->prop()), $this->interacted), $this->path ? sprintf('Unexpected Inertia properties were found in scope [%s].', $this->path) : 'Unexpected Inertia properties were found on the root level.' ); } public function etc(): self { $this->interacted = array_keys($this->prop()); return $this; } abstract protected function prop(string $key = null); }
php
MIT
1e4f320bd85146c5e85cd189126d46a21ec470ef
2026-01-05T05:07:58.862099Z
false
claudiodekker/inertia-laravel-testing
https://github.com/claudiodekker/inertia-laravel-testing/blob/1e4f320bd85146c5e85cd189126d46a21ec470ef/src/Concerns/Has.php
src/Concerns/Has.php
<?php namespace ClaudioDekker\Inertia\Concerns; use Closure; use Illuminate\Support\Arr; use Illuminate\Support\Collection; use PHPUnit\Framework\Assert as PHPUnit; trait Has { protected function count(string $key, $length): self { PHPUnit::assertCount( $length, $this->prop($key), sprintf('Inertia property [%s] does not have the expected size.', $this->dotPath($key)) ); return $this; } public function hasAll($key): self { $keys = is_array($key) ? $key : func_get_args(); foreach ($keys as $prop => $count) { if (is_int($prop)) { $this->has($count); } else { $this->has($prop, $count); } } return $this; } public function has(string $key, $value = null, Closure $scope = null): self { PHPUnit::assertTrue( Arr::has($this->prop(), $key), sprintf('Inertia property [%s] does not exist.', $this->dotPath($key)) ); $this->interactsWith($key); if (is_int($value) && ! is_null($scope)) { $path = $this->dotPath($key); $prop = $this->prop($key); if ($prop instanceof Collection) { $prop = $prop->all(); } PHPUnit::assertTrue($value > 0, sprintf('Cannot scope directly onto the first entry of property [%s] when asserting that it has a size of 0.', $path)); PHPUnit::assertIsArray($prop, sprintf('Direct scoping is currently unsupported for non-array like properties such as [%s].', $path)); $this->count($key, $value); return $this->scope($key.'.'.array_keys($prop)[0], $scope); } if (is_callable($value)) { $this->scope($key, $value); } elseif (! is_null($value)) { $this->count($key, $value); } return $this; } public function missingAll($key): self { $keys = is_array($key) ? $key : func_get_args(); foreach ($keys as $prop) { $this->misses($prop); } return $this; } public function missing(string $key): self { $this->interactsWith($key); PHPUnit::assertNotTrue( Arr::has($this->prop(), $key), sprintf('Inertia property [%s] was found while it was expected to be missing.', $this->dotPath($key)) ); return $this; } public function missesAll($key): self { return $this->missingAll( is_array($key) ? $key : func_get_args() ); } public function misses(string $key): self { return $this->missing($key); } abstract protected function prop(string $key = null); abstract protected function dotPath($key): string; abstract protected function interactsWith(string $key): void; abstract protected function scope($key, Closure $callback); }
php
MIT
1e4f320bd85146c5e85cd189126d46a21ec470ef
2026-01-05T05:07:58.862099Z
false
claudiodekker/inertia-laravel-testing
https://github.com/claudiodekker/inertia-laravel-testing/blob/1e4f320bd85146c5e85cd189126d46a21ec470ef/src/Concerns/Debugging.php
src/Concerns/Debugging.php
<?php namespace ClaudioDekker\Inertia\Concerns; trait Debugging { public function dump(string $prop = null): self { dump($this->prop($prop)); return $this; } public function dd(string $prop = null): void { dd($this->prop($prop)); } abstract protected function prop(string $key = null); }
php
MIT
1e4f320bd85146c5e85cd189126d46a21ec470ef
2026-01-05T05:07:58.862099Z
false
claudiodekker/inertia-laravel-testing
https://github.com/claudiodekker/inertia-laravel-testing/blob/1e4f320bd85146c5e85cd189126d46a21ec470ef/src/Concerns/PageObject.php
src/Concerns/PageObject.php
<?php namespace ClaudioDekker\Inertia\Concerns; use Illuminate\Support\Arr; use InvalidArgumentException; use PHPUnit\Framework\Assert as PHPUnit; trait PageObject { public function component(string $value = null, $shouldExist = null): self { PHPUnit::assertSame($value, $this->component, 'Unexpected Inertia page component.'); if ($shouldExist || (is_null($shouldExist) && config('inertia.page.should_exist', true))) { try { app('inertia.view.finder')->find($value); } catch (InvalidArgumentException $exception) { PHPUnit::fail(sprintf('Inertia page component file [%s] does not exist.', $value)); } } return $this; } protected function prop(string $key = null) { return Arr::get($this->props, $key); } public function url(string $value): self { PHPUnit::assertSame($value, $this->url, 'Unexpected Inertia page url.'); return $this; } public function version($value): self { PHPUnit::assertSame($value, $this->version, 'Unexpected Inertia asset version.'); return $this; } public function toArray(): array { return [ 'component' => $this->component, 'props' => $this->props, 'url' => $this->url, 'version' => $this->version, ]; } }
php
MIT
1e4f320bd85146c5e85cd189126d46a21ec470ef
2026-01-05T05:07:58.862099Z
false
claudiodekker/inertia-laravel-testing
https://github.com/claudiodekker/inertia-laravel-testing/blob/1e4f320bd85146c5e85cd189126d46a21ec470ef/src/Concerns/Matching.php
src/Concerns/Matching.php
<?php namespace ClaudioDekker\Inertia\Concerns; use Closure; use Illuminate\Contracts\Support\Arrayable; use Illuminate\Contracts\Support\Responsable; use Illuminate\Support\Collection; use PHPUnit\Framework\Assert as PHPUnit; trait Matching { public function whereAll(array $bindings): self { foreach ($bindings as $key => $value) { $this->where($key, $value); } return $this; } public function where($key, $expected): self { $this->has($key); $actual = $this->prop($key); if ($expected instanceof Closure) { PHPUnit::assertTrue( $expected(is_array($actual) ? Collection::make($actual) : $actual), sprintf('Inertia property [%s] was marked as invalid using a closure.', $this->dotPath($key)) ); return $this; } if ($expected instanceof Arrayable) { $expected = $expected->toArray(); } elseif ($expected instanceof Responsable) { $expected = json_decode(json_encode($expected->toResponse(request())->getData()), true); } $this->ensureSorted($expected); $this->ensureSorted($actual); PHPUnit::assertSame( $expected, $actual, sprintf('Inertia property [%s] does not match the expected value.', $this->dotPath($key)) ); return $this; } protected function ensureSorted(&$value): void { if (! is_array($value)) { return; } foreach ($value as &$arg) { $this->ensureSorted($arg); } ksort($value); } abstract protected function dotPath($key): string; abstract protected function prop(string $key = null); abstract public function has(string $key, $value = null, Closure $scope = null); }
php
MIT
1e4f320bd85146c5e85cd189126d46a21ec470ef
2026-01-05T05:07:58.862099Z
false
claudiodekker/inertia-laravel-testing
https://github.com/claudiodekker/inertia-laravel-testing/blob/1e4f320bd85146c5e85cd189126d46a21ec470ef/tests/TestCase.php
tests/TestCase.php
<?php namespace ClaudioDekker\Inertia\Tests; use ClaudioDekker\Inertia\InertiaTestingServiceProvider; use Illuminate\Foundation\Testing\TestResponse as LegacyTestResponse; use Illuminate\Testing\TestResponse; use Inertia\Inertia; use LogicException; use Orchestra\Testbench\TestCase as Orchestra; class TestCase extends Orchestra { protected function setUp(): void { parent::setUp(); Inertia::setRootView('welcome'); config()->set('inertia.page.should_exist', false); config()->set('inertia.page.paths', [realpath(__DIR__)]); } /** * @param \Illuminate\Foundation\Application $app * @return array */ protected function getPackageProviders($app) { return [ InertiaTestingServiceProvider::class, ]; } /** * @return string * @throws LogicException */ protected function getTestResponseClass(): string { // Laravel >= 7.0 if (class_exists(TestResponse::class)) { return TestResponse::class; } // Laravel <= 6.0 if (class_exists(LegacyTestResponse::class)) { return LegacyTestResponse::class; } throw new LogicException('Could not detect TestResponse class.'); } protected function makeMockRequest($view) { app('router')->get('/example-url', function () use ($view) { return $view; }); return $this->get('/example-url'); } }
php
MIT
1e4f320bd85146c5e85cd189126d46a21ec470ef
2026-01-05T05:07:58.862099Z
false
claudiodekker/inertia-laravel-testing
https://github.com/claudiodekker/inertia-laravel-testing/blob/1e4f320bd85146c5e85cd189126d46a21ec470ef/tests/Unit/AssertTest.php
tests/Unit/AssertTest.php
<?php namespace ClaudioDekker\Inertia\Tests\Unit; use ClaudioDekker\Inertia\Assert; use ClaudioDekker\Inertia\Tests\TestCase; use Exception; use Illuminate\Database\Eloquent\Model; use Illuminate\Foundation\Auth\User; use Illuminate\Http\Resources\Json\JsonResource; use Illuminate\Support\Collection; use Inertia\Inertia; use PHPUnit\Framework\AssertionFailedError; use TypeError; class AssertTest extends TestCase { /** @test */ public function the_view_is_served_by_inertia(): void { $response = $this->makeMockRequest( Inertia::render('foo') ); $response->assertInertia(); } /** @test */ public function the_view_is_not_served_by_inertia(): void { $response = $this->makeMockRequest(view('welcome')); $response->assertOk(); // Make sure we can render the built-in Orchestra 'welcome' view.. $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage('Not a valid Inertia response.'); $response->assertInertia(); } /** @test */ public function the_component_matches(): void { $response = $this->makeMockRequest( Inertia::render('foo') ); $response->assertInertia(function (Assert $inertia) { $inertia->component('foo'); }); } /** @test */ public function the_component_does_not_match(): void { $response = $this->makeMockRequest( Inertia::render('foo') ); $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage('Unexpected Inertia page component.'); $response->assertInertia(function (Assert $inertia) { $inertia->component('bar'); }); } /** @test */ public function the_component_exists_on_the_filesystem(): void { $response = $this->makeMockRequest( Inertia::render('fixtures/ExamplePage') ); config()->set('inertia.page.should_exist', true); $response->assertInertia(function (Assert $inertia) { $inertia->component('fixtures/ExamplePage'); }); } /** @test */ public function the_component_does_not_exist_on_the_filesystem(): void { $response = $this->makeMockRequest( Inertia::render('foo') ); config()->set('inertia.page.should_exist', true); $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage('Inertia page component file [foo] does not exist.'); $response->assertInertia(function (Assert $inertia) { $inertia->component('foo'); }); } /** @test */ public function it_can_force_enable_the_component_file_existence(): void { $response = $this->makeMockRequest( Inertia::render('foo') ); config()->set('inertia.page.should_exist', false); $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage('Inertia page component file [foo] does not exist.'); $response->assertInertia(function (Assert $inertia) { $inertia->component('foo', true); }); } /** @test */ public function it_can_force_disable_the_component_file_existence_check(): void { $response = $this->makeMockRequest( Inertia::render('foo') ); config()->set('inertia.page.should_exist', true); $response->assertInertia(function (Assert $inertia) { $inertia->component('foo', false); }); } /** @test */ public function the_component_does_not_exist_on_the_filesystem_when_it_does_not_exist_relative_to_any_of_the_given_paths(): void { $response = $this->makeMockRequest( Inertia::render('fixtures/ExamplePage') ); config()->set('inertia.page.should_exist', true); config()->set('inertia.page.paths', [realpath(__DIR__)]); $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage('Inertia page component file [fixtures/ExamplePage] does not exist.'); $response->assertInertia(function (Assert $inertia) { $inertia->component('fixtures/ExamplePage'); }); } /** @test */ public function the_component_does_not_exist_on_the_filesystem_when_it_does_not_have_one_of_the_configured_extensions(): void { $response = $this->makeMockRequest( Inertia::render('fixtures/ExamplePage') ); config()->set('inertia.page.should_exist', true); config()->set('inertia.page.extensions', ['bin', 'exe', 'svg']); $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage('Inertia page component file [fixtures/ExamplePage] does not exist.'); $response->assertInertia(function (Assert $inertia) { $inertia->component('fixtures/ExamplePage'); }); } /** @test */ public function it_has_a_prop(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'prop' => 'value', ]) ); $response->assertInertia(function (Assert $inertia) { $inertia->has('prop'); }); } /** @test */ public function it_does_not_have_a_prop(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'bar' => 'value', ]) ); $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage('Inertia property [prop] does not exist.'); $response->assertInertia(function (Assert $inertia) { $inertia->has('prop'); }); } /** @test */ public function it_has_a_nested_prop(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'example' => [ 'nested' => 'nested-value', ], ]) ); $response->assertInertia(function (Assert $inertia) { $inertia->has('example.nested'); }); } /** @test */ public function it_does_not_have_a_nested_prop(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'example' => [ 'nested' => 'nested-value', ], ]) ); $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage('Inertia property [example.another] does not exist.'); $response->assertInertia(function (Assert $inertia) { $inertia->has('example.another'); }); } /** @test */ public function it_can_count_the_amount_of_items_in_a_given_prop(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'bar' => [ 'baz' => 'example', 'prop' => 'value', ], ]) ); $response->assertInertia(function (Assert $inertia) { $inertia->has('bar', 2); }); } /** @test */ public function it_fails_counting_when_the_amount_of_items_in_a_given_prop_does_not_match(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'bar' => [ 'baz' => 'example', 'prop' => 'value', ], ]) ); $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage('Inertia property [bar] does not have the expected size.'); $response->assertInertia(function (Assert $inertia) { $inertia->has('bar', 1); }); } /** @test */ public function it_cannot_count_the_amount_of_items_in_a_given_prop_when_the_prop_does_not_exist(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'bar' => [ 'baz' => 'example', 'prop' => 'value', ], ]) ); $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage('Inertia property [baz] does not exist.'); $response->assertInertia(function (Assert $inertia) { $inertia->has('baz', 2); }); } /** @test */ public function it_fails_when_the_second_argument_of_the_has_assertion_is_an_unsupported_type(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'bar' => 'baz', ]) ); $this->expectException(TypeError::class); $response->assertInertia(function (Assert $inertia) { $inertia->has('bar', 'invalid'); }); } /** @test */ public function it_asserts_that_a_prop_is_missing(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'foo' => [ 'bar' => true, ], ]) ); $response->assertInertia(function (Assert $inertia) { $inertia->missing('foo.baz'); }); } /** @test */ public function it_asserts_that_a_prop_is_missing_using_the_misses_method(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'foo' => [ 'bar' => true, ], ]) ); $response->assertInertia(function (Assert $inertia) { $inertia->misses('foo.baz'); }); } /** @test */ public function it_fails_asserting_that_a_prop_is_missing_when_it_exists_using_the_misses_method(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'prop' => 'value', 'foo' => [ 'bar' => true, ], ]) ); $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage('Inertia property [foo.bar] was found while it was expected to be missing.'); $response->assertInertia(function (Assert $inertia) { $inertia ->has('prop') ->misses('foo.bar'); }); } /** @test */ public function it_fails_asserting_that_a_prop_is_missing_when_it_exists(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'prop' => 'value', 'foo' => [ 'bar' => true, ], ]) ); $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage('Inertia property [foo.bar] was found while it was expected to be missing.'); $response->assertInertia(function (Assert $inertia) { $inertia ->has('prop') ->missing('foo.bar'); }); } /** @test */ public function it_can_assert_that_multiple_props_are_missing(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'baz' => 'foo', ]) ); $response->assertInertia(function (Assert $inertia) { $inertia ->has('baz') ->missingAll([ 'foo', 'bar', ]); }); } /** @test */ public function it_cannot_assert_that_multiple_props_are_missing_when_at_least_one_exists(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'foo' => 'bar', 'baz' => 'example', ]) ); $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage('Inertia property [baz] was found while it was expected to be missing.'); $response->assertInertia(function (Assert $inertia) { $inertia ->has('foo') ->missingAll([ 'bar', 'baz', ]); }); } /** @test */ public function it_can_use_arguments_instead_of_an_array_to_assert_that_it_is_missing_multiple_props(): void { $this->makeMockRequest( Inertia::render('foo', [ 'baz' => 'foo', ]) )->assertInertia(function (Assert $inertia) { $inertia->has('baz')->missingAll('foo', 'bar'); }); $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage('Inertia property [baz] was found while it was expected to be missing.'); $this->makeMockRequest( Inertia::render('foo', [ 'foo' => 'bar', 'baz' => 'example', ]) )->assertInertia(function (Assert $inertia) { $inertia->has('foo')->missingAll('bar', 'baz'); }); } /** @test */ public function it_can_assert_that_multiple_props_are_missing_using_the_misses_all_method(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'baz' => 'foo', ]) ); $response->assertInertia(function (Assert $inertia) { $inertia ->has('baz') ->missesAll([ 'foo', 'bar', ]); }); } /** @test */ public function it_cannot_assert_that_multiple_props_are_missing_when_at_least_one_exists_using_the_misses_all_method(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'foo' => 'bar', 'baz' => 'example', ]) ); $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage('Inertia property [baz] was found while it was expected to be missing.'); $response->assertInertia(function (Assert $inertia) { $inertia ->has('foo') ->missesAll([ 'bar', 'baz', ]); }); } /** @test */ public function it_can_use_arguments_instead_of_an_array_to_assert_that_it_is_missing_multiple_props_using_the_misses_all_method(): void { $this->makeMockRequest( Inertia::render('foo', [ 'baz' => 'foo', ]) )->assertInertia(function (Assert $inertia) { $inertia->has('baz')->missesAll('foo', 'bar'); }); $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage('Inertia property [baz] was found while it was expected to be missing.'); $this->makeMockRequest( Inertia::render('foo', [ 'foo' => 'bar', 'baz' => 'example', ]) )->assertInertia(function (Assert $inertia) { $inertia->has('foo')->missesAll('bar', 'baz'); }); } /** @test */ public function the_prop_matches_a_value(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'bar' => 'value', ]) ); $response->assertInertia(function (Assert $inertia) { $inertia->where('bar', 'value'); }); } /** @test */ public function the_prop_does_not_match_a_value(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'bar' => 'value', ]) ); $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage('Inertia property [bar] does not match the expected value.'); $response->assertInertia(function (Assert $inertia) { $inertia->where('bar', 'invalid'); }); } /** @test */ public function the_prop_does_not_match_a_value_when_it_does_not_exist(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'bar' => 'value', ]) ); $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage('Inertia property [baz] does not exist.'); $response->assertInertia(function (Assert $inertia) { $inertia->where('baz', null); }); } /** @test */ public function the_prop_does_not_match_loosely(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'bar' => 1, ]) ); $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage('Inertia property [bar] does not match the expected value.'); $response->assertInertia(function (Assert $inertia) { $inertia->where('bar', true); }); } /** @test */ public function the_prop_matches_a_value_using_a_closure(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'bar' => 'baz', ]) ); $response->assertInertia(function (Assert $inertia) { $inertia->where('bar', function ($value) { return $value === 'baz'; }); }); } /** @test */ public function the_prop_does_not_match_a_value_using_a_closure(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'bar' => 'baz', ]) ); $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage('Inertia property [bar] was marked as invalid using a closure.'); $response->assertInertia(function (Assert $inertia) { $inertia->where('bar', function ($value) { return $value === 'invalid'; }); }); } /** @test */ public function array_props_will_be_automatically_cast_to_collections_when_using_a_closure(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'bar' => [ 'baz' => 'foo', 'example' => 'value', ], ]) ); $response->assertInertia(function (Assert $inertia) { $inertia->where('bar', function ($value) { $this->assertInstanceOf(Collection::class, $value); return $value->count() === 2; }); }); } /** @test */ public function the_prop_matches_a_value_using_an_arrayable(): void { Model::unguard(); $user = User::make(['name' => 'Example']); $response = $this->makeMockRequest( Inertia::render('foo', [ 'bar' => $user, ]) ); $response->assertInertia(function (Assert $inertia) use ($user) { $inertia->where('bar', $user); }); } /** @test */ public function the_prop_does_not_match_a_value_using_an_arrayable(): void { Model::unguard(); $userA = User::make(['name' => 'Example']); $userB = User::make(['name' => 'Another']); $response = $this->makeMockRequest( Inertia::render('foo', [ 'bar' => $userA, ]) ); $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage('Inertia property [bar] does not match the expected value.'); $response->assertInertia(function (Assert $inertia) use ($userB) { $inertia->where('bar', $userB); }); } /** @test */ public function the_prop_matches_a_value_using_an_arrayable_even_when_they_are_sorted_differently(): void { // https://github.com/claudiodekker/inertia-laravel-testing/issues/30 Model::unguard(); $response = $this->makeMockRequest( Inertia::render('foo', [ 'bar' => User::make(['id' => 1, 'name' => 'Example']), 'baz' => [ 'id' => 1, 'name' => 'Nayeli Hermiston', 'email' => 'vroberts@example.org', 'email_verified_at' => '2021-01-22T10:34:42.000000Z', 'created_at' => '2021-01-22T10:34:42.000000Z', 'updated_at' => '2021-01-22T10:34:42.000000Z', ], ]) ); $response->assertInertia(function (Assert $inertia) { $inertia ->where('bar', User::make(['name' => 'Example', 'id' => 1])) ->where('baz', [ 'name' => 'Nayeli Hermiston', 'email' => 'vroberts@example.org', 'id' => 1, 'email_verified_at' => '2021-01-22T10:34:42.000000Z', 'updated_at' => '2021-01-22T10:34:42.000000Z', 'created_at' => '2021-01-22T10:34:42.000000Z', ]); }); } /** @test */ public function the_prop_matches_a_value_using_a_responsable(): void { Model::unguard(); $user = User::make(['name' => 'Example']); $resource = JsonResource::collection(new Collection([$user, $user])); $response = $this->makeMockRequest( Inertia::render('foo', [ 'bar' => $resource, ]) ); $response->assertInertia(function (Assert $inertia) use ($resource) { $inertia->where('bar', $resource); }); } /** @test */ public function the_prop_does_not_match_a_value_using_a_responsable(): void { Model::unguard(); $resourceA = JsonResource::make(User::make(['name' => 'Another'])); $resourceB = JsonResource::make(User::make(['name' => 'Example'])); $response = $this->makeMockRequest( Inertia::render('foo', [ 'bar' => $resourceA, ]) ); $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage('Inertia property [bar] does not match the expected value.'); $response->assertInertia(function (Assert $inertia) use ($resourceB) { $inertia->where('bar', $resourceB); }); } /** @test */ public function the_nested_prop_matches_a_value(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'example' => [ 'nested' => 'nested-value', ], ]) ); $response->assertInertia(function (Assert $inertia) { $inertia->where('example.nested', 'nested-value'); }); } /** @test */ public function the_nested_prop_does_not_match_a_value(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'example' => [ 'nested' => 'nested-value', ], ]) ); $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage('Inertia property [example.nested] does not match the expected value.'); $response->assertInertia(function (Assert $inertia) { $inertia->where('example.nested', 'another-value'); }); } /** @test */ public function it_can_scope_the_assertion_query(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'bar' => [ 'baz' => 'example', 'prop' => 'value', ], ]) ); $called = false; $response->assertInertia(function (Assert $inertia) use (&$called) { $inertia->has('bar', function (Assert $inertia) use (&$called) { $called = true; $inertia ->where('baz', 'example') ->where('prop', 'value'); }); }); $this->assertTrue($called, 'The scoped query was never actually called.'); } /** @test */ public function it_cannot_scope_the_assertion_query_when_the_scoped_prop_does_not_exist(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'bar' => [ 'baz' => 'example', 'prop' => 'value', ], ]) ); $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage('Inertia property [baz] does not exist.'); $response->assertInertia(function (Assert $inertia) { $inertia->has('baz', function (Assert $inertia) { $inertia->where('baz', 'example'); }); }); } /** @test */ public function it_cannot_scope_the_assertion_query_when_the_scoped_prop_is_a_single_value(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'bar' => 'value', ]) ); $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage('Inertia property [bar] is not scopeable.'); $response->assertInertia(function (Assert $inertia) { $inertia->has('bar', function (Assert $inertia) { // }); }); } /** @test */ public function it_can_scope_on_complex_objects_responsable(): void { Model::unguard(); $userA = User::make(['name' => 'Example']); $userB = User::make(['name' => 'Another']); $response = $this->makeMockRequest( Inertia::render('foo', [ 'example' => JsonResource::make([$userA, $userB]), ]) ); $called = false; $response->assertInertia(function (Assert $inertia) use (&$called) { return $inertia->has('example', function (Assert $inertia) use (&$called) { $inertia->has('data', 2); $called = true; }); }); $this->assertTrue($called, 'The scoped query was never actually called.'); } /** @test */ public function it_can_directly_scope_onto_the_first_item_when_asserting_that_a_prop_has_a_length_greater_than_zero(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'bar' => [ ['key' => 'first'], ['key' => 'second'], ], ]) ); $response->assertInertia(function (Assert $inertia) { $inertia->has('bar', 2, function (Assert $inertia) { $inertia->where('key', 'first'); }); }); } /** @test */ public function it_cannot_directly_scope_onto_the_first_item_when_asserting_that_a_prop_has_a_length_of_zero(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'bar' => [ ['key' => 'first'], ['key' => 'second'], ], ]) ); $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage('Cannot scope directly onto the first entry of property [bar] when asserting that it has a size of 0.'); $response->assertInertia(function (Assert $inertia) { $inertia->has('bar', 0, function (Assert $inertia) { $inertia->where('key', 'first'); }); }); } /** @test */ public function it_cannot_directly_scope_onto_the_first_item_when_it_does_not_match_the_expected_size(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'bar' => [ ['key' => 'first'], ['key' => 'second'], ], ]) ); $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage('Inertia property [bar] does not have the expected size.'); $response->assertInertia(function (Assert $inertia) { $inertia->has('bar', 1, function (Assert $inertia) { $inertia->where('key', 'first'); }); }); } /** @test */ public function it_fails_when_it_does_not_interact_with_all_props_in_the_scope_at_least_once(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'bar' => [ 'baz' => 'example', 'prop' => 'value', ], ]) ); $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage('Unexpected Inertia properties were found in scope [bar].'); $response->assertInertia(function (Assert $inertia) { $inertia->has('bar', function (Assert $inertia) { $inertia->where('baz', 'example'); }); }); } /** @test */ public function it_does_not_fail_when_not_interacting_with_every_top_level_prop_by_default(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'foo' => 'bar', 'bar' => 'baz', ]) ); $response->assertInertia(function (Assert $inertia) { $inertia->has('foo'); }); } /** @test */ public function it_fails_when_not_interacting_with_every_top_level_prop_while_the_force_setting_is_enabled(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'foo' => 'bar', 'bar' => 'baz', ]) ); config()->set('inertia.force_top_level_property_interaction', true); $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage('Unexpected Inertia properties were found on the root level.'); $response->assertInertia(function (Assert $inertia) { $inertia->has('foo'); }); } /** @test */ public function it_can_disable_the_interaction_check_for_the_current_scope(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'bar' => true, ]) ); $response->assertInertia(function (Assert $inertia) { $inertia->etc(); }); } /** @test */ public function it_cannot_disable_the_interaction_check_for_any_other_scopes(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'bar' => true, 'baz' => [ 'foo' => 'bar', 'example' => 'value', ], ]) ); $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage('Unexpected Inertia properties were found in scope [baz].'); $response->assertInertia(function (Assert $inertia) { $inertia ->etc() ->has('baz', function (Assert $inertia) { $inertia->where('foo', 'bar'); }); }); } /** @test */ public function it_can_assert_that_multiple_props_match_their_expected_values_at_once(): void { Model::unguard(); $user = User::make(['name' => 'Example']); $resource = JsonResource::make(User::make(['name' => 'Another'])); $response = $this->makeMockRequest( Inertia::render('foo', [ 'foo' => [ 'user' => $user, 'resource' => $resource, ], 'bar' => 'baz', ]) ); $response->assertInertia(function (Assert $inertia) use ($user, $resource) { $inertia->whereAll([ 'foo.user' => $user, 'foo.resource' => $resource, 'bar' => function ($value) { return $value === 'baz'; }, ]); }); } /** @test */ public function it_cannot_assert_that_multiple_props_match_their_expected_values_when_at_least_one_does_not(): void { $response = $this->makeMockRequest( Inertia::render('foo', [ 'foo' => 'bar', 'baz' => 'example', ])
php
MIT
1e4f320bd85146c5e85cd189126d46a21ec470ef
2026-01-05T05:07:58.862099Z
true
claudiodekker/inertia-laravel-testing
https://github.com/claudiodekker/inertia-laravel-testing/blob/1e4f320bd85146c5e85cd189126d46a21ec470ef/tests/Unit/TestResponseMacrosTest.php
tests/Unit/TestResponseMacrosTest.php
<?php namespace ClaudioDekker\Inertia\Tests\Unit; use ClaudioDekker\Inertia\Assert; use ClaudioDekker\Inertia\Tests\TestCase; use Inertia\Inertia; class TestResponseMacrosTest extends TestCase { /** @test */ public function it_can_make_inertia_assertions(): void { $response = $this->makeMockRequest( Inertia::render('foo') ); $success = false; $response->assertInertia(function ($page) use (&$success) { $this->assertInstanceOf(Assert::class, $page); $success = true; }); $this->assertTrue($success); } /** @test */ public function it_preserves_the_ability_to_continue_chaining_laravel_test_response_calls(): void { $response = $this->makeMockRequest( Inertia::render('foo') ); $this->assertInstanceOf( $this->getTestResponseClass(), $response->assertInertia() ); } /** @test */ public function it_can_retrieve_the_inertia_page(): void { $response = $this->makeMockRequest( Inertia::render('foo', ['bar' => 'baz']) ); tap($response->inertiaPage(), function (array $page) { $this->assertSame('foo', $page['component']); $this->assertSame(['bar' => 'baz'], $page['props']); $this->assertSame('/example-url', $page['url']); $this->assertSame('', $page['version']); }); } }
php
MIT
1e4f320bd85146c5e85cd189126d46a21ec470ef
2026-01-05T05:07:58.862099Z
false
claudiodekker/inertia-laravel-testing
https://github.com/claudiodekker/inertia-laravel-testing/blob/1e4f320bd85146c5e85cd189126d46a21ec470ef/config/inertia.php
config/inertia.php
<?php return [ /* |-------------------------------------------------------------------------- | Force top-level property interaction |-------------------------------------------------------------------------- | | This setting allows you to toggle the automatic property interaction | check for your page's top-level properties. While this feature is | useful in property scopes, it is generally not as useful on the | top-level of the page, as it forces you to interact with each | (shared) property on the page, or to use the `etc` method. | */ 'force_top_level_property_interaction' => false, /* |-------------------------------------------------------------------------- | Page |-------------------------------------------------------------------------- | | The values described here are used to locate Inertia components on the | filesystem. For instance, when using `assertInertia`, the assertion | attempts to locate the component as a file relative to any of the | paths AND with any of the extensions specified here. | */ 'page' => [ /** * Determines whether assertions should check that Inertia page components * actually exist on the filesystem instead of just checking responses. */ 'should_exist' => true, /* * A list of root paths to your Inertia page components. */ 'paths' => [ resource_path('js/Pages'), ], /* * A list of valid Inertia page component extensions. */ 'extensions' => [ 'vue', 'svelte', ], ], ];
php
MIT
1e4f320bd85146c5e85cd189126d46a21ec470ef
2026-01-05T05:07:58.862099Z
false
recca0120/laravel-repository
https://github.com/recca0120/laravel-repository/blob/d506fdc8c602e0ccaa52aea2d2f8ee3380dbbedd/src/Method.php
src/Method.php
<?php namespace Recca0120\Repository; class Method { /** * $name. * * @var string */ public $name; /** * $parameters. * * @var mixed */ public $parameters; /** * @param string $name * @param mixed $parameters */ public function __construct($name, $parameters = []) { $this->name = $name; $this->parameters = $parameters; } }
php
MIT
d506fdc8c602e0ccaa52aea2d2f8ee3380dbbedd
2026-01-05T05:08:03.638560Z
false
recca0120/laravel-repository
https://github.com/recca0120/laravel-repository/blob/d506fdc8c602e0ccaa52aea2d2f8ee3380dbbedd/src/SqliteConnectionResolver.php
src/SqliteConnectionResolver.php
<?php namespace Recca0120\Repository; use Illuminate\Container\Container; use Illuminate\Database\ConnectionInterface; use Illuminate\Database\ConnectionResolverInterface; use Illuminate\Database\Connectors\ConnectionFactory; class SqliteConnectionResolver implements ConnectionResolverInterface { /** * All of the registered connections. * * @var array */ protected $connections = []; /** * The default connection name. * * @var string */ protected $default = 'default'; /** * The current globally available container (if any). * * @var static */ private static $instance; /** @var ConnectionFactory */ private $factory; public function __construct(?ConnectionFactory $factory = null) { $this->factory = $factory ?? new ConnectionFactory(Container::getInstance() ?: new Container); } /** * Get a database connection instance. * * @param string $name * @return ConnectionInterface */ public function connection($name = null) { if (is_null($name)) { $name = $this->getDefaultConnection(); } if (isset($this->connections[$name]) === false) { $this->connections[$name] = $this->factory->make([ 'driver' => 'sqlite', 'database' => ':memory:', ], $name); } return $this->connections[$name]; } /** * Get the default connection name. * * @return string */ public function getDefaultConnection() { return $this->default; } /** * Set the default connection name. * * @param string $name * @return void */ public function setDefaultConnection($name) { $this->default = $name; } /** * Set the globally available instance of the SqliteConnectionResolver. * * @return static */ public static function getInstance(?ConnectionFactory $factory = null) { if (is_null(static::$instance)) { static::$instance = new static($factory); } return static::$instance; } }
php
MIT
d506fdc8c602e0ccaa52aea2d2f8ee3380dbbedd
2026-01-05T05:08:03.638560Z
false
recca0120/laravel-repository
https://github.com/recca0120/laravel-repository/blob/d506fdc8c602e0ccaa52aea2d2f8ee3380dbbedd/src/EloquentRepository.php
src/EloquentRepository.php
<?php namespace Recca0120\Repository; use Illuminate\Contracts\Pagination\LengthAwarePaginator; use Illuminate\Contracts\Pagination\Paginator; use Illuminate\Contracts\Support\Arrayable; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Database\Query\Builder as QueryBuilder; use Illuminate\Support\Collection; use InvalidArgumentException; use Recca0120\Repository\Contracts\EloquentRepository as EloquentRepositoryContract; use Throwable; abstract class EloquentRepository implements EloquentRepositoryContract { /** * $model. * * @var Model|Builder */ protected $model; /** * __construct. * * @param Model|Builder $model */ public function __construct($model) { $this->model = $model; } /** * Find a model by its primary key. * * @param mixed $id * @param array $columns * @return Model */ public function find($id, $columns = ['*']) { return $this->newQuery()->find($id, $columns); } /** * Find multiple models by their primary keys. * * @param Arrayable|array $ids * @param array $columns * @return \Illuminate\Database\Eloquent\Collection */ public function findMany($ids, $columns = ['*']) { return $this->newQuery()->findMany($ids, $columns); } /** * Find a model by its primary key or throw an exception. * * @param mixed $id * @param array $columns * @return Model * * @throws ModelNotFoundException */ public function findOrFail($id, $columns = ['*']) { return $this->newQuery()->findOrFail($id, $columns); } /** * Find a model by its primary key or return fresh model instance. * * @param mixed $id * @param array $columns * @return Model */ public function findOrNew($id, $columns = ['*']) { return $this->newQuery()->findOrNew($id, $columns); } /** * Get the first record matching the attributes or instantiate it. * * @return Model */ public function firstOrNew(array $attributes, array $values = []) { return $this->newQuery()->firstOrNew($attributes, $values); } /** * Get the first record matching the attributes or create it. * * @return Model */ public function firstOrCreate(array $attributes, array $values = []) { return $this->newQuery()->firstOrCreate($attributes, $values); } /** * Create or update a record matching the attributes, and fill it with values. * * @return Model */ public function updateOrCreate(array $attributes, array $values = []) { return $this->newQuery()->updateOrCreate($attributes, $values); } /** * Execute the query and get the first result or throw an exception. * * @param Criteria[] $criteria * @param array $columns * @return Model * * @throws ModelNotFoundException */ public function firstOrFail($criteria = [], $columns = ['*']) { return $this->matching($criteria)->firstOrFail($columns); } /** * create. * * @param array $attributes * @return Model * * @throws Throwable */ public function create($attributes) { return $this->newQuery()->create($attributes); } /** * Save a new model and return the instance. * * @param array $attributes * @return Model * * @throws Throwable */ public function forceCreate($attributes) { return $this->newQuery()->forceCreate($attributes); } /** * update. * * @param array $attributes * @param mixed $id * @return Model * * @throws Throwable */ public function update($id, $attributes) { return tap($this->findOrFail($id), static function ($instance) use ($attributes) { $instance->fill($attributes)->saveOrFail(); }); } /** * forceCreate. * * @param array $attributes * @param mixed $id * @return Model * * @throws Throwable */ public function forceUpdate($id, $attributes) { return tap($this->findOrFail($id), static function ($instance) use ($attributes) { $instance->forceFill($attributes)->saveOrFail(); }); } /** * delete. * * @param mixed $id */ public function delete($id) { return $this->find($id)->delete(); } /** * Restore a soft-deleted model instance. * * @param mixed $id * @return bool|null */ public function restore($id) { return $this->newQuery()->where($this->getModel()->getKeyName(), $id)->restore(); } /** * Force a hard delete on a soft deleted model. * * This method protects developers from running forceDelete when trait is missing. * * @param mixed $id * @return bool|null */ public function forceDelete($id) { return $this->findOrFail($id)->forceDelete(); } /** * Create a new model instance that is existing. * * @param array $attributes * @return Model */ public function newInstance($attributes = [], $exists = false) { return $this->getModel()->newInstance($attributes, $exists); } /** * Execute the query as a "select" statement. * * @param Criteria[]|Criteria $criteria * @param array $columns * @return Collection */ public function get($criteria = [], $columns = ['*']) { return $this->matching($criteria)->get($columns); } /** * Chunk the results of the query. * * @param Criteria[]|Criteria $criteria * @param int $count * @return bool */ public function chunk($criteria, $count, callable $callback) { return $this->matching($criteria)->chunk($count, $callback); } /** * Execute a callback over each item while chunking. * * @param Criteria[]|Criteria $criteria * @param int $count * @return bool */ public function each($criteria, callable $callback, $count = 1000) { return $this->matching($criteria)->each($callback, $count); } /** * Execute the query and get the first result. * * @param Criteria[]|Criteria $criteria * @param array $columns * @return Model|null */ public function first($criteria = [], $columns = ['*']) { return $this->matching($criteria)->first($columns); } /** * Paginate the given query. * * @param Criteria[]|Criteria $criteria * @param int $perPage * @param array $columns * @param string $pageName * @param int|null $page * @return LengthAwarePaginator * * @throws InvalidArgumentException */ public function paginate($criteria = [], $perPage = null, $columns = ['*'], $pageName = 'page', $page = null) { return $this->matching($criteria)->paginate($perPage, $columns, $pageName, $page); } /** * Paginate the given query into a simple paginator. * * @param Criteria[]|Criteria $criteria * @param int $perPage * @param array $columns * @param string $pageName * @param int|null $page * @return Paginator */ public function simplePaginate($criteria = [], $perPage = null, $columns = ['*'], $pageName = 'page', $page = null) { return $this->matching($criteria)->simplePaginate($perPage, $columns, $pageName, $page); } /** * Retrieve the "count" result of the query. * * @param Criteria[]|Criteria $criteria * @param string $columns * @return int */ public function count($criteria = [], $columns = '*') { return (int) $this->matching($criteria)->count($columns); } /** * Retrieve the minimum value of a given column. * * @param Criteria[]|Criteria $criteria * @param string $column * @return float|int */ public function min($criteria, $column) { return $this->matching($criteria)->min($column); } /** * Retrieve the maximum value of a given column. * * @param Criteria[]|Criteria $criteria * @param string $column * @return float|int */ public function max($criteria, $column) { return $this->matching($criteria)->max($column); } /** * Retrieve the sum of the values of a given column. * * @param Criteria[]|Criteria $criteria * @param string $column * @return float|int */ public function sum($criteria, $column) { $result = $this->matching($criteria)->sum($column); return $result ?: 0; } /** * Retrieve the average of the values of a given column. * * @param Criteria[]|Criteria $criteria * @param string $column * @return float|int */ public function avg($criteria, $column) { return $this->matching($criteria)->avg($column); } /** * Alias for the "avg" method. * * @param string $column * @return float|int */ public function average($criteria, $column) { return $this->avg($criteria, $column); } /** * matching. * * @param Criteria[]|Criteria $criteria * @return Builder */ public function matching($criteria) { $criteria = is_array($criteria) === false ? [$criteria] : $criteria; return array_reduce($criteria, static function ($query, $criteria) { $criteria->each(static function ($method) use ($query) { call_user_func_array([$query, $method->name], $method->parameters); }); return $query; }, $this->newQuery()); } /** * getQuery. * * @param Criteria[] $criteria * @return QueryBuilder */ public function getQuery($criteria = []) { return $this->matching($criteria)->getQuery(); } /** * getModel. * * @return Model */ public function getModel() { return $this->model instanceof Model ? clone $this->model : $this->model->getModel(); } /** * Get a new query builder for the model's table. * * @return Builder */ public function newQuery() { return $this->model instanceof Model ? $this->model->newQuery() : clone $this->model; } }
php
MIT
d506fdc8c602e0ccaa52aea2d2f8ee3380dbbedd
2026-01-05T05:08:03.638560Z
false
recca0120/laravel-repository
https://github.com/recca0120/laravel-repository/blob/d506fdc8c602e0ccaa52aea2d2f8ee3380dbbedd/src/Expression.php
src/Expression.php
<?php namespace Recca0120\Repository; use Illuminate\Database\Query\Expression as QueryExpression; class Expression extends QueryExpression {}
php
MIT
d506fdc8c602e0ccaa52aea2d2f8ee3380dbbedd
2026-01-05T05:08:03.638560Z
false
recca0120/laravel-repository
https://github.com/recca0120/laravel-repository/blob/d506fdc8c602e0ccaa52aea2d2f8ee3380dbbedd/src/Criteria.php
src/Criteria.php
<?php namespace Recca0120\Repository; use BadMethodCallException; use Closure; use Illuminate\Database\Eloquent\Builder as EloquentBuilder; use Illuminate\Database\Query\Builder as QueryBuilder; use Illuminate\Support\Str; use ReflectionClass; use ReflectionException; use ReflectionMethod; /** * @mixin QueryBuilder * @mixin EloquentBuilder */ class Criteria { use Concerns\SoftDeletingScope; protected $proxies = [ EloquentBuilder::class, QueryBuilder::class, ]; /** * $methods. * * @var Method[] */ protected $methods = []; private static $cache = []; /** * Handle dynamic method calls into the method. * * @param string $method * @param array $parameters * @return Criteria * * @throws BadMethodCallException * @throws ReflectionException */ public function __call($method, $parameters) { $hasMethod = $this->hasMethod($method); if ($hasMethod) { $this->methods[] = new Method($method, $parameters); return $this; } if (Str::startsWith($method, 'where')) { return $this->dynamicWhere($method, $parameters); } $className = static::class; throw new BadMethodCallException("Call to undefined method {$className}::{$method}()"); } /** * create. * * @return static */ public static function create() { return new static; } /** * alias raw. * * @param mixed $value * @return Expression */ public static function expr($value) { return static::raw($value); } /** * @param mixed $value * @return Expression */ public static function raw($value) { return new Expression($value); } /** * each. * * @return void */ public function each(Closure $callback) { foreach ($this->methods as $method) { $callback($method); } } /** * toArray. * * @return array */ public function toArray() { return array_map(static function ($method) { return [ 'method' => $method->name, 'parameters' => $method->parameters, ]; }, $this->methods); } /** * Begin querying the model on the write connection. * * @return Criteria */ public function onWriteConnection() { return $this->useWritePdo(); } /** * @param string $class * @return string[] * * @throws ReflectionException */ private function findMethods($class) { if (array_key_exists($class, self::$cache)) { return self::$cache[$class]; } $ref = new ReflectionClass($class); return self::$cache[$class] = array_flip(array_map(static function ($method) { return $method->getName(); }, $ref->getMethods(ReflectionMethod::IS_PUBLIC))); } /** * @return bool * * @throws ReflectionException */ private function hasMethod(string $method) { foreach ($this->proxies as $proxy) { $methods = $this->findMethods($proxy); if (array_key_exists($method, $methods)) { return true; } } return false; } }
php
MIT
d506fdc8c602e0ccaa52aea2d2f8ee3380dbbedd
2026-01-05T05:08:03.638560Z
false
recca0120/laravel-repository
https://github.com/recca0120/laravel-repository/blob/d506fdc8c602e0ccaa52aea2d2f8ee3380dbbedd/src/HigherOrderTapProxy.php
src/HigherOrderTapProxy.php
<?php namespace Recca0120\Repository; class HigherOrderTapProxy { /** * The target being tapped. * * @var mixed */ public $target; /** * Create a new tap proxy instance. * * @param mixed $target * @return void */ public function __construct($target) { $this->target = $target; } /** * Dynamically pass method calls to the target. * * @param string $method * @param array $parameters * @return mixed */ public function __call($method, $parameters) { call_user_func_array([$this->target, $method], $parameters); return $this->target; } }
php
MIT
d506fdc8c602e0ccaa52aea2d2f8ee3380dbbedd
2026-01-05T05:08:03.638560Z
false
recca0120/laravel-repository
https://github.com/recca0120/laravel-repository/blob/d506fdc8c602e0ccaa52aea2d2f8ee3380dbbedd/src/CollectionModel.php
src/CollectionModel.php
<?php namespace Recca0120\Repository; use Illuminate\Support\Collection; abstract class CollectionModel extends FileModel { /** * items. * * @var array|Collection */ protected $items = []; /** * loadFromResource. * * @return Collection */ protected function loadFromResource() { return $this->items instanceof Collection ? $this->items : new Collection($this->items); } }
php
MIT
d506fdc8c602e0ccaa52aea2d2f8ee3380dbbedd
2026-01-05T05:08:03.638560Z
false