Получается из assertion-а к БД никак не обратиться?
Надо делать запросы в каком-то другом месте?
class IsUserDrunkAssertionFactory implements FactoryInterface
{
static protected $objectManager;
public function createService(ServiceLocatorInterface $serviceLocator)
{
static::$objectManager = $serviceLocator->get('doctrine.entitymanager.orm_default');
$assertion = new IsUserDrunkAssertion();
return $assertion;
}
static public function getObjectManager()
{
return static::$objectManager;
}
}
class IsUserDrunkAssertion implements AssertionInterface
{
public function assert(Acl $acl, RoleInterface $role = null, ResourceInterface $resource = null, $privilege = null)
{
$objectManager = IsUserDrunkAssertionFactory::getObjectManager();
$decision = // ... здесь бы запрос сделать
return $decision;
}
}
if ($form->isValid()) {
$data = $form->getData($form::VALUES_AS_ARRAY);
$authService = $this->getServiceLocator()->get('AuthenticationService');
$authService->getAdapter()->setIdentity($data['identity'])->setCredential($data['password']);
$result = $authService->authenticate();
if (!$result->isValid()) {
switch ($result->getCode()) {
case $result::FAILURE_IDENTITY_NOT_FOUND :
$form->get('identity')->setMessages(['Неверный логин']);
break;
case $result::FAILURE_CREDENTIAL_INVALID :
$form->get('password')->setMessages(['Неверный пароль']);
break;
default :
$form->get('identity')->setMessages(['Ошибка авторизации']);
break;
}
}
}
return array(
'param_bool' => true,
'param_str' => 'value',
'param_array' => array(1, 2, 3),
// ...
// А ещё можно так:
'param_object' => (object) array(
'prop' => 'value',
),
'param_function' => function ($param) { /* ... */ }
);
$config = include 'config.php';
Насколько понимаю, если хранить это всё в ini, то придётся потом все значения очень серьёзно парсить, чтобы получить PHP-массив например.
$jsonError->error='No function called';
, PHP в данном случае неявно создаёт объект stdClass. Делать так не желательно, т. к. PHP сделает предупреждение: <?php
header('Content-type: text/html; charset=UTF-8');
if (count($_REQUEST)>0){
// ...
}else{
$jsonError = new stdClass();
$jsonError->error = 'No function called';
echo json_encode($jsonError);
}
?>
смысл $this нигде не объясняют
return $this
- делается это для реализации цепочек вызовов (Method Chaining).public function sendAction()
{
$page_id = $this->_getParam('page_id');
$topic_id = $this->_getParam('topic_id');
$subject = $this->_getParam('subject');
$message = $this->_getParam('message');
$senderName = $this->_getParam('sender_name');
$senderEmail = $this->_getParam('sender_email');
$birthDate = $this->_getParam('birthdate'); //
$address = $this->_getParam('address'); //
$country = $this->_getParam('country'); //
$postal = $this->_getParam('postal'); //
$pagesTbl = Engine_Api::_()->getDbTable('pages', 'page');
$select = $pagesTbl->select()
->from(array($pagesTbl->info('name')), array('displayname'))
->where('page_id = ?', $page_id);
$query = $select->query();
$result = $query->fetchAll();
$pageName = $result[0]['displayname'];
$viewer = $this->_helper->api()->user()->getViewer();
$user_id = $viewer->getIdentity();
$topicsTbl = Engine_Api::_()->getDbTable('topics', 'pagecontact');
$emails = $topicsTbl->getEmails($page_id, $topic_id);
$i = 0;
$emails = explode(',',$emails);
foreach($emails as $email) {
$emails[$i] = trim($email);
$i++;
}
if ($user_id != 0) {
$senderName = $viewer['displayname'];
$senderEmail = $viewer['email'];
}
$message .= "\r\nBirthdate: " . $birthDate
. "\r\nAddress: " . $address
. "\r\nCountry: " . $country
. "\r\nPostal: " . $postal;
foreach($emails as $email) {
// Make params
$mail_settings = array(
'date' => time(),
'page_name' => $pageName,
'sender_name' => $senderName,
'sender_email' => $senderEmail,
'subject' => $subject,
'message' => $message,
);
// send email
Engine_Api::_()->getApi('mail', 'core')->sendSystem(
$email,
'pagecontact_template',
$mail_settings
);
}
}
namespace Application\View\Model;
use Zend\View\Model\JsonModel as ZendJsonModel;
class JsonModel extends ZendJsonModel
{
/**
* {@inheritDoc}
*/
public function serialize()
{
return (parent::serialize() . "\r\n");
}
}
namespace Application\View\Helper;
use Zend\View\Helper\AbstractHelper;
use Zend\Form\View\Helper\FormTextarea;
use Zend\Form\ElementInterface;
use HTMLPurifier;
use HTMLPurifier_Config;
use HTMLPurifier_ConfigSchema;
use Soflomo\Purifier\View\Helper\Purifier;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorAwareTrait;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\ServiceManager\AbstractPluginManager;
class PurefierFormTextarea extends FormTextarea implements ServiceLocatorAwareInterface
{
protected $serviceLocator = null;
public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
{
$this->serviceLocator = $serviceLocator;
return $this;
}
public function getServiceLocator()
{
return $this->serviceLocator;
}
public function getMainServiceLocator()
{
if ($this->serviceLocator instanceof AbstractPluginManager) {
return $this->serviceLocator->getServiceLocator();
}
return $this->serviceLocator;
}
public function render(ElementInterface $element)
{
// ...
$this->getMainServiceLocator()->get('HTMLPurifier');
// ...
}
}
$filterManager = $this->getServiceLocator()->get('FilterManager');
$factory = new Zend\Form\Factory();
$factory->getInputFilterFactory()
->getDefaultFilterChain()
->setPluginManager($filterManager);
class Module implements Zend\ModuleManager\Feature\FilterProviderInterface
{
// ...
/**
* {@inheritDoc}
*/
public function getFilterConfig()
{
return [
'invokables' => [
'myfilter' => \Application\Filter\MyFilter::class,
],
];
}
}
var data = {
name: 'Jane Doe'
}
$('.updates').append( template(data) );
class iaComment
{
// Метод можно сделать static
static public function smileToSmile() {
$smiles = array(
':)' => '<img alt=":)" src="' . IA_URL . 'plugins/comments/templates/front/img/smiles/smile.png">',
'=)' => '<img alt="=)" src="' . IA_URL . 'plugins/comments/templates/front/img/smiles/smile.png">',
':(' => '<img alt=":(" src="' . IA_URL . 'plugins/comments/templates/front/img/smiles/sad.png">',
'=(' => '<img alt="=(" src="' . IA_URL . 'plugins/comments/templates/front/img/smiles/sad.png">',
':D' => '<img alt=":D" src="' . IA_URL . 'plugins/comments/templates/front/img/smiles/happy.png">',
':\'(' => '<img alt=":\'(" src="' . IA_URL . 'plugins/comments/templates/front/img/smiles/cry.png">'
);
return array(array_keys($smiles), array_values($smiles));
}
// ...
}
// Получаем массив один раз (вне цикла), чтобы каждый раз не дёргать класс
$smiles = iaComment::smileToSmile();
foreach ($comments as &$comment) {
$comment['body'] = str_replace($smiles[0], $smiles[1], $comment['body']);
}