Class 'Aws\Common\Aws' not found cakephp - php

I am using AWS PHP SDK V2.8 in my cakephp. I am working on AWS ec2 ubuntu machine.
I use zip files not any composer.
I am getting following error.
Class 'Aws\Common\Aws' not found
I create a custom component for accessing all features of SDK. with the reference of https://github.com/Ali1/cakephp-amazon-aws-sdk
My folder structure is as follows
Here is my AmazonComponent.php
<?php
App::uses('Component', 'Controller');
use Aws\Common\Aws;
/**
* AmazonComponent
*
* Provides an entry point into the Amazon SDK.
*/
class AmazonComponent extends Component {
/**
* Constructor
* saves the controller reference for later use
* #param ComponentCollection $collection A ComponentCollection this component can use to lazy load its components
* #param array $settings Array of configuration settings.
*/
public function __construct(ComponentCollection $collection, $settings = array()) {
$this->_controller = $collection->getController();
parent::__construct($collection, $settings);
}
/**
* Initialization method. Triggered before the controller's `beforeFilfer`
* method but after the model instantiation.
*
* #param Controller $controller
* #param array $settings
* #return null
* #access public
*/
public function initialize(Controller $controller) {
// Handle loading our library firstly...
$this->Aws = Aws::factory(Configure::read('Amazonsdk.credentials'));
}
/**
* PHP magic method for satisfying requests for undefined variables. We
* will attempt to determine the service that the user is requesting and
* start it up for them.
*
* #var string $variable
* #return mixed
* #access public
*/
public function __get($variable) {
$this->$variable = $this->Aws->get($variable);
return $this->$variable;
}
}
I add these two line on the top on file with the reference of this question
How to load AWS SDK into CakePHP?
ini_set('include_path', ROOT . DS . 'lib' . PATH_SEPARATOR . ini_get('include_path'). PATH_SEPARATOR . ROOT .DS . 'app/Plugin/Amazonsdk/Vendor/aws');
require ROOT . DS . 'app/Plugin/Amazonsdk/Vendor/aws/aws-autoloader.php';
Where I am wrong and how can I fix that?

#urfusion Could you pls move AWS SDK folder from app/Plugin to app/Vendor In Side the app/Vendor And then try to import aws-sdk AmazonComponent having Function initialize.
I am using AWS PHP SDK V3
// Handle loading our library firstly...
App::import('Vendor','aws-autoloader',array('file'=>'aws'.DS.'aws-autoloader.php'));

Related

Symfony incompatibilities. The LoaderInterface and the XmlFileLoader have an issue

