Skip to content

Commit

Permalink
rm boot method
Browse files Browse the repository at this point in the history
  • Loading branch information
basemkhirat committed Feb 25, 2018
1 parent f350136 commit 65b0e9b
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 101 deletions.
Empty file modified .editorconfig 100755 → 100644
Empty file.
Empty file modified .gitignore 100755 → 100644
Empty file.
Empty file modified .travis.yml 100755 → 100644
Empty file.
Empty file modified CHANGELOG.md 100755 → 100644
Empty file.
Empty file modified LICENSE 100755 → 100644
Empty file.
Empty file modified _config.yml 100755 → 100644
Empty file.
Empty file modified composer.json 100755 → 100644
Empty file.
Empty file modified phpunit.xml 100755 → 100644
Empty file.
Empty file modified readme.md 100755 → 100644
Empty file.
13 changes: 13 additions & 0 deletions src/Collection.php 100755 → 100644
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Support\Collection as BaseCollection;


class Collection extends BaseCollection
{

Expand All @@ -18,4 +19,16 @@ public function toJson($options = 0)
return json_encode($this->toArray(), $options);
}

/**
* Get the collection of items as Array.
*
* @return string
*/
public function toArray()
{
return array_map(function($item){
return $item->toArray();
}, $this->items);
}

}
41 changes: 21 additions & 20 deletions src/Connection.php
Expand Up @@ -2,9 +2,7 @@

namespace Basemkhirat\Elasticsearch;

use Elasticsearch\Client;
use Elasticsearch\ClientBuilder;
use Symfony\Component\HttpKernel\Exception\HttpException as HttpException;

/**
* Class Connection
Expand All @@ -15,7 +13,7 @@ class Connection

/**
* Laravel app instance
* @var \Illuminate\contracts\Foundation\Application|mixed
* @var \Illuminate\Foundation\Application|mixed
*/
protected $app;

Expand All @@ -27,13 +25,13 @@ class Connection

/**
* The current connection
* @var Client
* @var
*/
protected $connection;

/**
* all available connections
* @var Client[]
* @var array
*/
protected $connections = [];

Expand Down Expand Up @@ -79,11 +77,11 @@ public static function create($config)
/**
* Create a connection for laravel or lumen frameworks
* @param $name
* @throws HttpException
* @return Query
*/
function connection($name)
{

// Check if connection is already loaded.

if ($this->isLoaded($name)) {
Expand Down Expand Up @@ -123,16 +121,6 @@ function connection($name)
}


/**
* @param string $name
* @throws HttpException
* @return Query
*/
function connectionByName($name = 'default') {
return $this->connection($this->config[$name]);
}


/**
* route the request to the query class
* @param $connection
Expand Down Expand Up @@ -160,22 +148,35 @@ function newQuery($connection)
function isLoaded($name)
{

return array_key_exists($name, $this->connections);
if (array_key_exists($name, $this->connections)) {
return true;
}

return false;
}


/**
* Set the default connection
* @param $name
* @param $arguments
* @throws HttpException
* @return mixed
*/
function __call($name, $arguments)
{
if (method_exists($this, $name)) {

return call_user_func_array([$this, $name], $arguments);

} else {

$query = $this->connectionByName('default');
// if no connection, use default.

return call_user_func_array([$query, $name], $arguments);
$query = $this->connection($this->config["default"]);

return call_user_func_array([$query, $name], $arguments);

}
}

}
3 changes: 3 additions & 0 deletions src/ElasticsearchServiceProvider.php
Expand Up @@ -73,7 +73,10 @@ public function boot()
// Laravel Scout service provider was not loaded yet.

}

}


}

/**
Expand Down
55 changes: 5 additions & 50 deletions src/Model.php
Expand Up @@ -2,14 +2,14 @@

namespace Basemkhirat\Elasticsearch;

use ArrayAccess;
use Illuminate\Support\Collection;

/**
* Elasticsearch data model
* Class Model
* @package Basemkhirat\Elasticsearch
*/
class Model implements ArrayAccess
class Model
{

/**
Expand Down Expand Up @@ -99,7 +99,6 @@ public function getConnection()

/**
* Set current connection
* @param $connection
* @return void
*/
public function setConnection($connection)
Expand All @@ -119,7 +118,7 @@ public function getIndex()

/**
* Set index name
* @param $index
*
* @return void
*/
public function setIndex($index)
Expand All @@ -138,7 +137,6 @@ public function getType()

/**
* Set type name
* @param $type
* @return void
*/
public function setType($type)
Expand Down Expand Up @@ -272,11 +270,11 @@ public function __set($name, $value)

/**
* Create a new model query
* @return Query
* @return mixed
*/
protected function newQuery()
{
$query = app("es")->connectionByName()->setModel($this);
$query = app("es")->setModel($this);

$query->connection($this->getConnection());

Expand All @@ -293,7 +291,6 @@ protected function newQuery()

/**
* Get all model records
* @throws \Exception
* @return mixed
*/
public static function all()
Expand All @@ -308,7 +305,6 @@ public static function all()
/**
* Get model by key
* @param $key
* @throws \Exception
* @return mixed
*/
public static function find($key)
Expand Down Expand Up @@ -401,47 +397,6 @@ function getID()
return $this->attributes["_id"];
}

/**
* Determine if an item exists at an offset.
* @param mixed $key
* @return bool
*/
public function offsetExists($key)
{
return array_key_exists($key, $this->attributes) or in_array($key, $this->appends) or property_exists($this, $key);
}

/**
* Get an item at a given offset.
* @param mixed $key
* @return mixed
*/
public function offsetGet($key)
{
return $this->__get($key);
}

/**
* Set the item at a given offset.
* @param mixed $key
* @param mixed $value
* @return void
*/
public function offsetSet($key, $value)
{
$this->__set($key, $value);
}

/**
* Unset the item at a given offset.
* @param string $key
* @return void
*/
public function offsetUnset($key)
{
unset($this->attributes[$key]);
}

/**
* Handle dynamic static method calls into the method.
* @param string $method
Expand Down

0 comments on commit 65b0e9b

Please sign in to comment.