public function testSetProperty()
 {
     $category = new AcCategory();
     $privatePropertyName = 'privateProperty';
     set_property($category, $privatePropertyName, 'updated private property');
     $this->assertNotEquals('private property', get_property($category, $privatePropertyName));
     $this->assertEquals('updated private property', get_property($category, $privatePropertyName));
 }
 protected function setCollectionInstance($instance)
 {
     $instanceName = str_plural($this->getInstanceName());
     if (property_exists($this->controller, $instanceName)) {
         set_property($this->controller, $instanceName, $instance);
     } else {
         $this->controller->{$instanceName} = $instance;
     }
 }
Example #3
0
function delete_property($filename, $propname)
{
    return set_property($filename, $propname, NULL, NULL);
}
 public function setProperty($object, $propertyName, $value)
 {
     set_property($object, $propertyName, $value);
 }
 /**
  * Fill the $params property of the given Controller
  *
  * @param  \Illuminate\Routing\Controller $controller
  */
 public function fillController($controller)
 {
     $router = app('router');
     $controllerClass = get_classname($controller);
     $paramsFilterPrefix = "router.filter: ";
     $paramsFilterName = "controller.parameters." . $controllerClass;
     if (!Event::hasListeners($paramsFilterPrefix . $paramsFilterName)) {
         Event::listen($paramsFilterPrefix . $paramsFilterName, function () use($controller, $router) {
             $currentRoute = $router->current();
             $resourceParams = [];
             list($resourceParams['controller'], $resourceParams['action']) = explode('@', $router->currentRouteAction());
             $resourceParams['controller'] = $this->normalizeControllerName($resourceParams['controller']);
             $resourceId = str_singular($resourceParams['controller']);
             if (request()->has($resourceId)) {
                 $params = request()->all();
             } else {
                 $specialInputKeys = $this->specialInputKeys();
                 $params = [$resourceId => request()->except($specialInputKeys)] + request()->only($specialInputKeys);
             }
             $routeParams = $currentRoute->parametersWithoutNulls();
             // In Laravel, unlike Rails, by default 'id' parameter of a 'Product' resource is 'products'
             // And 'shop_id' parameter of a 'Shop' parent resource is 'shops'
             // So we need to reaffect correct parameter name before any controller's actions or filters.
             $routeParamsParsed = [];
             $keysToRemove = [];
             $lastRouteParamKey = last(array_keys($routeParams));
             if ($lastRouteParamKey === 'id' || $resourceId === str_singular($lastRouteParamKey)) {
                 $id = last($routeParams);
                 if (is_a($id, 'Illuminate\\Database\\Eloquent\\Model')) {
                     $id = $id->getKey();
                 }
                 if (is_string($id) || is_numeric($id)) {
                     array_pop($routeParams);
                     $routeParamsParsed['id'] = $id;
                 }
             }
             foreach ($routeParams as $parentIdKey => $parentIdValue) {
                 if (is_a($parentIdValue, 'Illuminate\\Database\\Eloquent\\Model')) {
                     $parentIdValue = $parentIdValue->getKey();
                 }
                 if (is_string($parentIdValue) || is_numeric($parentIdValue)) {
                     if (!ends_with($parentIdKey, '_id')) {
                         $parentIdKey = str_singular($parentIdKey) . '_id';
                     }
                     $routeParamsParsed[$parentIdKey] = $parentIdValue;
                     $keysToRemove[] = $parentIdKey;
                 }
             }
             $routeParams = array_except($routeParams, $keysToRemove);
             /**
              * You can escape or purify these parameters. For example:
              *
              *   class ProductsController extends Controller
              *   {
              *       public function __construct()
              *       {
              *           $self = $this;
              *           $this->beforeFilter(function () use($self) {
              *               if (array_get($self->params, 'product')) {
              *                   $productParams = $this->yourPurifyOrEscapeMethod('product');
              *                   $self->params['product'] = $productParams;
              *               }
              *           });
              *       }
              *   }
              *
              */
             $this->params = array_filter(array_merge($params, $routeParams, $routeParamsParsed, $resourceParams));
             if (property_exists($controller, 'params')) {
                 set_property($controller, 'params', $this->params);
             } else {
                 $controller->params = $this->params;
             }
         });
         $controller->paramsBeforeFilter($paramsFilterName);
     }
 }
        $sql .= implode(',', $set_mas);
        $sql .= ' WHERE id IN (' . implode(',', $id_list) . ')';
        //        echo $sql.'<br/>';
        //если массив set_mas не пустой
        if (count($set_mas) > 0) {
            mysql_query($sql);
        }
        switch (mysql_errno()) {
            case 1146:
                echo "<b>Table " . $base_name . " doesn't exist. Please create DB.</b><br>";
                break;
            default:
                if (mysql_errno() > 0) {
                    echo mysql_errno() . '  ' . mysql_error() . '<br>';
                } else {
                    echo 'Groups ' . $description . ' ' . implode(', ', $id_list) . ' were сhanged.<br/>';
                }
        }
    }
}
include_once '../../db_connect.php';
//подключаемся к базе
$dbh = mysql_connect(host, user, pswd) or die("Не могу соединиться с MySQL.");
mysql_select_db(SCAD) or die("Не могу подключиться к базе.");
$res = mysql_query("SET NAMES utf8");
//запись свойств
echo 'PROP<br/>';
set_property(member_group, $_POST['mas_group'], $_POST['mas_key'], $_POST['mas_value'], 'of members');
set_property(member_group_for_steel, $_POST['mas_group_for_steel'], $_POST['mas_key'], $_POST['mas_value'], 'of members for steel');
//закрываем соединение с базой
mysql_close($dbh);