interface HasStatus
{
public const STATUS_NOT_PAID = 0;
public const STATUS_PAID = 1;
public const STATUS_CANCEL = 3;
public function getStatus(): int;
}
class StatusHelper
{
/**
* Статистический метод получения списка статусов
*
* @return array
*/
public static function getStatusList()
{
return [
HasStatus::STATUS_NOT_PAID => 'Не оплачено',
HasStatus::STATUS_PAID => 'Оплачено',
HasStatus::STATUS_CANCEL => 'Отменена',
];
}
public function getStatusName(HasStatus $entity): string
{
ArrayHelper::getValue(self::getStatusList(), $entity->getStatus());
}
}
https://мойсервер/telegrambot/file.php?apibot=24953021_______Pnjwywdkg&chatid=-1003333102111&document=%D0%9F%D1%80%D0%BE%D0%B4%D0%B0%D0%B6%D0%B8_%D0%BC%D0%B5%D1%81%D1%8F%D1%86_%D0%BC%D0%B0%D0%B9.xls
<?php
namespace app\components;
use Adldap\Adldap;
use Adldap\Auth\BindException;
use Adldap\Auth\PasswordRequiredException;
use Adldap\Auth\UsernameRequiredException;
use Adldap\Connections\ProviderInterface;
use Adldap\Models\Group;
use Adldap\Models\Model;
use Adldap\Models\User;
use app\components\interfaces\ExternalAuthProviderInterface;
use Illuminate\Support\Collection;
use yii\base\Component;
/**
* Class LdapService
* Wrapper to work with LDAP package.
*
* @package app\components
*/
class LdapService extends Component implements ExternalAuthProviderInterface
{
/**
* Account suffix.
*
* @var string
*/
public $accountSuffix = '';
/**
* List of domain controllers.
*
* @var array
*/
public $domainControllers = [];
/**
* Base DN.
*
* @var string
*/
public $baseDn;
/**
* Domain admin user name.
*
* @var string
*/
public $adminUserName;
/**
* Domain admin password.
*
* @var string
*/
public $adminPassword;
/**
* Connection provider to the AD.
*
* @var ProviderInterface
*/
private $provider;
/**
* Attempt to login in domain.
*
* @param string $login login.
* @param string $password password.
*
* @throws BindException if there are connections errors.
* @throws PasswordRequiredException
* @throws UsernameRequiredException
*
* @return bool
*/
public function attempt(string $login, string $password): bool
{
return $this->getProvider()
->auth()
->attempt($login, $password);
}
/**
* Find user in the AD by login(account name).
*
* @param string $login login/account name.
*
* @throws \Adldap\Models\ModelNotFoundException
* @throws BindException
* @throws \InvalidArgumentException
* @return User|Model
*/
public function findUserByLogin(string $login): User
{
return $this->getProvider()
->search()
->users()
->where('samaccountname', '=', $login)
->firstOrFail();
}
/**
* Find user in the AD by full name.
*
* @param string $username users full name.
*
* @throws \Adldap\Models\ModelNotFoundException
* @throws BindException
* @throws \InvalidArgumentException
* @return User|Model
*/
public function findUserByFullName(string $username): User
{
return $this->getProvider()
->search()
->users()
->where('cn', '=', $username)
->firstOrFail();
}
/**
* Returns list of all group in the AD.
*
* @throws BindException
* @return Collection|Group[]
*/
public function getAllGroups(): Collection
{
return $this->getProvider()
->search()
->groups()
->get();
}
/**
* Returns configured AD provider.
*
* @throws BindException
* @return ProviderInterface
*/
private function getProvider(): ProviderInterface
{
if (null === $this->provider) {
$ad = new Adldap($this->getConfig());
$this->provider = $ad->connect('default');
}
return $this->provider;
}
/**
* Returns config to connect to the ldap domain.
*
* @return array
*/
private function getConfig(): array
{
return [
'default' => [
'domain_controllers' => $this->domainControllers,
'base_dn' => $this->baseDn,
'admin_username' => $this->adminUserName,
'admin_password' => $this->adminPassword,
'account_suffix' => $this->accountSuffix,
],
];
}
}
'components' => [
...
'ldap' => [
'class' => \app\components\LdapService::class,
'accountSuffix' => '@test',
'domainControllers' => ['192.168.1.1'],
'baseDn' => 'DC=admin',
'adminUserName' => 'admin',
'adminPassword' => 'password',
],
],
$user = \Yii::$app->get('ldap')->findUserByLogin('someLogin');
products
----------
id
name
...
categories
------------
id
name
...
products_categories
------------------------
product_id
category_id
$width, $image
и т.д. Эти переменные надо передавать как аргументы функцииfunction someFunction($width)
{
return ++$width;
}
function someFunction()
{
global $width;
// do something with $width
}
class BlogPost extends Post implements JsonSerializable {
//...
public function jsonSerialize() {
return [
'title' => $this->title,
'attachments' => $this->attachments,
...
];
}
}
return json_encode($blogPost);
<?php
namespace app\assets;
use yii\web\AssetBundle;
class AppAsset extends AssetBundle
{
public function init()
{
$format = 'theme/assets/global/plugins/date/locales/dater.%s.min.js';
$this->js[] = sprintf($format, \Yii::$app->language);
}
}
public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors['authenticator'] = [
'class' => HttpBearerAuth::className(),
];
return $behaviors;
}
<?php
interface UserInterface
{
public function getFirstName();
public function getLastName();
public function getLogin();
}
/**
* Class User
*
* @property string $firstName
* @property string $lastName
* @property string $login
*/
class User extends \yii\db\ActiveRecord implements UserInterface
{
...
public function getFirstName()
{
return $this->firstName;
}
public function getLastName()
{
return $this->lastName;
}
public function getLogin()
{
return $this->login;
}
}
class TestController
{
/**
* Здесь явно указываем тип переменной, которую ожидаем. Если мы передадим
* объект, который не имплиментирует нужный интерфейс, то будет ошибка.
*
* @param UserInterface $user
*/
public function actionTest(UserInterface $user)
{
$name = $user->getFirstName();
...
}
}
Route::any('{page}', 'PageHandlerController@handle')->where('page', '^(?!admin).*');
class PageHandlerController extends Controller
{
public function handle($page)
{
$page = CustomPage::where('url', $page)->first();
if (!$page) {
abort(404);
}
// тут делаем все что нам угодно
}
$form = ActiveForm::begin([
'id' => 'form-input-example',
'options' => [
'onsubmit' => 'sendAjax(this, myAction)'
],
]);
...
var myAction = function (response) {
//Делаем то, что нам нужно с ответом
console.log(response);
}
function sendAjax(form, callback) {
$.ajax({
method: 'post',
url: '/test',
dataType: 'json',
data: $(form).serialize()
}).done(function (response) {
callback(response);
})
//Возвращаем false чтобы форма не отправилась
return false;
}
try {
//Тут что то делаем с сокетом
fsockopen();
} catch (ErrorException $e) {
//Что то пошло не так - обработаем исключение, например, так:
echo $e->getMessage();
}