I am testing out the Gitonomy Library within PHP and something I just cannot put my finger on. I have created a small application found here with a class that uses the Repository class from the library to list available branches on GITHUB Remote REposictory. Below is the class:
namespace LuSoft\Library{
use Gitonomy\Git\Repository as RemoteRepositroy;
class Repository
{
public function getBranches($repository)
{
if(!is_string($repository)){
throw new Exception("Reposotory must be in a form of a string.");
}
$rr = new RemoteRepositroy($repository);
$branches = [];
foreach($rr->getReferences()->getBranches() as $branch){
$branches[] = $branch->getName();
}
$rr->run('fetch', array('--all'));
return $branches;
}
}
}
I have followed the example from here. Below is how I call this class in my index.php page.
require_once "vendor/autoload.php";
use LuSoft\Library\Repository;
$repository = new Repository();
try{
var_dump($repository->getBranches(__DIR__));
}catch(\Exception $e){
echo "Exception :" . $e->getMessage();
}
Below is the error that I get:
Exception :Error while getting list of references: '"git"' is not
recognized as an internal or external command, operable program or
batch file.
I am using the application I am testing with to get the branches and if things went on correctly I am suppose to be seeing master.
Can someone please explain to me how does the library really work in simplest form?
NB: My index.php is on the same folder level of the application where git has been initialized.
Related
I wrote a basic package for augmenting ldap into laravel
it can now parse subschema do searchs and generate ldif entries,my problem is
this package is driver based as in
when you create you first instance from the manager the front class
i do like this
$driver=new ldapman('openldap')->getDriverInstance();
or in Larvel 5.1
$man=app('Ldapman',['drivername'=>'openldap']);
$driver=$man->getDriverInstance();
and that's lead to constructer like this,
public function __construct( $driver,$type='driver')
{
$drivername=ucfirst($this->drivername);
$drivername.=$type;
$this->driverArray[$type]=null;
if(file_exists(__DIR__."/driver/$drivername.php"))
{
include_once(__DIR__."/driver/$drivername.php");
$drivername="\\Chromax\\Ldapman\\driver\\".$drivername;
if(isset($config)&&!is_null($config))
{
$this->driverArray[$type]=new $drivername($this->config);
}else{
$this->driverArray[$type]=new $drivername();
}
if($this->driverArray[$type] instanceof $drivername)
{
}else{
throw new \Exception("201 Class Not Found");
}
}
else
{
throw new \Exception("200 Driver Not Found");
}
}
this approach is fine and it helps me well but when i sent this package to a friend who was costumed to auto completion he had a hard time working with it
so i want to mod it to support completion
notice : my IDE is PHPSTROM
I've been playing with the Phalcon framework for some time now, but I haven't managed to figure out how to work with application events (via the EventManager).
Specifically, I would like to create a 'boot' event, so I can run code only once per application instead of once per controller (which would be the case if I extended a ControllerBase).
The manual gives me the syntax to use, but I still don't know how to use it and in what file I should put it.
I know I could just require a 'boot.php' file in index.php, but that isn't really an elegant solution.
Assume that you have the index.php file which is the entry point of your application. In that file you have code to register all the services in your application. My personal preference is to keep the index.php file as small as possible and put the bootstrap sequence (registering services) in a different file.
So I would have in the index.php
<?php
use \Phalcon\DI\FactoryDefault as PhDi;
error_reporting(E_ALL);
date_default_timezone_set('US/Eastern');
if (!defined('ROOT_PATH')) {
define('ROOT_PATH', dirname(dirname(__FILE__)));
}
try {
include ROOT_PATH . "/app/var/bootstrap.php";
/**
* Handle the request
*/
$di = new PhDi();
$app = new Bootstrap($di);
echo $app->run(array());
} catch (\Phalcon\Exception $e) {
echo $e->getMessage();
} catch (PDOException $e){
echo $e->getMessage();
}
The bootstrap.php contains the functions needed to initialize all the services that your application needs. One of these services can be as follows:
public function initEventsManager($app)
{
$evManager = new \Phalcon\Events\Manager();
$app->setEventsManager($evManager);
$evManager->attach(
"application",
function($event, $application) {
switch ($event->getType()) {
case 'boot':
$this->handleBoot();
break;
case 'beforeStartModule':
$this->handleBeforeStartModule();
break;
case 'afterStartModule':
$this->handleAfterStartModule();
break;
case 'beforeHandleRequest':
$this->handleBeforeHandleRequest();
break;
case 'afterHandleRequest':
$this->handleAfterHandleRequest();
break;
}
);
}
In your bootstrap.php file you should have relevant functions such as handleBoot handleAfterHandleRequest etc. that will process the code the way you need to.
The above function to register the events manager will need to be invoked with the Phalcon\Mvc\Application as a parameter. A good place to put it would be here (based on the examples)
https://github.com/phalcon/website/blob/master/app/var/bootstrap.php#L62
I'm trying to setup a Laravel task to eventually be called as a cron job using the artisan interface.
In trying to get a simple task working, I keep getting the error that Laravel can't find that task: "Sorry, can't find that task."
Is this a problem with my version? I'm using a version downloaded less than a month ago which I know is at least v3.0 but I don't know how to check the specific version number.
Is there something I need to configure in start.php to register all my "Tasks"? I thought this was done by default for all classes saved in /application/tasks
Mytask.php
class Mytask_Task {
public function run($arguments) {
// Do awesome notifying...
echo "Hello from Mytask Task";
}
}
Routes.php
try{
\Laravel\CLI\Command::run(array('mytask'));
echo "Success";
} catch (Exception $e) {
echo $e->getMessage();
}
The reason is that for the non-cli requests the application workflow of laravel does not autoload the CLI components.
This is why you have to do it like this:
require_once path('sys') . 'cli' . DS . 'dependencies' . EXT;
Laravel\CLI\Command::run(array('migrate', 'application'));
So I got to the bottom of this and it turns out to be a pretty frustrating error.
In the particular v3.x version of Laravel I'm using, the Tasks are not recognized by their lowercase/case insensitive names. I was pointed in the right direction by this post on Github.
So I renamed Mytask.php to mytask.php and the Task executes fine.
If anyone knows how to check the version of Laravel I'm running so others can know if they are affected, please let me know and I'll update this post.
I am trying to use a SOAP Client-Server in my computer and it doesn't look like it is going to work, I am getting this error Error Fetching Http Headers when I try to run my SOAP Client.
I have been looking and the solution that I have encountred is to increase the default_socket_timeout from 60 to 120 seconds and it doesn't work for me, also I have seen another solution that is putting the vhost in my apache KeepAlive Off and that didn't work.
The WSDL is working fine because I try to use it in another computer and it work.
I am running PHP Version 5.3.5-1ubuntu7.4 in Linux Mint using Zend Framework, I hope some of you can help me fix this thank you.
I'm sorry but I don't know what you are using to set up your SOAP service.....
If you can give more information about your SOAP service (poss Zend_Soap given the Zend Framework tag) etc that would be great.
Also, as a quick alternative, you say you've looked at the WSDL on another computer, perhaps try the application in an alternative environment to ensure it's not an environment issue.
May be a simple issue with your client-server code.
UPDATE: Ok so I realised the example I mentioned yesterday wasn't fully implemented so I've hacked something together quickly that you can try to see if it works in your environment.
The code is a mix of something I found here (an example of Zend_Soap_Server) and something from another SO question here (an example of a basic SOAP service test).
I've tested it at my end using ZF 1.11 and the example I'm outlining uses the default Application path you get with a new ZF project (e.g models are in directory application/models so the model shown is headed up Application_Model_Classname).
If it works, you can tweak accordingly....if it doesn't work we can try something else.
Start by creating a new SOAP controller and set the class up like this:
<?php
class SoapController extends Zend_Controller_Action
{
public function init()
{
ini_set("soap.wsdl_cache_enabled", "0"); //disable WSDL caching
$this->_helper->layout()->disableLayout(); //disable the layout
$this->_helper->viewRenderer->setNoRender(); //disable the view
}
public function indexAction ()
{
if (isset($_GET['wsdl'])) {
//return the WSDL
$this->handleWSDL();
} else {
//handle SOAP request
$this->handleSOAP();
}
}
private function handleWSDL ()
{
$strategy = new Zend_Soap_Wsdl_Strategy_AnyType();
$autodiscover = new Zend_Soap_AutoDiscover();
$autodiscover->setComplexTypeStrategy($strategy);
$autodiscover->setClass('Application_Model_SoapService');
$autodiscover->handle();
}
private function handleSOAP ()
{
$server = new Zend_Soap_Server(null,
array('uri' => "http://YOURDOMAIN/soap?wsdl"));
$server->setClass("Application_Model_SoapService");
$server->handle();
}
public function testAction()
{
$client = new Zend_Soap_Client("http://YOURDOMAIN/soap?wsdl");
try {
echo $client->testMethod('test');
} catch (Exception $e) {
echo $e;
}
}
}
In the class above, the WSDL is automatically generated using Zend_Soap_Autodiscover with a SoapService.php file at application/models/SoapService.php used as the template. Note the DocBock comments above each method in your target class are integral to this process.
Next create the SoapService.php file in the default models folder:
<?php
class Application_Model_SoapService
{
/**
* testMethod
*
* #param string $string
* #return string $testSuccess
*/
public function testMethod(string $string)
{
$testSuccess = 'Test successful, the message was: ' . $string;
return $testSuccess;
}
}
If all is working as it should be you can visit:
http://YOURDOMAIN/soap?wsdl
to see the WSDL and visit:
http://YOURDOMAIN/soap/test
to get a success message with the string you specified in the client request within the testAction() code in the SoapController class as part of the message.
Let me know if it's working or not and we can go from there.
I'll be able to have another look on Monday.
I'm trying to use SOAP with C#. Magento 1.4.2.
http://localhost/api/v2_soap/?wsdl
Here I can see the method catalogProductCreate
So I try to connect with:
$proxy = new SoapClient('http://localhost/api/v2_soap/?wsdl');
$sessionId = $proxy->login('xxx', 'xxxxxx'); // user with full access
$newProductData = new stdClass();
$newProductData->name = 'Product Name';
$newProductData->description = 'Description';
$newProductData->short_description = 'Short Description';
$newProductData->websites = array(138);
$newProductData->categories = array(7,15);
$newProductData->status = 1;
$newProductData->price = 45;
$newProductData->tax_class_id = 2;
$newProductData->weight = 1;
$result = $proxy->catalogProductCreate(
$sessionId, // Soap Session
'simple', // Product Type
4, // Attribute Set Id (Default)
'product-sku', // Product Sku
$newProductData // Product Data
);
But I receive this output:
Fatal error: Uncaught SoapFault exception: [4] Resource path is not callable.
(details are Magento 1.6.x specific, but techniques, if not details, should be applicable to other versions)
I'm assuming, based on your code sample, that you're using PHP client code to test for the existence of a method, which you can then apply to a call from your C# application?
Assuming that's the case, it means you know PHP, so you'll want to debug this at the Magento soap server PHP level. The only class file that produces that fault is
app/code/core/Mage/Api/Model/Server/Handler/Abstract.php
Either add the following logging temporarily and directly to that file, or drop a copy of the class file in
app/code/local/Mage/Api/Model/Server/Handler/Abstract.php
for a codepool override.
Look in that class file for the following exception
throw new Mage_Api_Exception('resource_path_not_callable')
This is what causes the Magento soap server to response with that fault. There are four places this happens in that file. Add logging calls above each one.
Mage::Log(sprintf('Line %s in file %s',__LINE__, __FILE__));
throw new Mage_Api_Exception('resource_path_not_callable');
This will let you know which fault is causing your problem, from which you can debug and log further. There are two places this can happen (four total in the file, one for a regular call, another for the multi-call).
In order of appearance, with possible causes in the comments.
//here magento is attempting to instantiate the "API Model" that will perform
//the work of your API call. Upon instantiation, it discovers that the model
//doesn't inherit from Mage_Api_Model_Resource_Abstract, and bails.
//This is rare for a non-custom API call, but might be caused by a class rewrite
//gone amuck, or a very hacked system
try {
$model = Mage::getModel($modelName);
if ($model instanceof Mage_Api_Model_Resource_Abstract) {
$model->setResourceConfig($resources->$resourceName);
}
} catch (Exception $e) {
Mage::Log(sprintf('Line %s in file %s',__LINE__, __FILE__));
throw new Mage_Api_Exception('resource_path_not_callable');
}
//Here Magento's been able to instantiate the $model, and is checking if the method is
//callable. If not, it bails. Again, for a standard, stock API call this shouldn't
//be happening, but could be the result of a rewrite gone wrong, or someone hacking an
//api class to make the method non accesible, or someone hacking the method mapping in api.xml
if (is_callable(array(&$model, $method))) {
if (isset($methodInfo->arguments) && ((string)$methodInfo->arguments) == 'array') {
return $model->$method((is_array($args) ? $args : array($args)));
} elseif (!is_array($args)) {
return $model->$method($args);
} else {
return call_user_func_array(array(&$model, $method), $args);
}
} else {
Mage::Log(sprintf('Line %s in file %s',__LINE__, __FILE__));
throw new Mage_Api_Exception('resource_path_not_callable');
}
Figure out why Magento is throwing the API error. It will often point to a type in your soap call, OR point you towards what's been hacked in your PHP system
Making sure that you can she the wsdl resource is correct, but i also ran into that issue when i didnt have the user set up to the correct permissions under the role.
Try to create a webservice user with role and assigned them to a role that has access to ‘ALL’. option in role resources menu in role information.
Put this file into root folder of magento/project so that you can access all the method of magento.
Enjoy the idea...