I'm trying to learn about Events in Doctrine, but when I read the docs, I get stuck at the very first line:
$evm = new EventManager();
Here I get a
PHP Fatal error: Class 'EventManager' not found
How can I solve this issue?
Here is the complete code:
use Doctrine\ORM\Tools\Setup;
require_once("Doctrine/ORM/Tools/Setup.php");
Setup::registerAutoloadPEAR();
$classLoader = new Doctrine\Common\ClassLoader('Entities', __DIR__);
$classLoader->register();
$paths = array();
$isDevMode = true;
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
$dbParams = array("driver" => "pdo_mysql",
"host" => variable_get("dbManip_host"),
"user" => variable_get("dbManip_user"),
"password" => variable_get("dbManip_password"),
"dbname" => variable_get("dbManip_dbName"),
"charset" => "utf8");
global $entityManager_globalObject;
$entityManager_globalObject = \Doctrine\ORM\EntityManager::create($dbParams, $config);
$entityManager_globalObject->getConnection()->exec("SET NAMES UTF8");
$evm = new EventManager();
You are looking for class Doctrine\Common\EventManager.
$evm = new \Doctrine\Common\EventManager();
or
use Doctrine\Common\EventManager; // at the top of your file
$evm = new EventManager();
Related
I am attempting to mock out my SignalR hub for some unit tests. I am running into an issue on my Hubs OnConnectedAsync() call due to using a header to auto join a group if it exists. My issue is lying with the fact that the HubCallerContext.GetHttpContext() method is an extension method and cant be mocked. I dunno if there is a work around to this and I cant seem to find any similarly posted question about this.
OnConnectedAsync() Segment
Context.GetHttpContext().Request.Headers.TryGetValue(SignalRHeaders.GroupHeader, out StringValues header);
if (header.Any())
{
await Groups.AddToGroupAsync(Context.ConnectionId, SignalRConstants.Group);
}
Base Test Class
public DefaultHubBaseTest()
{
var memberId = Guid.NewGuid().ToString();
var orgId = Guid.NewGuid().ToString();
MockClients = new Mock<IHubCallerClients>();
MockClientProxy = new Mock<IClientProxy>();
MockClients.Setup(clients => clients.Group(It.IsAny<string>()))
.Returns(MockClientProxy.Object);
MockGroups = new Mock<IGroupManager>();
MockGroups.Setup(x => x.AddToGroupAsync(It.IsAny<string>(), It.IsAny<string>(), default(CancellationToken))).Returns(Task.CompletedTask);
MockGroups.Setup(x => x.RemoveFromGroupAsync(It.IsAny<string>(), It.IsAny<string>(), default(CancellationToken))).Returns(Task.CompletedTask);
Mock<HttpRequest> MockRequest = new Mock<HttpRequest>();
MockRequest.Setup(x => x.Headers).Returns(new HeaderDictionary()
{
{ SignalRHeaders.GroupHeader, orgId },
{ SignalRHeaders.GroupAdminHeader, "t" },
});
Mock<HttpContext> MockHttpContext = new Mock<HttpContext>();
MockHttpContext.Setup(x => x.Request).Returns(MockRequest.Object);
MockContext = new Mock<HubCallerContext>();
MockContext.Setup(x => x.ConnectionId).Returns("1");
MockContext.Setup(x => x.User.Claims).Returns(new List<Claim>() { new Claim(SignalRConstants.AzureAuthOID, memberId) });
MockContext.Setup(x => x.GetHttpContext()).Returns(MockHttpContext.Object);
DefaultHub = new DefaultHub()
{
Context = MockContext.Object,
Groups = MockGroups.Object,
Clients = MockClients.Object,
};
}
If anyone could help me with this, I would greatly appreciate it. Thanks!
I tried following code but it's give exceptions:
var mockIdsDbContext = new Mock<IdentityServerDbContext>();
var applicationUser = new ApplicationUser()
{
Id = Guid.NewGuid().ToString(),
Email = "shashikant0423#gmail.com",
PhoneNumber = "999999999"
};
var usersTestData = new List<ApplicationUser>() { applicationUser };
var users = MockDbSet(usersTestData);
mockIdsDbContext.Setup(x => x.Users).Returns(userManager.Object.Users);
Mock<DbSet<T>> MockDbSet<T>(IEnumerable<T> list) where T : class, new()
{
IQueryable<T> queryableList = list.AsQueryable();
Mock<DbSet<T>> dbSetMock = new Mock<DbSet<T>>();
dbSetMock.As<IQueryable<T>>().Setup(x => x.Provider).Returns(queryableList.Provider);
dbSetMock.As<IQueryable<T>>().Setup(x => x.Expression).Returns(queryableList.Expression);
dbSetMock.As<IQueryable<T>>().Setup(x => x.ElementType).Returns(queryableList.ElementType);
dbSetMock.As<IQueryable<T>>().Setup(x => x.GetEnumerator()).Returns(() => queryableList.GetEnumerator());
//dbSetMock.Setup(x => x.Create()).Returns(new T());
return dbSetMock;
}
but I got error like:
Can not instantiate proxy of class: RenewPlus.IdentityServer.Data.IdentityServerDbContext. Could not find a parameterless constructor
Instead of mocking the rather complex DbContext I'd recommend instead using the Microsoft.EntityFrameworkCore.InMemory driver.
https://learn.microsoft.com/en-us/ef/core/providers/in-memory/
I want to register an AWS Cognito Identity using getOpenIdTokenForDeveloperIdentity.
Below are my codes written in CodeIgniter framework:
Awscognitoauth.php
<?php
// <MYPROJECT>/application/controllers/Awscognitoauth.php
defined('BASEPATH') or exit('No direct script access allowed');
class Awscognitoauth extends CI_Controller {
function getOpenId($userId) {
$this->load->library('awsauth');
return $this->awsauth->identity($userId);
}
}
Awsauth.php
<?php
// <MY PROJECT>/application/libraries/Awsauth.php
defined('BASEPATH') or exit('No direct script access allowed');
require_once APPPATH . "third_party/aws/aws-autoloader.php";
use Aws\CognitoIdentity\CognitoIdentityClient;
use Aws\Sts\StsClient;
class Awsauth {
public function identity($userId) {
$region = '<my region>';
$key = '<my key>';
$secret = '<my secret>';
$version = 'latest';
$client = CognitoIdentityClient::factory(array('region' => $region, 'key' => $key, 'secret' => $secret, 'version' => $version));
$poolId = '<my pool Id>'; // formatted: "<region>:<UUID>"
$domain = '<my reversed company domain>'; // com.<company...>...
return $client->GetOpenIdTokenForDeveloperIdentity(array('IdentityPoolId' => $poolId, 'Logins' => array($domain => $userId))); // https://docs.aws.amazon.com/cognitoidentity/latest/APIReference/API_GetOpenIdTokenForDeveloperIdentity.html
}
}
In safari, I call the controller Awscognitoauth and get the following error:
I double-checked my user's role here:
It is AdministratorAccess
Access key does match with the key in my code
What could cause this 404 Not Found response? I thought that my user has AdministratorAccess and I can access any resource. Do I miss something?
oh shoot!
I just found out that the $key and $secret must be wrapped in credentials.
So, the final code for Awsauth.php is:
<?php
// <MY PROJECT>/iot.kooltechs.com/application/libraries
defined('BASEPATH') or exit('No direct script access allowed');
require_once APPPATH . "third_party/aws/aws-autoloader.php";
use Aws\CognitoIdentity\CognitoIdentityClient;
use Aws\Sts\StsClient;
class Awsauth {
public function identity($userId) {
$region = '<my region>';
$key = '<my key>';
$secret = '<my secret>';
$version = 'latest';
$config = [
'version' => $version,
'region' => $region,
'credentials' => [
'key' => $key,
'secret' => $secret
]
];
$client = CognitoIdentityClient::factory($config);
$poolId = '<my pool Id>'; // formatted: "<region>:<UUID>"
$domain = '<my reversed company domain>'; // com.<company...>...
return $client->GetOpenIdTokenForDeveloperIdentity(array('IdentityPoolId' => $poolId, 'Logins' => array($domain => $userId)));
}
}
Regards,
get attributes from the URI using Slim 2 Framwork
http://localhost:8080/serverEndModule1/v1/varifyid=OQ==&code=1e212ffc375e52a9c6e7debe8adcc17
using the following Code:
$app->get('/varify', function () use ($app) {
$id = $app->request->get('id');
$paramValue2 = $app->request->get('code');
$db = new DbOperation();
$response = array();
$db->userVarify($id, $code); // send to database
help me to implement the following $app->get route .
Thanks I got it now it' working
$app->get('/varify', function() use ($app){
$req = $app->request();
$id = $req->get('id'); //
$code = $req->get('code');
$db = new DbOperation();
$response = array();
$res= $db->userVarify($id, $code);
}
I read, i try, i looking informations about how add / update combinations by webservice, in presta 1.5.3 but still i don't know how to do that.
Can someone help me?
Assigning combinations to products via Webservice is a multi-step operation (unlike CSV import).
given a product with id_product
add product_options (BO Attribute Names)
add product_option_values (BO Attribute Values) to product_options
add combinations while specifying id_product
Start by initialising PrestaShopWebservice with DEBUG=true:
$api = new PrestaShopWebservice($psShopUrl, $psAuthKey, $psDebug);
Instead of building the XML from scratch get a template for the resource you need like this:
$sxml = $api->get(array('url' => $psShopUrl.'api/'.$resource.'?schema=blank'));
The response is a SimpleXMLElement which is a easier to manipulate than DOM.
NB: The response contains all wrapper nodes and you must send the same back in your request i.e. PSWebServiceLibrary will not recreate them for you.
<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<combination>
...
</combination>
</prestashop>
SXML manipulation example:
$schema = $api->get(array('url' => $psShopUrl.'api/product_options?schema=blank'));
$data = $schema->children()->children();
$data->is_color_group = false;
$data->group_type = $group_type; // radio, select
$data->name->language[0] = 'attribute private name';
$data->public_name->language[0] = 'attribute public name';
$xml = $schema->asXML(); // all of it!
$ret = $api->add(array('resource' => 'product_options', 'postXml' => $xml));
$id_attribute_group = (int)$ret->children()->children()->id; // save for next step
Then get product_option_values schema, set data and the id_attribute_group from previous step. And so on.
Updating is the same except you will get the resource by id and then edit:
$sxml = $api->get(array('resource' => $resource, 'id' => $id));
...
$ret = $api->edit(array('resource' => $resource, 'id' => $id, 'putXml' => $xml));
As for adding multiple id values to the product_option_values node in the combinations resource you can use the array_push shortcut []:
$data->associations->product_option_values->product_option_values[]->id = 123;
$data->associations->product_option_values->product_option_values[]->id = 456;
This is work fine for me :
$webService = new PrestaShopWebservice($url, $api_key, FALSE);
$xml = $webService->get(array('url' => $url .'/api/combinations?schema=blank'));
$resources = $xml->children()->children();
$resources->id_product = $ps_product_id;
$resources->wholesale_price = $wholesale_price;
$resources->price = $price;
$resources->unit_price_impact = $unit_price_impact;
$resources->minimal_quantity = $minimal_quantity;
$resources->quantity = $quantity;
$resources->weight = $weight;
$resources->associations->product_option_values->product_option_value[0]->id = $color_id;
$resources->associations->product_option_values->product_option_value[1]->id = $size_id;
$request = $xml->asXML();
//This is a function that curl request to specific URL using method (POST)
$response = ps_curl($url . '/api/combinations', $request, 'POST', $api_key);
$xml_load = simplexml_load_string($response);
$id = $xml_load->combination->id;
I hope that's helpful :)