Skip to content

Commit

Permalink
Alfa release
Browse files Browse the repository at this point in the history
  • Loading branch information
niksamokhvalov committed Nov 24, 2015
1 parent 87a3fe5 commit adbb131
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/FileAccessManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@

namespace Bex\Niceaccess;

use Bex\Tools\GroupTools;
use Bex\Tools\Group\GroupTools;
use Bex\Tools\ValueNotFoundException;
use Bitrix\Main\ArgumentNullException;
use Bitrix\Main\IO\File;
use Bitrix\Main\IO\InvalidPathException;

/**
* Implements replacement of user group id's by \Bex\Tools method which returns user group id by symbol code
* in .access.php files. File .access.php will not depend on DB user group id after that
* in .access.php files. File .access.php will not depend on DB user group id after that.
*
* @author Nik Samokhvalov <[email protected]>
*/
Expand Down Expand Up @@ -48,12 +49,11 @@ public function __construct($path)
}

/**
* Resave file .access.php, with usage symbol of the codes users groups instead id's
* Converting content from .access.php file, with usage symbol of the codes users groups instead id's.
*
* @param string $content
*
* @return bool
* @throws ArgumentNullException
*/
public function convertContent(&$content)
{
Expand All @@ -63,17 +63,25 @@ public function convertContent(&$content)
}
elseif (empty($content))
{
throw new ArgumentNullException('content');
return false;
}

$content = preg_replace_callback('/(PERM\[.+\]\[)(\"G?[0-9]+\")(\])/', function ($matches) {
$matches[2] = trim($matches[2], "\"");
$groupId = str_replace('G', '', $matches[2], $addG);

try
{
$groupCode = GroupTools::findById($groupId)->code();
}
catch (ValueNotFoundException $e)
{
return $matches[0];
}

// @todo Если символьный код не установлен?
$groupCode = GroupTools::findById($groupId)->code();
$value = ($addG ? "'G'." : '') . '\Bex\Tools\Group\GroupTools::find(\'' . $groupCode . '\', true)->id()';

return $matches[1] . ($addG ? "'G'." : '') . "\Bex\Tools\Group\GroupTools::find('{$groupCode}')->id()" . $matches[3];
return $matches[1] . $value . $matches[3];
}, $content);

return true;
Expand Down

0 comments on commit adbb131

Please sign in to comment.