I'm having a problem. What I'm trying to do is create basic package for geolocation. I'm using workbench to create the package and there is only one source and one config file. Plus the API that I'm using. Here's my GeoLocation class
<?php namespace EvansEric\GeoLocate;
require('ip2locationlite.class.php');
class GeoLocate{
public function gip()
{
echo 'test';
}
public function gCountry()
{
echo 'test';
}
}
And here's my config file
<?php
return array(
/**
*
* # Set the API Key obtained from ipinfodb.com
*/
'key' => '',
/**
*
* # Set Refresh rate. Set to 0 by default
*/
'refresh' => 0,
/**
*
* # Set default location
*/
'default_location' => '216.110.94.228',
);
I have my package register in the app config on the main application. EvansEric\GeoLocate
But I can't use it in my application. Keeps saying it can't find class. But I'm looking at the class and I know it's there. Please help.
Related
I have the Laravel project with websocket. I cloned the project on server with cPanel. Now I can access the running Laravel project through a sub domain like https://app.example.com. But I can not able to use the websocket with that domain name, because time out.
The websocket which I using is wss. I used the following command to run the websocket : php artisan websocketsecure:init. The command is running successfully, but I can't able to use. I tried the following address wss://app.example.com:8090
How can I access the secure websocket in the Laravel project?
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use React\EventLoop\Factory;
use React\Socket\SecureServer;
use React\Socket\Server;
use App\Http\Controllers\WebSocketController;
class WebSocketSecureServer extends Command
{
/**
* The name and signature of the console command.
*
* #var string
*/
protected $signature = 'websocketsecure:init';
/**
* The console command description.
*
* #var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* #return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* #return mixed
*/
public function handle()
{
$loop = Factory::create();
$webSock = new SecureServer(
new Server('0.0.0.0:8090', $loop),
$loop,
array(
'local_cert' => '/apache/conf/ssl.crt/server.crt', // path to your cert
'local_pk' => '/apache/conf/ssl.key/server.key', // path to your server private key
'allow_self_signed' => TRUE, // Allow self signed certs (should be false in production)
'verify_peer' => FALSE
)
);
// Ratchet magic
$webServer = new IoServer(
new HttpServer(
new WsServer(
new WebSocketController()
)
),
$webSock
);
$loop->run();
}
}
Well to run websockets you have 2 requirements basically:
be able to run the service (check, you can do that apparently)
Access the server (your server probably doesn't have port 8090 open to the outside world)
The last part is probably where your problem lies.
I have Location Policy and one api and one custom helper for both i want to use same policy,
Here is example :
1. Routes/API to read location record :
Route::group(['middleware' => 'policy:view,location'], function () {
// Read location
Route::post('/locations/{location_id}', [
'uses' => 'LocationApiController#read'
]);
});
2. Custom Function/Helper to read location record
LocationHelper.php
/**
* Class LocationHelper.
*/
class LocationHelper
{
/** #var LocationRepositoryInterface */
private $locationRepo;
/**
* ReminderHelper constructor.
*/
public function __construct()
{
$this->locationRepo = App::make(LocationRepositoryInterface::class);
}
/**
* #param int $locationId
*/
public function readLocation($locationId)
{
$this->locationRepo->read($locationId);
}
}
Problem is :
While calling location read route/api policy will apply, and while calling read funtion from LocationHelper.php it will not apply
What i want is apply same policy for both.
Is there any way to do this ??
You can call the policy manually, after retrieving the user. For example:
$allowed = Auth::user()->can('view', Location::firstOrFail($locationId));
Return a 403 if when the user is not allowed to view the resource, like this:
abort_unless($allowed, 403);
I have a Behat FeatureContext for which I want to swap a Laravel implementation of a given class with a mocked one.
so I have this method, with a #beforeSuite annotation
/**
* #static
* #beforeSuite
*/
public static function mockData()
{
$unitTesting = true;
$testEnvironment = 'acceptance';
$app = require_once __DIR__.'/../../../bootstrap/start.php';
$app->boot();
$fakeDataRetriever = m::mock('My\Data\Api\Retriever');
$fakeData = [
'fake_name' => 'fake_value'
];
$fakeDataRetriever->shouldReceive('getData')->andReturn($fakeData);
$app->instance('My\Data\Api\Retriever', $fakeDataRetriever);
}
So I see the Laravel app and the fake data being swapped, but when I run Behat, it is being ignored, meaning Laravel is using the actual implementation instead of the fake one.
I'm using Laravel 4.2
Does someone know a way to swap Laravel implementations when running Behat?
The reason I need this is because the data is coming from remote API and I want the test to run without hitting the API.
I'm not too familiar with Behat besides what I just read in a quick tutorial to see if I can help found here... http://code.tutsplus.com/tutorials/laravel-bdd-and-you-lets-get-started--cms-22155
It looks like you are creating a new instance of Laravel, setting an instance implementation inside of it, then you are not doing anything with the Laravel instance. What's likely happening next is the testing environment is then going ahead and using its own instance of Laravel to run the tests on.
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
use PHPUnit_Framework_Assert as PHPUnit;
use Symfony\Component\DomCrawler\Crawler;
use Illuminate\Foundation\Testing\ApplicationTrait;
/**
* Behat context class.
*/
class LaravelFeatureContext implements SnippetAcceptingContext
{
/**
* Responsible for providing a Laravel app instance.
*/
use ApplicationTrait;
/**
* Initializes context.
*
* Every scenario gets its own context object.
* You can also pass arbitrary arguments to the context constructor through behat.yml.
*/
public function __construct()
{
}
/**
* #BeforeScenario
*/
public function setUp()
{
if ( ! $this->app)
{
$this->refreshApplication();
}
}
/**
* Creates the application.
*
* #return \Symfony\Component\HttpKernel\HttpKernelInterface
*/
public function createApplication()
{
$unitTesting = true;
$testEnvironment = 'testing';
return require __DIR__.'/../../bootstrap/start.php';
}
/**
* #static
* #beforeSuite
*/
public function mockData()
{
$fakeDataRetriever = m::mock('My\Data\Api\Retriever');
$fakeData = [
'fake_name' => 'fake_value'
];
$fakeDataRetriever->shouldReceive('getData')->andReturn($fakeData);
$this->app->instance('My\Data\Api\Retriever', $fakeDataRetriever);
}
}
Is there any event like onafterConfirmorder in virtuemart ?
like in joomla onAfterRender,onBeforeRender events.
i want to execute code after order has been confirm .
Maybe the path is different in Joomla 2 or 3?
In Joomla 1.5 there is no path like:
ROOT_PATH\folder_name\administrator\components\com_virtuemart\models\order.php
Only the following path exists:
ROOT_PATH\folder_name\administrator\components\com_virtuemart\classes\ps_order.php
Better you have to create a plugin for this concept.
First you need to find the ORDER section in Virtumart. The following model file contains all the order functionality.
ROOT_PATH\folder_name\administrator\components\com_virtuemart\models\order.php
In this file you have to find where the order has been completed. In that section once the order was completed you have to trigger this plugin process your functionality.
You can call any event of plugin which is defined in that plugin.
$dispatcher = JDispatcher::getInstance();
$data = array($argu1, $argu2); // any number of arguments you want
return $dispatcher->trigger(onAfterRender, $data);
Then it will trigger the onAfterRender event in plugin which you created.
<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.plugin.plugin' );
/**
* Example system plugin
*/
class plgSystemExample extends JPlugin
{
/**
* Constructor.
*
* #access protected
* #param object $subject The object to observe
* #param array $config An array that holds the plugin configuration
* #since 1.0
*/
public function __construct( &$subject, $config )
{
parent::__construct( $subject, $config );
// Do some extra initialisation in this constructor if required
}
/**
* Do something onAfterRender
*/
function onAfterRender()
{
}
}
Like this you have to create your plugin..
All the best....
I'm new to codeigniter and building web applications using MVC. I'm trying to wrap my head around how I would implement widgets in a modular fashion in my application. My question is more theoretical at this point. I don't have actual code to show.
What I want to know is this, how would I construct a data-driven widget in such a way that I can simply drop it on to any page that I want. For example, let's say I have a widget called Widget. I've created a model file called /models/widget_model.php. I then have a controller file called /controllers/widget.php. Obviously my controller will use the model to grab necessary data from my database. What I don't understand is how to use this as a widget dropped onto multiple views. What I'm seeing and understand so far is how to use a controller to drive a specific view. So it's basically like one controller is used per page. What would be the process of using this widget in a modular fashion I guess?
What you search for is HMVC. There are two common library/packages you can use : Modular CI or HMVC. With that, you can actually put something like <?php echo Modules::run('module/controller/method', $param, $...); ?> as a widget, in your view files.
You can do it via drivers. Send the controller as an object reference to the driver to use view class. Then you just load drivers and use them as plugins.
Edit:
Here is the code I use in my application:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter base widget driver
*
* #author Alex
* #version 1.0.0
*/
class Basedriver {
/**
* Current specified controller.
* #var CI_Controller
*/
public $controller;
/**
* Contents of the driver which should be outputted or returned.
* #var string
*/
protected $contents;
/**
* Loader Class
* #var CI_Loader
*/
protected $load;
/**
* Constructor function for Basedriver class
*/
public function __construct()
{
$this->controller =& get_instance();
$this->load = $this->controller->load;
}
/**
* Renders driver data into specified output. If $echo_contents is true,
* output is echoed to the client, otherwise it is returned.
* #param boolean $echo_contents Specifies whether the content should be outputted or returned as string
* #param mixed $params Array of parameters which should be sent to the driver
* #return string Returned driver data if $echo_contents is set
*/
public function render($params = NULL, $echo_contents = true)
{
$this->parse_params($params);
$this->run();
if ($echo_contents)
echo $this->contents;
else
return $this->contents;
return NULL;
}
/**
* Default run function for all drivers, should be overidden by extending classes.
*/
protected function run()
{
$this->contents = NULL;
}
/**
* Parses parameters and sets them as variables.
* Default variables need to be defined in extending class
*/
protected function parse_params($params)
{
if ($params === NULL) return;
foreach($params as $variable => $value)
{
if (isset($this->$variable))
$this->$variable = $value;
}
}
}
/* End of file Basedriver.php */
/* Location: ./application/libraries/Basedriver.php */
Load class is there to allow you to use view class and controller is there to allow you to use database functions and to give you some other access if you need it. This class needs to be loaded before all other drivers (widgets) and all drivers (widgets) need to extend this class. You can do this by adding 'basedriver' in $config['libraries'] array in application/config/autoload.php.
Example Driver Widget:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Example extends Basedriver
{
protected $parameter1 = 'defaultvalueparam1';
protected $parameter2 = 'defaultvalueparam2';
protected function run()
{
// Widget logic here...
// you can use $this->load->view and $this->controller->db here
$this->contents = 'final_processed_data_here';
}
}
/* End of file Example.php */
/* Location: ./application/libraries/Example/Example.php */
To use the driver which extends Basedriver as a widget, example:
$this->load->driver('example');
$this->example->render(array('parameter1' => '1', 'parameter2' => '2'));
I think you could simply using CI's view system. You create a view per widget, then you inject any variable you want from your model, and finally you display the resulting HTML anywhere you want. I can't think of any particular difficulty.