Skip to content

Commit

Permalink
Merge pull request #1 from sanderborgman/v1.1
Browse files Browse the repository at this point in the history
V1.1
  • Loading branch information
krzysztof-kabala committed Feb 9, 2017
2 parents 8ad04b8 + aa23843 commit 8578455
Show file tree
Hide file tree
Showing 20 changed files with 583 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: php

php:
- 5.4
- 5.6

services:
- mongodb
Expand Down
18 changes: 17 additions & 1 deletion src/DI/Scaffolding.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ class Scaffolding implements ScaffoldingInterface
*/
protected $formName;

/**
* Query
*
* @var array
*/
protected $query = [];

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -135,6 +142,15 @@ public function setModelName($name)
return $this;
}

/**
* {@inheritdoc}
*/
public function setQuery($query)
{
$this->adapter->setQuery($query);
return $this;
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -194,7 +210,7 @@ public function doDelete($id)
*/
private function processForm($values)
{
$form = $this->getForm();
$form = $this->getForm($this->record);
$form->bind($values, $this->record);

if ($form->isValid()) {
Expand Down
18 changes: 18 additions & 0 deletions src/DI/Scaffolding/Adapter/Mongo.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ class Mongo implements AdapterInterface, ScaffoldingAdapterInterface
*/
protected $scaffolding;

/**
* Query for paginator
*
* @var array
*/
protected $query = [];

/**
* Constructor
* Verifies services required by Mongo
Expand All @@ -49,6 +56,16 @@ public function __construct()
$this->setupExtraServices($di);
}

/**
* {@inheritdoc}
*/
public function setQuery($query)
{
$this->query = $query;

return $this;
}

/**
* {@inheritdoc}
*/
Expand All @@ -69,6 +86,7 @@ public function retrieveOne($id)
public function getPaginator($page = 1, $limit = 10)
{
return new PaginatorAdapterMongo(array(
'query' => $this->query,
'model' => $this->scaffolding->getRecord(),
'limit' => $limit,
'page' => $page
Expand Down
19 changes: 18 additions & 1 deletion src/DI/Scaffolding/Adapter/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ class Mysql implements AdapterInterface, ScaffoldingAdapterInterface
*/
protected $scaffolding;

/**
* Query for paginator
*
* @var array
*/
protected $query = [];

/**
* Constructor
*/
Expand All @@ -47,6 +54,16 @@ public function __construct()
$this->verifyRequiredServices($di);
}

/**
* {@inheritdoc}
*/
public function setQuery($query)
{
$this->query = $query;

return $this;
}

/**
* {@inheritdoc}
*/
Expand All @@ -71,7 +88,7 @@ public function getPaginator($page = 1, $limit = 10)
$this->ensureScaffolding();

return new PaginatorAdapterModel(array(
'data' => (object) call_user_func(array($this->scaffolding->getRecord(), 'find')),
'data' => call_user_func(array($this->scaffolding->getRecord(), 'find'), $this->query),
'limit' => $limit,
'page' => $page
));
Expand Down
8 changes: 8 additions & 0 deletions src/DI/Scaffolding/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ interface AdapterInterface
*/
public function retrieveOne($id);

/**
* Sets query for the paginator
*
* @param $id
* @return mixed
*/
public function setQuery($query);

/**
* Retrieve list of records as paginator object.
*
Expand Down
8 changes: 8 additions & 0 deletions src/DI/ScaffoldingInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ public function getForm($entity = null);
*/
public function setFormName($name);

/**
* Sets query for paginator
*
* @param $query
* @return mixed
*/
public function setQuery($query);

/**
* Sets model name
*
Expand Down
8 changes: 8 additions & 0 deletions src/Mvc/Controller/CrudAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ public function initialize()
*/
protected $modelName;

/**
* Query that will be used in index action
*
* @var array
*/
protected $query = [];

/**
* Array of fields names that will be used in index action
*
Expand Down Expand Up @@ -104,6 +111,7 @@ protected function initializeScaffolding()

$this->scaffolding->setModelName($this->modelName);
$this->scaffolding->setFormName($this->formName);
$this->scaffolding->setQuery($this->query);
}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/Mvc/Dispatcher/ExceptionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ public function resolve(\Exception $exception)
throw $exception;
}

error_log(
sprintf(
'Vegas %d error: %s in %s on line %d',
$exception->getCode(),
$exception->getMessage(),
$exception->getFile(),
$exception->getLine()
),
0
);
$error = $this->prepareLiveEnvException($exception);

try {
Expand Down
2 changes: 1 addition & 1 deletion src/Mvc/Module/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function dump($inputDirectory, $outputDirectory, $dumpVendorModules = tru
* @param $modulesList
* @return mixed
*/
private function dumpModulesFromVendor(array &$modulesList)
public function dumpModulesFromVendor(array &$modulesList)
{
if (!file_exists(APP_ROOT.'/composer.json')) {
return $modulesList;
Expand Down
37 changes: 34 additions & 3 deletions src/Task/AssetsTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Vegas\Cli\Task\Option;
use Vegas\Cli\Task;
use Vegas\Cli\TaskAbstract;
use Vegas\Mvc\Module\Loader;

/**
* Class AssetsTask
Expand All @@ -28,16 +29,20 @@ class AssetsTask extends TaskAbstract
*/
public function publishAction()
{
$this->putText("Copying assets...");
$this->copyAllAssets();
$this->putText("Copying Vegas CMF assets...");
$this->copyCmfAssets();

$this->putText("Copying vendor assets:");
$this->copyVendorAssets();

$this->putSuccess("Done.");
}

/**
* Copies all assets from vegas-cmf libraries
* @internal
*/
private function copyAllAssets()
private function copyCmfAssets()
{
$vegasCmfPath = APP_ROOT . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'vegas-cmf';
$publicAssetsDir = $this->getOption('d', APP_ROOT.DIRECTORY_SEPARATOR.'public'.DIRECTORY_SEPARATOR.'assets');
Expand All @@ -59,6 +64,32 @@ private function copyAllAssets()
}
}

/**
* Copies all assets vendor modules
* @internal
*/
private function copyVendorAssets()
{
$modules = [];
$moduleLoader = new Loader($this->di);
$moduleLoader->dumpModulesFromVendor($modules);

$publicAssetsDir = $this->getOption('d', APP_ROOT.DIRECTORY_SEPARATOR.'public'.DIRECTORY_SEPARATOR.'assets');


if ($modules) {
foreach ($modules as $moduleName => $module) {
$assetsDir = dirname($module['path']) . '/../assets';

if (file_exists($assetsDir)) {
$this->putText("- " . $moduleName . "...");

$this->copyRecursive($assetsDir, $publicAssetsDir);
}
}
}
}

/**
* Copies assets recursively
*
Expand Down

0 comments on commit 8578455

Please sign in to comment.