Situation:
This is the screen message I became after installing tikiwiki 24.
Fatal error: Declaration of Symfony\Component\DependencyInjection\Loader\XmlFileLoader::load($resource, ?string $type = NULL) must be compatible with Symfony\Component\Config\Loader\LoaderInterface::load($resource, $type = NULL) in /var/www/contiki/vendor/symfony/dependency-injection/Loader/XmlFileLoader.php on line 46
So please, does anyone have a clue what's going on here? I'm quite new to composer, solved many compatibility issues but this is out of my range.
I don't understand why they are incompatible.
These are (part) of the files:
My /var/www/contiki/vendor_bundled/vendor/symfony/config/Loader/LoaderInterface.php
interface LoaderInterface
{
/**
* Loads a resource.
*
* #param mixed $resource The resource
* #param string|null $type The resource type or null if unknown
*
* #throws \Exception If something went wrong
*/
public function load($resource, $type = null);
/**
* Returns whether this class supports the given resource.
*
* #param mixed $resource A resource
* #param string|null $type The resource type or null if unknown
*
* #return bool True if this class supports the given resource, false otherwise
*/
public function supports($resource, $type = null);
/**
* Gets the loader resolver.
*
* #return LoaderResolverInterface A LoaderResolverInterface instance
*/
public function getResolver();
/**
* Sets the loader resolver.
*/
public function setResolver(LoaderResolverInterface $resolver);
}
The first part of the /var/www/contiki/vendor_bundled/vendor/symfony/dependency-injection/Loader/XmlFileLoader.php file
namespace Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\Config\Util\XmlUtils;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\Argument\BoundArgument;
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\ExpressionLanguage\Expression;
/**
* XmlFileLoader loads XML files service definitions.
*
* #author Fabien Potencier <fabien#symfony.com>
*/
class XmlFileLoader extends FileLoader
{
const NS = 'http://symfony.com/schema/dic/services';
/**
* {#inheritdoc}
*/
public function load($resource, $type = null)
{
$path = $this->locator->locate($resource);
$xml = $this->parseFileToDOM($path);
$this->container->fileExists($path); <-- This is rule 46
$defaults = $this->getServiceDefaults($xml, $path);
// anonymous services
$this->processAnonymousServices($xml, $path, $defaults);
// imports
$this->parseImports($xml, $path);
// parameters
$this->parseParameters($xml, $path);
// extensions
$this->loadFromExtensions($xml);
// services
try {
$this->parseDefinitions($xml, $path, $defaults);
} finally {
$this->instanceof = [];
}
}```
Sounds like something's got tangled up here, Tiki 24 is not out yet but will be branching soon, so if you want a stable safe Tiki now, probably best to use a stable released branch, i.e. 23.x? Also, we are still on Smarty 3.x and plan to upgrade to 4.x (and PHP 8+) after the release of 24 which is our next LTS version, so not sure where that is coming from... did you run sh setup.sh?
As Nico said above, this is probably more Tiki-specific than is suitable for here, so the best thing would be to come and chat with the community in our new Gitter room, here?
Welcome to Tiki! :)

How Is The Correct Way To Use CLI Command In Codeigniter 4 To Execute Controller

I have a problem when using CLI command In codeigniter 4. I want to call or execute controller from CLI codeigniter 4.
I have a controller file and folder structure :
Edit :
mywebapp\app\Controllers\ExportAlert.php
And this is the Code inside ExportAlert.php :
<?php
namespace App\Controllers;
use CodeIgniter\Controller;
class ExportAlert extends Controller
{
function __construct()
{
}
public function index()
{
}
public function ExportAlert() {
if ($this->request->isCLI()) {
echo "Ok"; }
else {
echo "Not allowed";
}
}
}
And My Folder Structure :
I try to execute the CLI command :
E:\Codeigniter4\mywebapp>php public/index.php ExportAlert ExportAlert
And it return :
ERROR: 404 Controller or its method is not found: ExportAlert::ExportAlert
What I have missing in here ? How is the correct way to use CLI command to call a controller in codeigniter 4 ?
Thank You
first:
remove index.php in url
go to app/config/app.php
public $indexPage = '';
second:
app/confi/authload.php
call you modules like me
<?php
namespace Config;
use CodeIgniter\Config\AutoloadConfig;
/**
* -------------------------------------------------------------------
* AUTOLOADER CONFIGURATION
* -------------------------------------------------------------------
*
* This file defines the namespaces and class maps so the Autoloader
* can find the files as needed.
*
* NOTE: If you use an identical key in $psr4 or $classmap, then
* the values in this file will overwrite the framework's values.
*/
class Autoload extends AutoloadConfig
{
/**
* -------------------------------------------------------------------
* Namespaces
* -------------------------------------------------------------------
* This maps the locations of any namespaces in your application to
* their location on the file system. These are used by the autoloader
* to locate files the first time they have been instantiated.
*
* The '/app' and '/system' directories are already mapped for you.
* you may change the name of the 'App' namespace if you wish,
* but this should be done prior to creating any namespaced classes,
* else you will need to modify all of those classes for this to work.
*
* Prototype:
*```
* $psr4 = [
* 'CodeIgniter' => SYSTEMPATH,
* 'App' => APPPATH
* ];
*```
* #var array<string, string>
*/
public $psr4 = [
APP_NAMESPACE => APPPATH, // For custom app namespace
'Config' => APPPATH . 'Config',
'Modules\Shared' => ROOTPATH . 'module/shared',
'Modules\Common' => ROOTPATH . 'module/common',
'Modules\Auth' => ROOTPATH . 'module/auth',
'Modules\Home' => ROOTPATH . 'module/home',
'Modules\Payment' => ROOTPATH . 'module/payment',
];
/**
* -------------------------------------------------------------------
* Class Map
* -------------------------------------------------------------------
* The class map provides a map of class names and their exact
* location on the drive. Classes loaded in this manner will have
* slightly faster performance because they will not have to be
* searched for within one or more directories as they would if they
* were being autoloaded through a namespace.
*
* Prototype:
*```
* $classmap = [
* 'MyClass' => '/path/to/class/file.php'
* ];
*```
* #var array<string, string>
*/
public $classmap = [];
/**
* -------------------------------------------------------------------
* Files
* -------------------------------------------------------------------
* The files array provides a list of paths to __non-class__ files
* that will be autoloaded. This can be useful for bootstrap operations
* or for loading functions.
*
* Prototype:
* ```
* $files = [
* '/path/to/my/file.php',
* ];
* ```
* #var array<int, string>
*/
public $files = [];
}
There are few changes you need to make here:
First, it extends to Controller and Not BaseController.
So replace BaseController use statement with use CodeIgniter\Controller;
Second, you do not need routes defined for this. So remove them.
php index.php ExportAlert ExportAlert
should be
php public/index.php ExportAlert ExportAlert
Also, you haven't defined anything in the body so for testing try to enter some data on CLI using CLI's write method.

Missing system injecting dependencies using vanilla php

I'm trying to get my app working, Its a vanilla php, I have 2 services with one dependent on other. I'm running service from the bootstrap, which requires simple SplClassLoader.
The directory structure (Slightly simplified):
-src
-logic
-Service
-CustomService.php
-DataProviderService.php
-SplClassLoader.php
-test
-bootstrap.php
Bootstrap:
<?php
require __DIR__ . '/../src/SplClassLoader.php';
$oClassLoader = new \SplClassLoader('logic', __DIR__ . '/../src');
$oClassLoader->register();
$service = new logic\Service\CustomService;
$service->execute();
SplClassLoader:
<?php
/**
* SplClassLoader implementation that implements the technical interoperability
* standards for PHP 5.3 namespaces and class names.
*
* http://groups.google.com/group/php-standards/web/final-proposal
*
* // Example which loads classes for the Doctrine Common package in the
* // Doctrine\Common namespace.
* $classLoader = new SplClassLoader('Doctrine\Common', '/path/to/doctrine');
* $classLoader->register();
*
* #author Jonathan H. Wage <jonwage#gmail.com>
* #author Roman S. Borschel <roman#code-factory.org>
* #author Matthew Weier O'Phinney <matthew#zend.com>
* #author Kris Wallsmith <kris.wallsmith#gmail.com>
* #author Fabien Potencier <fabien.potencier#symfony-project.org>
*/
class SplClassLoader
{
private $_fileExtension = '.php';
private $_namespace;
private $_includePath;
private $_namespaceSeparator = '\\';
/**
* Creates a new <tt>SplClassLoader</tt> that loads classes of the
* specified namespace.
*
* #param string $ns The namespace to use.
*/
public function __construct($ns = null, $includePath = null)
{
$this->_namespace = $ns;
$this->_includePath = $includePath;
}
/**
* Sets the namespace separator used by classes in the namespace of this class loader.
*
* #param string $sep The separator to use.
*/
public function setNamespaceSeparator($sep)
{
$this->_namespaceSeparator = $sep;
}
/**
* Gets the namespace seperator used by classes in the namespace of this class loader.
*
* #return void
*/
public function getNamespaceSeparator()
{
return $this->_namespaceSeparator;
}
/**
* Sets the base include path for all class files in the namespace of this class loader.
*
* #param string $includePath
*/
public function setIncludePath($includePath)
{
$this->_includePath = $includePath;
}
/**
* Gets the base include path for all class files in the namespace of this class loader.
*
* #return string $includePath
*/
public function getIncludePath()
{
return $this->_includePath;
}
/**
* Sets the file extension of class files in the namespace of this class loader.
*
* #param string $fileExtension
*/
public function setFileExtension($fileExtension)
{
$this->_fileExtension = $fileExtension;
}
/**
* Gets the file extension of class files in the namespace of this class loader.
*
* #return string $fileExtension
*/
public function getFileExtension()
{
return $this->_fileExtension;
}
/**
* Installs this class loader on the SPL autoload stack.
*/
public function register()
{
spl_autoload_register(array($this, 'loadClass'));
}
/**
* Uninstalls this class loader from the SPL autoloader stack.
*/
public function unregister()
{
spl_autoload_unregister(array($this, 'loadClass'));
}
/**
* Loads the given class or interface.
*
* #param string $className The name of the class to load.
* #return void
*/
public function loadClass($className)
{
if (null === $this->_namespace || $this->_namespace.$this->_namespaceSeparator === substr($className, 0, strlen($this->_namespace.$this->_namespaceSeparator))) {
$fileName = '';
$namespace = '';
if (false !== ($lastNsPos = strripos($className, $this->_namespaceSeparator))) {
$namespace = substr($className, 0, $lastNsPos);
$className = substr($className, $lastNsPos + 1);
$fileName = str_replace($this->_namespaceSeparator, DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
}
$fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . $this->_fileExtension;
require ($this->_includePath !== null ? $this->_includePath . DIRECTORY_SEPARATOR : '') . $fileName;
}
}
}
So yeah, Im running php php bootstrap.php and getting error that too few arguments passed into contructor. How to make bootstrap load dependency injections? How I should make it work? Can I use some kind of service container of phpunit maybe? Its a clue I have been given. No idea if I did explain problem well enough, but hope I did! :)
Error message:
PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function logic\Service\CustomService::execute(), 0 passed in /.../test/bootstrap.php on line 12 and exactly 1 expected in /.../Service/CustomService.php:23
Stack trace:
#0 /.../test/bootstrap.php(12): logic\Service\CustomService->execute()
#1 {main}
thrown in /.../logic/Service/CustomService.php on line 23

PHP - How can I test this class?

I'm just getting started with PHPUnit and I'm struggling on how to test certain features. For example, I've got the following class with loads the DotEnv library, and I'd like to test the following features...
Test the variables are loaded
Test it doesn't if the config is already cached
Test it throws an exception if a required variable is missing
But I'm struggling with the best way to do this $app->configurationIsCached() is managed elsewhere so blocks then rest of the class from executing.
<?php declare(strict_types=1);
namespace Foundation\Bootstrap;
use Dotenv\Dotenv;
use Foundation\Core;
class LoadEnvironmentVariables
{
/**
* Any required variables.
*
* #var array
*/
protected $required = [
'APP_URL',
'DB_NAME',
'DB_USER',
'DB_PASS',
'DB_HOST'
];
/**
* Creates a new instance.
*
* #param Core $app The application instance.
*/
public function __construct(Core $app)
{
// If the configuration is cached, then we don't need DotEnv.
if ($app->configurationIsCached()) {
return;
}
// Load the DotEnv instance
$this->load($app->get('paths.base'));
}
/**
* Loads the .env file at the given path
*
* #param string $filePath The path to the .env file
* #return void
*/
public function load(string $filePath)
{
$dotEnv = Dotenv::create($filePath);
$dotEnv->safeLoad();
$dotEnv->required($this->required);
}
}
Regarding your code getting tied up on the $app->configurationIsCached():
Use something like Mockery to create a mock of your Core class you're passing in as $app to your class. You can then mock configurationIsCached(), having it return whatever is needed to route your class through to the early return or the call to your load() method.

Trouble loading PHP Class within the same project

Someone could help me on the issue of referencing php files within the same project (calling classes) using "namespace","use" ( php v5.3 or higher) [My Screenshoot][http://i.imgur.com/6GC4UUK.png?1]
Zoho\
CRM\
Common\
-HttpClientInterface.php
Config\
Entities\
Exception\
Request\
Wrapper\
index.php
I've read about autoloading classes but I don't undersand very well..
Fatal error: Class 'Zoho\CRM\Common\HttpClientInterface' not found in C:\root\zohocrm-master\src\Zoho\CRM\index.php on line 73
<?php namespace Zoho\CRM;
use Zoho\CRM\Common\HttpClientInterface;
use Zoho\CRM\Common\FactoryInterface;
use Zoho\CRM\Request\HttpClient;
use Zoho\CRM\Request\Factory;
use Zoho\CRM\Wrapper\Element;
.
.
.
public function __construct($authtoken, HttpClientInterface $client =null , FactoryInterface $factory = null )
{
$this->authtoken = $authtoken;
// Only XML format is supported for the time being
$this->format = 'xml';
$this->client = new HttpClientInterface();
$this->factory = $factory ;
$this->module = "Leads";
return $this;
}
This is my class file :
<?php namespace Zoho\CRM\Common;
/**
* Common interface for Http clients
*
* #package Zoho\CRM\Common
* #version 1.0.0
*/
interface HttpClientInterface
{
/**
* Performs POST request.
*
* #param string $uri Direction to make the post
* #param string $postBody Post data
*/
public function post($uri, $postBody);
}

Categories